project; comments, formatting py
This commit is contained in:
parent
90da82a8ec
commit
029835aeb7
@ -33,10 +33,12 @@ images_set = {
|
|||||||
loop: bool = True
|
loop: bool = True
|
||||||
tone: bool = False
|
tone: bool = False
|
||||||
midi_key: int = 69
|
midi_key: int = 69
|
||||||
|
tone_mode: bool = True
|
||||||
|
|
||||||
|
|
||||||
# Fetch the base image for the note letter from the global dictionary,
|
# Fetch the base image for the note letter from the global dictionary,
|
||||||
# Then embellish it with the octave pattern (in binary) and potential flat flag
|
# Then embellish it with the octave pattern (in binary) and potential flat flag
|
||||||
|
# Flat flag goes in the bottom right pixel at partial brightness, and binary octave pattern goes from top right down
|
||||||
def get_image(note_letter: str, octave: int) -> Image:
|
def get_image(note_letter: str, octave: int) -> Image:
|
||||||
base_letter = note_letter[0]
|
base_letter = note_letter[0]
|
||||||
base_img = images_set[base_letter]
|
base_img = images_set[base_letter]
|
||||||
@ -56,11 +58,12 @@ def get_image(note_letter: str, octave: int) -> Image:
|
|||||||
base_img.set_pixel(4, i, 0)
|
base_img.set_pixel(4, i, 0)
|
||||||
return base_img
|
return base_img
|
||||||
|
|
||||||
|
# Example: get_note(69) -> ("A", 4)
|
||||||
def get_note(key: int) -> tuple:
|
def get_note(key: int) -> tuple:
|
||||||
return ((note_names[key % 12]), ((key // 12) - 1))
|
return ((note_names[key % 12]), ((key // 12) - 1))
|
||||||
|
|
||||||
|
|
||||||
|
# Logic controller for the speaker. Decides when to start and stop, and looks up which note to play
|
||||||
def manage_tone(midi_key):
|
def manage_tone(midi_key):
|
||||||
global tone
|
global tone
|
||||||
if pin_logo.is_touched() and tone == False:
|
if pin_logo.is_touched() and tone == False:
|
||||||
@ -73,6 +76,7 @@ def manage_tone(midi_key):
|
|||||||
tone = False
|
tone = False
|
||||||
|
|
||||||
|
|
||||||
|
# Logic controller for the display
|
||||||
def manage_display(midi_key):
|
def manage_display(midi_key):
|
||||||
note = get_note(midi_key)
|
note = get_note(midi_key)
|
||||||
note_letter = note[0]
|
note_letter = note[0]
|
||||||
@ -85,8 +89,9 @@ def log():
|
|||||||
print(midi_key, "-", note[0], "[", note[1], "]")
|
print(midi_key, "-", note[0], "[", note[1], "]")
|
||||||
|
|
||||||
|
|
||||||
manage_display(midi_key)
|
# Logic for "tone mode" - Pick a note and play it
|
||||||
while loop:
|
def tone_mode_controller():
|
||||||
|
global midi_key
|
||||||
input = (button_a.was_pressed(), button_b.was_pressed())
|
input = (button_a.was_pressed(), button_b.was_pressed())
|
||||||
update = False
|
update = False
|
||||||
if input == (False, False):
|
if input == (False, False):
|
||||||
@ -103,4 +108,23 @@ while loop:
|
|||||||
log()
|
log()
|
||||||
manage_display(midi_key)
|
manage_display(midi_key)
|
||||||
manage_tone(midi_key)
|
manage_tone(midi_key)
|
||||||
|
|
||||||
|
|
||||||
|
# Stub logic for listen mode. See README.md for elaboration
|
||||||
|
def listen_mode_controller():
|
||||||
|
# mic_in = pin5.get_pull()
|
||||||
|
# mic_run = pin20.get_analog_period_microseconds()
|
||||||
|
display.show(Image.CONFUSED)
|
||||||
|
|
||||||
|
|
||||||
|
# Main Program Logic. Run the display once before looping
|
||||||
|
manage_display(midi_key)
|
||||||
|
while loop:
|
||||||
|
if button_a.is_pressed() and button_b.is_pressed():
|
||||||
|
tone_mode = not tone_mode
|
||||||
|
sleep(100)
|
||||||
|
if tone_mode:
|
||||||
|
tone_mode_controller()
|
||||||
|
else:
|
||||||
|
listen_mode_controller()
|
||||||
sleep(100)
|
sleep(100)
|
||||||
|
Reference in New Issue
Block a user