def __init__(self):
     # Initialise library
     LEDMatrix.init()
     # Clear the whole display
     LEDMatrix.clear_all()
     # Reset brightness
     LEDMatrix.brightness(3)
Exemplo n.º 2
0
 def low_voltage_shutdown(self):
     LEDMatrix.clear_all()
     # Clear GPIO
     GPIO.cleanup()
     command = "/usr/bin/sudo /sbin/shutdown now"
     process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
     output = process.communicate()[0]
Exemplo n.º 3
0
 def __init__(self, state, flag):
     self.state = state
     self.flag = flag
     # Initialise library
     LEDMatrix.init()
     # Clear the whole display
     LEDMatrix.clear_all()
     # Reset brightness
     LEDMatrix.brightness(3)
Exemplo n.º 4
0
def display_messages(messages):
    LEDMatrix.init()
    try:
        LEDMatrix.brightness(3)
        LEDMatrix.scroll_message_horiz([messages])
        LEDMatrix.clear_all()
    except KeyboardInterrupt:
        LEDMatrix.scroll_message_horiz(["", "Have a good PyDay!", ""], 1, 8)
    LEDMatrix.clear_all()
Exemplo n.º 5
0
 async def exit_service(self):
     "Stop movement, clean up matrices and GPIO and send a stop message to Arduino. Service is stopped from listen_for_shutdown.service"
     # Stop Movement - Send message to Arduino
     #        await write_serial(b'S\r\n')
     # Clear LED Matrices
     LEDMatrix.clear_all()
     # Clear GPIO
     GPIO.cleanup()
     # Shutdown raspberry pi
     sys.exit(0)
Exemplo n.º 6
0
def normal():
    # Display a stationary message
    a = 1
    b = 0
    ##happy=[[0,0,1,1,1,1,0,0],[0,1,0,1,0,0,1,0],[1,0,1,0,0,1,0,1],[1,0,1,0,0,0,0,1],[1,0,1,0,0,0,0,1],[1,0,1,0,0,1,0,1],[0,1,0,1,0,0,1,0],[0,0,1,1,1,1,0,0]]
    happy = [[b, b, b, b, b, b, b, b], [b, b, a, b, b, b, b, b],
             [b, a, b, b, b, a, b, b], [b, a, b, b, b, b, b, b],
             [b, a, b, b, b, b, b, b], [b, a, b, b, b, a, b, b],
             [b, b, a, b, b, b, b, b], [b, b, b, b, b, b, b, b]]
    LEDMatrix.gfx_sprite_array(happy, start_x=0, start_y=0, state=GFX_INVERT)
    LEDMatrix.gfx_scroll_towards(new_graphic=GFX_OFF,
                                 repeats=3,
                                 speed=5,
                                 direction=DIR_L,
                                 finish=True)
    LEDMatrix.gfx_render()
    time.sleep(1)
    LEDMatrix.clear_all()
    while True:
        for row in cur.fetchall():
            mq2 = str(row[0])
            mq7 = str(row[1])
            mq131 = str(row[2])
            mq135 = str(row[3])
            mq136 = str(row[4])
            pm1 = str(row[5])
            pm25 = str(row[6])
            pm10 = str(row[7])
            print(mq2)
            print(mq7)
            print(mq131)
            print(mq135)
            print(mq136)

            LEDMatrix.scroll_message_horiz(["LPG: " + mq2], 1, 5)
            LEDMatrix.scroll_message_horiz(["CO: " + mq7], 1, 5)
            LEDMatrix.scroll_message_horiz(["NOx: " + mq131], 1, 5)
            LEDMatrix.scroll_message_horiz(["HAZ: " + mq135], 1, 5)
            LEDMatrix.scroll_message_horiz(["H2S: " + mq136], 1, 5)
            LEDMatrix.scroll_message_horiz(["PM1.0: " + pm1], 1, 5)
            LEDMatrix.scroll_message_horiz(["PM2.5: " + pm25], 1, 5)
            LEDMatrix.scroll_message_horiz(["PM10: " + pm10], 1, 5)
            time.sleep(1)
            LEDMatrix.clear_all()
Exemplo n.º 7
0
def move():
	global running, speed
	if running:
		newPosition = tail[0] + direction
		if newPosition.x > WIDTH:
			newPosition.x -= WIDTH+1
		elif newPosition.x < 0:
			newPosition.x += WIDTH+1
		if newPosition.y > HEIGHT:
			newPosition.y -= HEIGHT+1
		elif newPosition.y < 0:
			newPosition.y += HEIGHT+1
		
		if newPosition == target:
			tail.insert(0,newPosition)
			setTarget()
			speed = max(0.07, min(0.3, 2/float(len(tail))))
		elif newPosition not in tail:
			tail.insert(0, newPosition)
			tail.pop()
		else:
			# Game Over
			running = False
			for i in range(6):
				LEDMatrix.gfx_set_all(GFX_INVERT)
				LEDMatrix.gfx_render()
				time.sleep(0.3)
			if USE_JOYPAD:
				print "Game Over. Score: " + str(len(tail)-1)
			else:
				print "Game Over. Press any Key to exit. Score: " + str(len(tail)-1)
			LEDMatrix.clear_all()
			raise SystemExit("\n")
		
		# threading for calling it every period
		threading.Timer(speed, move).start ()
	else:
		LEDMatrix.clear_all()
	display()
Exemplo n.º 8
0
def warn():
    a = 0
    b = 1
    sad = [[b, b, b, b, b, b, b, b], [b, a, b, b, b, b, b, b],
           [b, b, a, b, b, a, b, b], [b, b, a, b, b, b, b, b],
           [b, b, a, b, b, b, b, b], [b, b, a, b, b, a, b, b],
           [b, a, b, b, b, b, b, b], [b, b, b, b, b, b, b, b]]
    LEDMatrix.gfx_sprite_array(sad, start_x=0, start_y=0, state=GFX_INVERT)
    LEDMatrix.gfx_scroll_towards(new_graphic=GFX_OFF,
                                 repeats=3,
                                 speed=5,
                                 direction=DIR_L,
                                 finish=True)
    LEDMatrix.gfx_render()
    LEDMatrix.gfx_render()
    LEDMatrix.gfx_render()
    time.sleep(1)
    LEDMatrix.clear_all()
    LEDMatrix.scroll_message_horiz(["warning"], 1, 5)
    while True:
        for row in cur.fetchall():
            mq2 = str(row[0])
            mq7 = str(row[1])
            mq131 = str(row[2])
            mq135 = str(row[3])
            mq136 = str(row[4])
            pm1 = str(row[5])
            pm25 = str(row[6])
            pm10 = str(row[7])
            print(mq2)
            print(mq7)
            print(mq131)
            print(mq135)
            print(mq136)

            LEDMatrix.scroll_message_horiz(["LPG: 2100"], 1, 5)
            time.sleep(1)
            LEDMatrix.clear_all()
Exemplo n.º 9
0
            mq131 = str(row[2])
            mq135 = str(row[3])
            mq136 = str(row[4])
            pm1 = str(row[5])
            pm25 = str(row[6])
            pm10 = str(row[7])
            print(mq2)
            print(mq7)
            print(mq131)
            print(mq135)
            print(mq136)

            LEDMatrix.scroll_message_horiz(["LPG: " + mq2], 1, 5)
            LEDMatrix.scroll_message_horiz(["CO: " + mq7], 1, 5)
            LEDMatrix.scroll_message_horiz(["NOx: " + mq131], 1, 5)
            LEDMatrix.scroll_message_horiz(["HAZ: " + mq135], 1, 5)
            LEDMatrix.scroll_message_horiz(["H2S: " + mq136], 1, 5)
            LEDMatrix.scroll_message_horiz(["PM1.0: " + pm1], 1, 5)
            LEDMatrix.scroll_message_horiz(["PM2.5: " + pm25], 1, 5)
            LEDMatrix.scroll_message_horiz(["PM10: " + pm10], 1, 5)
            time.sleep(1)
            LEDMatrix.clear_all()


try:
    warn()
except KeyboardInterrupt:
    # reset array
    LEDMatrix.scroll_message_horiz(["Goodbye!"], 1, 6)
    LEDMatrix.clear_all()
Exemplo n.º 10
0
def exit_service(signal, frame):
    LEDMatrix.clear_all()
    GPIO.cleanup()
    sys.exit(0)
Exemplo n.º 11
0
def exit_service(signal, frame):
    LEDMatrix.clear_all()
    GPIO.cleanup()
    time.sleep(1)
    sys.exit()
Exemplo n.º 12
0
			GPIO.setup(GPIO_RIGHT, GPIO.IN)
			GPIO.setup(GPIO_LEFT, GPIO.IN)
			while running:
				if GPIO.input(GPIO_UP) == GPIO.HIGH:
					changeDirection(DIR_U)
				elif GPIO.input(GPIO_DOWN) == GPIO.HIGH:
					changeDirection(DIR_D)
				elif GPIO.input(GPIO_RIGHT) == GPIO.HIGH:
					changeDirection(DIR_R)
				elif GPIO.input(GPIO_LEFT) == GPIO.HIGH:
					changeDirection(DIR_L)
				time.sleep(0.1)
		except KeyboardInterrupt:
			# CTRL + C
			print "\nGoodbye"
			LEDMatrix.clear_all()
			time.sleep(0.1)
			running = False
			GPIO.cleanup(GPIO_UP)
			GPIO.cleanup(GPIO_DOWN)
			GPIO.cleanup(GPIO_RIGHT)
			GPIO.cleanup(GPIO_LEFT)
	else:
		# Use Keyboard Arrows
		from _Getch import _Getch
		getch = _Getch()
		print "To end the game press <q>"
		while running:
			key = ord(getch())
			if key == 27: #ESC
				key = ord(getch())