temp = bus.read_byte_data(tmp101_0, 0)
    print("Temperature: " + str(temp))
    if (temp > 0x1c):
        bus.write_i2c_block_data(matrix, 0, clear)
        state = [
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00
        ]

    if (Vertical.position > 0):
        if (cursorY < 0x80):
            cursorY = cursorY << 1
    elif (Vertical.position < 0):
        if (cursorY > 0x01):
            cursorY = cursorY >> 1
    Vertical.position = 0

    if (Horizontal.position > 0):
        if (cursorX < 15):
            cursorX = cursorX + 2
    elif (Horizontal.position < 0):
        if (cursorX > 1):
            cursorX = cursorX - 2
    Horizontal.position = 0

    state[cursorX] = state[cursorX] | cursorY
    bus.write_i2c_block_data(matrix, 0, state)
    print("cursorX: " + str(cursorX))
    print("cursorY: " + str(cursorY))

    time.sleep(0.25)
Esempio n. 2
0
 def main(self, stdscr):
     # Defining Buttons
     buttonUp = "P9_27"
     buttonDown = "P9_16"
     buttonLeft = "P9_17"
     buttonRight = "P9_18"
     buttonQuit = "P9_22"
     buttonShake = "P9_24"
     # Setting up buttons
     GPIO.setup(buttonUp, GPIO.IN)
     GPIO.setup(buttonDown, GPIO.IN)
     GPIO.setup(buttonLeft, GPIO.IN)
     GPIO.setup(buttonRight, GPIO.IN)
     GPIO.setup(buttonQuit, GPIO.IN)
     GPIO.setup(buttonShake, GPIO.IN)
     # Setup the encoders
     upDownEncoder = RotaryEncoder(eQEP2)
     leftRightEncoder = RotaryEncoder(eQEP1)
     upDownEncoder.setAbsolute()
     leftRightEncoder.setAbsolute()
     upDownEncoder.enable()
     leftRightEncoder.enable()
     # Setting up the LED matrix
     self.bus.write_byte_data(self.matrix, 0x21, 0)   # Start oscillator (p10)
     self.bus.write_byte_data(self.matrix, 0x81, 0)   # Disp on, blink off (p11)
     self.bus.write_byte_data(self.matrix, 0xe7, 0)   # Full brightness (page 15)
     # Pointing the screen to itself
     self.stdscr = stdscr
     stdscr.clear()
     self.shake()
     try:
         while True:
             # Update cursor
             self.cursor()
             # Initliaze the screen
             curses.initscr()
             if GPIO.input(buttonUp) | upDownEncoder.position > 0:
                 if self.pos[1] > 0:
                     self.pos[1] -= 1
             elif GPIO.input(buttonDown) | upDownEncoder.position < 0:
                 if self.pos[1] < self.height - 1:
                     self.pos[1] += 1
             elif GPIO.input(buttonLeft) | leftRightEncoder.position > 0:
                 if self.pos[0] > 0:
                     self.pos[0] -= 1
             elif GPIO.input(buttonRight) | leftRightEncoder.position < 0:
                 if self.pos[0] < self.width - 1:
                     self.pos[0] += 1
             elif GPIO.input(buttonQuit):
                 break
             elif GPIO.input(buttonShake):
                 self.shake()
                 self.oldpos = list(self.pos)
                 continue
             else:
                 continue
             upDownEncoder.position = 0
             leftRightEncoder.position = 0
             # Draw something on the board
             stdscr.addstr(self.oldpos[1], self.oldpos[0], self.full)
             self.updateLEDMatrix()
             # Update the old position
             self.oldpos = list(self.pos)
             time.sleep(delay/10)
     finally:
           GPIO.cleanup()
		if ledy>7:
			ledy=7
		column = 2**ledy
		row = 2*ledx
		ledMatrix[row]= ledMatrix[row] | column
	if myEncoderx.position<0:
		ledx-=1
		if ledx<0:
			ledx=0
		column = 2**ledy
		row = 2*ledx
		ledMatrix[row]= ledMatrix[row] | column
	if myEncoderx.position>0:
		ledx+=1
		if ledx>7:
			ledx=7
		column = 2**ledy
		row = 2*ledx
		ledMatrix[row]= ledMatrix[row] | column
	if GPIO.input("P8_7"):
		ledMatrix = [0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
		ledx=0
		ledy=0

	myEncoderx.position=0
	myEncodery.position=0
				
	i2cbus.write_i2c_block_data(led_addr, 0, ledMatrix)
	time.sleep(.1)

	elif verticalEncoder.position > 0:
		if first:
			first = False
			grid[0][0] = True
		else:
			if pos[1]<7:
				pos[1] = pos[1] + 1
	elif horizontalEncoder.position > 0:
		if first:
			first = False
			grid[0][0] = True
		else:
			if pos[0]<7:
				pos[0] = pos[0] + 1
	elif GPIO.input(resetState):
		grid = copy.deepcopy(reset)
		output =  [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
		first = True
		pos = [0,0]


	if horizontalEncoder.position!=0 or verticalEncoder.position!=0:
		grid[pos[0]][pos[1]] = True

	horizontalEncoder.position = 0
	verticalEncoder.position = 0
	mark()
	bus.write_i2c_block_data(matrix, 0, output)
	time.sleep(0.2)
Esempio n. 5
0
    if HEncoder.position > 0:
        xcur += 1
        if xcur > 7:
            xcur = 7
        output = update(output, xcur, ycur)

    if VEncoder.position < 0:
        ycur -= 1
        if ycur < 0:
            ycur = 0
        output = update(output, xcur, ycur)

    if HEncoder.position < 0:
        xcur -= 1
        if xcur < 0:
            xcur = 0
        output = update(output, xcur, ycur)

    if not GPIO.input(reset):
        output = [
            0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00
        ]
        xcur = 0
        ycur = 0

    HEncoder.position = 0
    VEncoder.position = 0
    bus.write_i2c_block_data(matrix, 0, output)