From d3675173e05aa8318f56341ec30c769b29a8ed12 Mon Sep 17 00:00:00 2001 From: p01ar Date: Tue, 4 Sep 2018 06:45:21 +0100 Subject: [PATCH 1/2] added magicmusic --- magicmusic/main.py | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 magicmusic/main.py diff --git a/magicmusic/main.py b/magicmusic/main.py new file mode 100644 index 0000000..99d328c --- /dev/null +++ b/magicmusic/main.py @@ -0,0 +1,73 @@ +"""BEEP BEEP! + +Todo: fix this, it doesn't work at at the moment +""" + +___name___ = "MAGICMUSIC" +___license___ = "MIT" +___categories___ = ["Sound"] +___dependencies___ = ["speaker", "buttons", "ugfx_helper", "app"] + +import ugfx, speaker, ugfx_helper, random, sleep +from tilda import Buttons, Sensors +from buttons import * +from app import restart_to_default + +notes = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"] + +ugfx_helper.init() +octave = 4 +delay = 200 +def mode_buttons(): + global octave + global delay + # render_ui() + + alive = True + while alive: + speaker.enabled(True) + + if is_pressed(Buttons.JOY_Up): + delay += 10 + if is_pressed(Buttons.JOY_Down): + if delay > 10: + delay -= 10 + + if is_pressed(Buttons.JOY_Left): + if 1 < octave: + octave -= 1 + if is_pressed(Buttons.JOY_Right): + if octave < 6: + octave += 1 + + rand_temp = str(Sensors.get_hdc_temperature()).split('.')[-1] + + + rand_num = int(rand_temp) % len(notes) + + rest_delay = int(rand_temp) % 100 + + note_to_play = notes[rand_num] + render_ui(note_to_play, delay, octave, rest_delay) + # octave = random.randint(1,5) + speaker.note("{}{}".format(note_to_play, octave)) + sleep.sleep_ms(delay) + + speaker.enabled(False) + sleep.sleep_ms(rest_delay) + + + + + +def render_ui(note, delay, octave, rest_delay): + ugfx.clear() + ugfx.text(0, 0, "lets make some music! {}".format(note), ugfx.BLACK) + ugfx.text(0, 100, "Delay: {}ms".format(delay), ugfx.BLACK) + ugfx.text(0, 200, "Octave: {}".format(octave), ugfx.BLACK) + ugfx.text(0, 300, "Note Delay: {}".format(rest_delay), ugfx.BLACK) + +mode_buttons() # Todo: Allow different modes and allow users to switch between them via joystick or something +restart_to_default() + + From a9d8f5985fac9f93e17a9f34c3b8de072e844e5c Mon Sep 17 00:00:00 2001 From: polar Date: Tue, 4 Sep 2018 10:46:41 +0100 Subject: [PATCH 2/2] Update main.py --- magicmusic/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/magicmusic/main.py b/magicmusic/main.py index 99d328c..0ff6588 100644 --- a/magicmusic/main.py +++ b/magicmusic/main.py @@ -1,6 +1,5 @@ """BEEP BEEP! -Todo: fix this, it doesn't work at at the moment """ ___name___ = "MAGICMUSIC"