Toggle Navigation
Hatchery
Eggs
Crazy monkey
__init__.py
Login
Register
__init__.py
Content
import easydraw, system, badge, ugfx, sys, samd, gc def var_global(): # VARS global r,g,b,led,r_done,g_done,b_done,w_done,fr,fr_max,fr_min,fr_step r,g,b = [0,0,0] led = 0 r_done = 0 g_done = 0 b_done = 0 w_done = 0 fr = 0 fr_step = 1 fr_max = 40 fr_min = 1 def action_exit(pushed): if (pushed): # to turn off all the leds at ones badge.led(6,0,0,0) gc.collect() # go back to the home screen system.home() def show_names(): easydraw.msg("Crazy Monkey App :)") easydraw.msg("UP/ DOWN - LED") easydraw.msg("LEFT/RIGHT - BUZZ") badge.init() gc.collect() badge.led(6,0,0,0) #Start state def action_up(push): # change all led state +1 global r,g,b,led,r_done,g_done,b_done,w_done if(push): gc.collect() if led >= 0 and led <= 6: if r_done == 0: r = 1 badge.led(led,r,g,b) led += 1 if led >= 6: r_done = 1 led = 0 elif g_done == 0: g = 1 badge.led(led,r,g,b) led += 1 if led >= 6: g_done = 1 led = 0 elif b_done == 0: b = 1 badge.led(led,r,g,b) led += 1 if led >= 6: b_done = 1 w_done = 1 led = 0 elif w_done == 1: easydraw.msg("No More Up, Crazy Monkey :)") def action_down(push): global r,g,b,led,r_done,g_done,b_done,w_done # change all led state -1 if (push): gc.collect() if led >= 0 and led <= 6: if b_done == 1: b = 0 badge.led(led,r,g,b) led += 1 if led >= 6: b_done = 0 led = 0 elif g_done == 1: g = 0 badge.led(led,r,g,b) led += 1 if led >= 6: g_done = 0 led = 0 elif r_done == 1: r = 0 badge.led(led,r,g,b) led += 1 if led >= 6: r_done = 0 w_done = 0 led = 0 elif w_done == 0: easydraw.msg("No More Down, Crazy Monkey :)") def action_right(push): global fr,fr_max,fr_min,fr_step if (push): gc.collect() if fr + fr_step <= fr_max: fr += 1 easydraw.msg("Buzz freq up:") else: easydraw.msg("Max freq reached") buzzing() def action_left(push): global fr,fr_max,fr_min,fr_step if (push): gc.collect() if fr - fr_step >= fr_min: fr -= 1 easydraw.msg("Buzz freq up:") else: easydraw.msg("Max freq reached") buzzing() def buzzing(): samd.buzzer(fr,1) easydraw.msg("fr {}".format(fr)) def main(): var_global() ugfx.input_init() ugfx.input_attach(ugfx.BTN_B, action_exit) ugfx.input_attach(ugfx.BTN_SELECT, action_exit) ugfx.input_attach(ugfx.JOY_UP,action_up) ugfx.input_attach(ugfx.JOY_DOWN,action_down) ugfx.input_attach(ugfx.JOY_RIGHT,action_right) ugfx.input_attach(ugfx.JOY_LEFT,action_left) show_names() while True: sys.stdin.read(1) #Wait for any key action_exit(True) main()