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()
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()
def setPoints(): global board_position_bottom, cpu_position_bottom if (points[0] < 10 and points[1] < 10): board_position_bottom = round( 8*LEDMatrix.MATRIX_HEIGHT/2 - board_height / 2 ) cpu_position_bottom = board_position_bottom LEDMatrix.gfx_set_all(GFX_OFF) display = LEDNumbers[points[0]] + LED_colon + LEDNumbers[points[1]] LEDMatrix.gfx_sprite_array(display, int((LEDMatrix.MATRIX_WIDTH*8 - len(display))/2), int( LEDMatrix.MATRIX_HEIGHT*4 - 4 ) ) LEDMatrix.gfx_render() time.sleep(1) else: print "Game over: %d - %d" % (points[0], points[1]) LEDMatrix.gfx_set_all(GFX_OFF) if points[0] >= 10: sign = [[1,1,1,1,1,1,1],[1,0,0,0,0,0,0],[1,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,1,1,1,1,1,0],[1,0,0,0,0,0,1],[1,0,0,0,0,0,1],[0,1,1,1,1,1,0],[0,0,0,0,0,0,0],[1,0,0,1,1,1,1],[1,0,0,1,0,0,1],[1,1,1,1,0,0,1],[0,0,0,0,0,0,0],[0,0,0,0,0,0,1],[1,1,1,1,1,1,1],[0,0,0,0,0,0,1]] LEDMatrix.gfx_sprite_array(sign, int((LEDMatrix.MATRIX_WIDTH*8 - len(sign))/2), int( LEDMatrix.MATRIX_HEIGHT*4 - 4 ) ) else: sign = [[0,1,1,1,1,1],[1,0,0,0,0,0],[0,1,1,1,0,0],[1,0,0,0,0,0],[0,1,1,1,1,1],[0,0,0,0,0,0],[1,1,1,1,1,1],[0,0,0,0,0,0],[1,1,1,1,1,1],[0,0,0,1,1,0],[0,0,1,0,0,0],[1,1,0,0,0,0],[1,1,1,1,1,1],[0,0,0,0,0,0],[1,0,1,1,1,1]] LEDMatrix.gfx_sprite_array(sign, int((LEDMatrix.MATRIX_WIDTH*8 - len(sign))/2), int( LEDMatrix.MATRIX_HEIGHT*4 - 3 ) ) LEDMatrix.gfx_render() sys.exit(0)
def setPoints(): global board_position_bottom, cpu_position_bottom if (points[0] < 10 and points[1] < 10): board_position_bottom = round(8 * LEDMatrix.MATRIX_HEIGHT / 2 - board_height / 2) cpu_position_bottom = board_position_bottom LEDMatrix.gfx_set_all(GFX_OFF) display = LEDNumbers[points[0]] + LED_colon + LEDNumbers[points[1]] LEDMatrix.gfx_sprite_array( display, int((LEDMatrix.MATRIX_WIDTH * 8 - len(display)) / 2), int(LEDMatrix.MATRIX_HEIGHT * 4 - 4)) LEDMatrix.gfx_render() time.sleep(1) else: print "Game over: %d - %d" % (points[0], points[1]) LEDMatrix.gfx_set_all(GFX_OFF) if points[0] >= 10: sign = [[1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 0], [1, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 1], [0, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 1, 1, 1, 1], [1, 0, 0, 1, 0, 0, 1], [1, 1, 1, 1, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 1]] LEDMatrix.gfx_sprite_array( sign, int((LEDMatrix.MATRIX_WIDTH * 8 - len(sign)) / 2), int(LEDMatrix.MATRIX_HEIGHT * 4 - 4)) else: sign = [[0, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0], [0, 1, 1, 1, 0, 0], [1, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1], [0, 0, 0, 1, 1, 0], [0, 0, 1, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0], [1, 0, 1, 1, 1, 1]] LEDMatrix.gfx_sprite_array( sign, int((LEDMatrix.MATRIX_WIDTH * 8 - len(sign)) / 2), int(LEDMatrix.MATRIX_HEIGHT * 4 - 3)) LEDMatrix.gfx_render() sys.exit(0)
for letter in range(len(text)): LEDMatrix.gfx_letter(ord(text[letter]), (letter%LEDMatrix.MATRIX_WIDTH)*8, ((LEDMatrix.MATRIX_HEIGHT-1) - letter//LEDMatrix.MATRIX_WIDTH)*8 -1) LEDMatrix.gfx_render() time.sleep(0.2) # Using gfx_ methods allows easy subsequent manipulation eg inverting text for col in range(0,LEDMatrix.MATRIX_WIDTH*8): LEDMatrix.gfx_set_col(col, GFX_INVERT) time.sleep(0.08) LEDMatrix.gfx_render() time.sleep(1.5) # Define & draw a sprite array, and then move it around on the array Pi = [[0,0,0,0,0,0,1,1],[0,0,0,0,0,1,0,1],[0,0,1,1,1,0,0,1],[0,1,0,0,0,1,1,0],[1,0,1,0,1,0,1,0],[1,0,0,1,0,1,0,0],[1,0,1,0,1,0,1,0],[0,1,0,0,0,1,1,0],[0,0,1,1,1,0,0,1],[0,0,0,0,0,1,0,1],[0,0,0,0,0,0,1,1],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]] LEDMatrix.gfx_set_all(GFX_OFF) LEDMatrix.gfx_sprite_array(Pi, 7,8) LEDMatrix.gfx_render() time.sleep(1) for repeat in range(2): for scroll in (DIR_L, DIR_LU, DIR_U, DIR_RU, DIR_R, DIR_RD, DIR_D, DIR_LD): moves = 2*repeat+1 if scroll in [DIR_R, DIR_RD, DIR_D, DIR_LD]: moves += 1 for loop in range(moves): LEDMatrix.gfx_scroll(scroll) LEDMatrix.gfx_render() time.sleep(0.1) time.sleep(1) # Rain Effect imgx = [[0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0],[0,1,1,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0],[1,0,0,0,0,1,1,0,1,0,0,0,0,1,1,0,1,0,0,1,0,0,0,0],[1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,0,1,0,0,0],[0,1,1,1,1,1,1,0,0,1,0,0,1,1,0,0,1,0,0,0,0,1,0,0],[0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1,0,0],[0,0,0,0,0,1,1,0,1,0,0,0,0,1,1,0,1,0,0,0,1,0,0,0],[0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0],[0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,1,1,1,0,0,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,1,0],[0,1,1,1,1,1,0,0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,0],[0,1,0,0,0,1,0,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,0],[0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,1,0,0,1,0,0,1,0],[0,1,1,0,1,1,0,0,0,0,0,0,0,1,1,0,1,0,1,1,1,0,1,0],[0,0,1,0,1,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0],[0,0,0,0,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0],[0,1,1,1,1,1,0,0,1,1,1,1,1,0,0,0,1,0,0,1,0,0,0,0],[1,1,1,1,1,1,1,0,1,0,1,0,1,0,0,0,1,1,1,1,1,1,0,0],[1,0,0,0,1,0,0,0,1,0,1,0,1,0,0,0,1,1,1,1,1,1,1,0],[0,1,0,0,1,0,0,0,1,0,1,1,1,0,0,0,1,0,0,1,0,0,1,0],[0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0]]