Toggle Navigation
Hatchery
Eggs
kitt
__init__.py
Login
Register
__init__.py
Content
import easydraw, system, badge, ugfx, sys, time # A few tips for hooking up the badge to Windows and testing without using the # Hatchery: neither mpfshell, nor armpy seems to work with the Hacktivity badge, # and the file downloader tool (Tools menu) appears to be broken in the current # firmware, too. # What works are: # - puTTY on Win32: you'll get an interactive microPython shell, but no file upload. # - the rshell "Remote MicroPython shell" works pretty well and allows you to # upload files ('cp') that you can run through REPL ('repl') like: # execfile('lib/kitt/__init__.py'). Get back to rshell using CTRL-X. # # Enjoy! Peter def action_exit(pushed): if (pushed): # turn off all the LEDs -- LED ID 6 refers to all LEDs badge.led(6,0,0,0) # go back to the home screen system.home() def run_boy_run(): # here we go easydraw.messageCentered("K.I.T.T.") badge.init() # set up animation loop parameters animation_time_unit = 0.04 # the higher the slower the animation animation_step_units = 5 # time units required for a full step animation_trail_units = 2 # time units we wait until we turn of a trailing light first_led = 1 # the LED to start from last_led = 4 # the LED to end width # keep animating step_direction = 1 # 1 = forward, -1 backward current_iteration = 0 trail_lifetime_left = 0 trailing_led = -1 next_led_to_light_up = first_led while True: # turn on LED next in line if we've reached the next step if (current_iteration % animation_step_units == 0): badge.led(next_led_to_light_up, 1, 0, 0) # LED, R,G,B # get the previous LED trailing_led = next_led_to_light_up - step_direction # change iteration direction if we've reached the last or first LED if (next_led_to_light_up == last_led): step_direction = -1 if(next_led_to_light_up == first_led): step_direction = 1 # reset trailing LED lifetime counter -- each animation step will reduce this trail_lifetime_left = animation_trail_units # choose the next LED to light up next_led_to_light_up += step_direction # turn off trailing LED if it has reached its lifetime if((trail_lifetime_left == 0) and (trailing_led >= first_led) and (trailing_led <= last_led)): badge.led(trailing_led, 0, 0, 0) # go black # proceed to next iteration and wait 1 unit of animation step time current_iteration += step_direction trail_lifetime_left -= 1 time.sleep(animation_time_unit) # wait a sec def main(): # hook up event handlers ugfx.input_init() ugfx.input_attach(ugfx.BTN_B, action_exit) ugfx.input_attach(ugfx.BTN_START, action_exit) # run in loop run_boy_run() sys.stdin.read(1) #Wait for any key action_exit(True) main()