Toggle Navigation
Hatchery
Eggs
Buzzer button tester
__init__.py
Login
Register
__init__.py
Content
import easydraw, system, ugfx, sys, samd, time def init_global(): global pitch, pitch_step, pitch_min, pitch_max global time, time_step, time_min, time_max pitch = 20 pitch_step = 1 pitch_min = 1 pitch_max = 40 time = 1 time_step = 1 time_min = 1 time_max = 5 def action_exit(pushed): if (pushed): # go back to the home screen system.home() def action_inc_pitch(pushed): global pitch, pitch_step, pitch_max if (pushed): if pitch + pitch_step <= pitch_max: pitch += pitch_step easydraw.msg("Increase pitch") else: easydraw.msg("Pitch is max") play_note() def action_dec_pitch(pushed): global pitch, pitch_step, pitch_min if (pushed): if pitch - pitch_step >= pitch_min: pitch -= pitch_step easydraw.msg("Decrease pitch") else: easydraw.msg("Pitch is min") play_note() def action_inc_time(pushed): global time, time_step, time_max if (pushed): if time + time_step <= time_max: time += time_step easydraw.msg("Increase time") else: easydraw.msg("Time is max") play_note() def action_dec_time(pushed): global time, time_step, time_min if(pushed): if time - time_step >= time_min: time -= time_step easydraw.msg("Decrease time") else: easydraw.msg("Time is min") play_note() def play_note(): easydraw.msg("Pitch {} duration {}".format(pitch, time)) samd.buzzer(pitch, time) time.sleep(0.1) def main(): init_global() 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_inc_pitch) ugfx.input_attach(ugfx.JOY_DOWN, action_dec_pitch) ugfx.input_attach(ugfx.JOY_LEFT, action_dec_time) ugfx.input_attach(ugfx.JOY_RIGHT, action_inc_time) easydraw.msg("Play a note!") while True: sys.stdin.read(1) #Wait for any key action_exit(True) main()