Toggle Navigation
Hatchery
Eggs
x-mas leds
__init__.py
Login
Register
__init__.py
Content
import easydraw, system, badge, ugfx, sys import time pattern = [ [[0,0,1,1,0,0], [0,1,1,1,1,0], [1,1,1,1,1,1], [1,1,0,0,1,1], [1,0,0,0,0,1], [0,0,0,0,0,0]], [[1,1,0,0,0,0], [0,1,1,0,0,0], [0,0,1,1,0,0], [0,0,0,1,1,0], [0,0,0,0,1,1], [0,0,0,0,0,0]], [[1,1,0,0,1,1], [0,0,1,1,0,0], [1,1,0,0,1,1], [0,0,1,1,0,0], [1,1,0,0,1,1], [0,0,1,1,0,0]], [[1,1,0,0,0,0], [0,0,1,1,0,0], [0,0,0,0,1,1], [0,0,1,1,0,0], [1,1,0,0,0,0], [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,0,0,0], [1,1,1,1,1,1], [0,0,0,0,0,0]], [[0,1,1,0,0,0], [0,1,1,1,0,0], [0,1,1,1,1,0], [0,1,1,1,0,0], [0,1,1,0,0,0], [0,1,0,0,0,0]], [[1,0,0,0,0,1], [0,1,1,1,1,0], [1,0,0,0,0,1], [0,1,1,1,1,0], [1,0,0,0,0,1], [0,0,0,0,0,0]], [[1,1,0,0,0,0], [0,0,1,0,0,0], [0,0,0,1,0,0], [0,0,0,0,1,1], [0,0,0,0,0,0], [0,0,0,0,0,0]], [[1,0,0,0,0,1], [1,1,0,0,1,1], [1,1,1,1,1,1], [0,1,1,1,1,0], [0,0,1,1,0,0], [0,0,0,0,0,0]]] speed = [1,1,1,2,2,3,2,1,1] speedmulti = 1 colorfix = 0 def action_exit(pushed): if (pushed): # to turn off all the leds at ones badge.led(6,0,0,0) # go back to the home screen system.home() def action_speed_up(pushed): global speedmulti if (pushed): if speedmulti > 1: speedmulti = speedmulti-1 def action_speed_down(pushed): global speedmulti if (pushed): if speedmulti < 4: speedmulti = speedmulti+1 def action_color_up(pushed): global colorfix if (pushed): if colorfix < 7: colorfix = colorfix + 1 else: colorfix = 0 def action_color_down(pushed): global colorfix if (pushed): if colorfix > 0: colorfix = colorfix - 1 else: colorfix = 7 def show_names(): global speedmulti global colorfix easydraw.msg("X-mas Led Lights!") easydraw.msg("Up-Down change Speed") easydraw.msg("Left-Right change Color") badge.init() while True: i = 0 # loop over patterns for px in range(9): # repeat some times for i in range(28): #loop over the colors if colorfix == 0: color = i % 7 else: color = colorfix-1 if color == 0: r, g, b = [1,0,0] elif color == 1: r, g, b = [0,1,0] elif color == 2: r, g, b = [0,0,1] elif color == 3: r, g, b = [1,1,0] elif color == 4: r, g, b = [0,1,1] elif color == 5: r, g, b = [1,0,1] elif color == 6: r, g, b = [1,1,1] else: r, g, b = [0,0,0] # loop over the leds for pat in range(6): for led_id in range(6): # [0,1,2,3,4,5]: # default, turn off all the leds # select a random color # rgb = random.randint(1, 3) # turn the led to the selected state if pattern[px][pat][led_id] == 1: badge.led(led_id,r,g,b) else: badge.led(led_id,0,0,0) time.sleep(0.05*speed[px]*speedmulti) time.sleep(0.05) time.sleep(0.5) def main(): global speedmulti global colorfix ugfx.input_init() ugfx.input_attach(ugfx.BTN_B, action_exit) ugfx.input_attach(ugfx.BTN_START, action_exit) ugfx.input_attach(ugfx.JOY_UP, action_speed_up) ugfx.input_attach(ugfx.JOY_DOWN, action_speed_down) ugfx.input_attach(ugfx.JOY_LEFT, action_color_down) ugfx.input_attach(ugfx.JOY_RIGHT, action_color_up) show_names() sys.stdin.read(1) #Wait for any key action_exit(True) main()