diff --git a/python_payload/main.py b/python_payload/main.py index a651bbf2b4d6305f67e1af67da5d83763eef308e..0c8163c246c36f5448c3a443be6dbe7f67b130d6 100644 --- a/python_payload/main.py +++ b/python_payload/main.py @@ -42,7 +42,7 @@ def draw_text_big(text, x, y): def highlight_bottom_petal(num, r, g, b): start = 4 + 8*num for i in range(7): - set_led_rgb((i+start%40), r, g, b) + set_led_rgb(((i+start)%40), r, g, b) update_leds() def long_bottom_petal_captouch_blocking(num, ms): @@ -96,7 +96,7 @@ def run_menu(): cap_touch_demo.foreground() if long_bottom_petal_captouch_blocking(1,20): clear_all_leds() - highlight_bottom_petal(0,255,0,0) + highlight_bottom_petal(1,255,0,0) display_fill(background) display_update() foreground = melodic_demo.run diff --git a/python_payload/melodic_demo.py b/python_payload/melodic_demo.py index 35ab7f03509d42784d2af894ee80c9af21d2502a..dbce6ac4e4cb7aa161e6d70d8f0c19514ff7b4ee 100644 --- a/python_payload/melodic_demo.py +++ b/python_payload/melodic_demo.py @@ -1,22 +1,35 @@ from synth import tinysynth from hardware import * - octave = 0 synths = [] scale = [0,2,4,5,7,9,11] -def set_chord(i): - global chord_index - global chord - if(i != chord_index): - chord_index = i - for j in range(40): - hue = int(72*(i+0.5)) % 360 - set_led_hsv(j, hue, 1, 0.5) - chord = chords[i] - print("set chord " +str(i)) - update_leds() +def highlight_bottom_petal(num, r, g, b): + start = 4 + 8*num + for i in range(7): + set_led_rgb(((i+start)%40), r, g, b) + +def change_playing_field_color(r,g,b): + highlight_bottom_petal(0, r, g, b) + highlight_bottom_petal(1, r, g, b) + highlight_bottom_petal(3, r, g, b) + highlight_bottom_petal(4, r, g, b) + highlight_bottom_petal(2, 255, 0, 255) + set_led_rgb(18, 255, 0, 255) + set_led_rgb(19, 255, 0, 255) + set_led_rgb(27, 255, 0, 255) + set_led_rgb(28, 255, 0, 255) + update_leds() + +def adjust_playing_field_to_octave(): + global octave + if(octave == -1): + change_playing_field_color(0,0,255) + elif(octave == 0): + change_playing_field_color(0,127,127) + elif(octave == 1): + change_playing_field_color(0,255,0) def run(): global scale @@ -26,10 +39,13 @@ def run(): if(get_captouch(i)): if(i == 4): octave = -1 + adjust_playing_field_to_octave() elif(i == 5): octave = 0 + adjust_playing_field_to_octave() elif(i == 6): octave = 1 + adjust_playing_field_to_octave() else: k = i if(k>3): @@ -41,27 +57,11 @@ def run(): def init(): global synths - for i in range(1): synths += [tinysynth(440,1)] - for synth in synths: synth.decay(100) synth.waveform(1) -def highlight_bottom_petal(num, r, g, b): - start = 4 + 8*num - for i in range(7): - set_led_rgb((i+start%40), r, g, b) - update_leds() - def foreground(): - highlight_bottom_petal(0, 0, 0, 255) - highlight_bottom_petal(1, 0, 0, 255) - highlight_bottom_petal(4, 0, 0, 255) - highlight_bottom_petal(3, 0, 0, 255) - set_led_rgb(18, 255, 0, 255) - set_led_rgb(19, 255, 0, 255) - set_led_rgb(27, 255, 0, 255) - set_led_rgb(28, 255, 0, 255) - highlight_bottom_petal(2, 255, 0, 255) + adjust_playing_field_to_octave()