From 66bb2174124674af44301beb2cc63c57f482d41a Mon Sep 17 00:00:00 2001 From: Dave Arter Date: Fri, 31 Aug 2018 16:47:42 +0100 Subject: [PATCH] Can now exit synth app and change octave --- synth/main.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/synth/main.py b/synth/main.py index ddc848f..d73a822 100644 --- a/synth/main.py +++ b/synth/main.py @@ -16,7 +16,10 @@ from app import restart_to_default ugfx_helper.init() speaker.enabled(True) +octave = 4 + def mode_buttons(): + global octave print("mode: buttons") notes = { Buttons.BTN_1: "C", @@ -32,10 +35,7 @@ def mode_buttons(): Buttons.BTN_0: "A#", Buttons.BTN_Hash: "B" } - ugfx.clear() - ugfx.text(5, 5, "Synth", ugfx.BLACK) - ugfx.text(5, 30, "Use the buttons >", ugfx.BLACK) - ugfx.text(5, 80, "Octave: 4", ugfx.BLUE) # Allow the octave to be changed + render_ui() alive = True while alive: @@ -45,9 +45,23 @@ def mode_buttons(): note_to_play = note break if note_to_play: - speaker.note(note_to_play) + speaker.note("{}{}".format(note_to_play, octave)) else: speaker.stop() + if is_triggered(Buttons.BTN_Menu): + return + if is_triggered(Buttons.JOY_Up): + octave = min(6, max(0, octave+1)) + render_ui() + if is_triggered(Buttons.JOY_Down): + octave = min(6, max(0, octave-1)) + render_ui() + +def render_ui(): + ugfx.clear() + ugfx.text(5, 5, "Synth", ugfx.BLACK) + ugfx.text(5, 30, "Use the buttons >", ugfx.BLACK) + ugfx.text(5, 80, "Octave: {}".format(octave), ugfx.BLUE) mode_buttons() # Todo: Allow different modes and allow users to switch between them via joystick or something restart_to_default()