diff --git a/firmware/apps/tonic.c b/firmware/apps/tonic.c new file mode 100644 index 0000000..9e1e601 --- /dev/null +++ b/firmware/apps/tonic.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include + +static void run(void) { + uint8_t prev_buttons = 0; + static uint8_t octave = 4; + + pentatonic_direction(ALL_IN); + + for ever { + uint8_t buttons = pentatonic_buttons(); + + if(button_clicked(RIGHT) && octave < 8) { + ++octave; + prev_buttons = 0; + } + + if(button_clicked(LEFT) && octave > 0) { + --octave; + prev_buttons = 0; + } + + if (prev_buttons != buttons) { + if (buttons & 16) set_note(NOTE_Db, octave); + else if (buttons & 8) set_note(NOTE_Eb, octave); + else if (buttons & 4) set_note(NOTE_Gb, octave); + else if (buttons & 2) set_note(NOTE_Ab, octave); + else if (buttons & 1) set_note(NOTE_Bb, octave); + else stop_note(); + prev_buttons = buttons; + } + + wait_ms(1); + } +} + +REG(run); diff --git a/firmware/apps/tonictest.c b/firmware/apps/tonictest.c deleted file mode 100644 index a94fa9e..0000000 --- a/firmware/apps/tonictest.c +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#include -#include - -static void init(void) { - pentatonic_direction(ALL_IN); -} - -static void run(void) { - pentatonic_direction(ALL_IN); - - uint8_t prev_buttons = 0; - for(;;) { - uint8_t buttons = pentatonic_buttons(); - if (prev_buttons != buttons) { - if (buttons & 16) set_note(NOTE_Db, 4); - else if (buttons & 8) set_note(NOTE_Eb, 4); - else if (buttons & 4) set_note(NOTE_Gb, 4); - else if (buttons & 2) set_note(NOTE_Ab, 4); - else if (buttons & 1) set_note(NOTE_Bb, 4); - else stop_note(); - prev_buttons = buttons; - } - wait_ms(1); - } -} - -REGISTER(run, init, NULL); diff --git a/firmware/include/pentabug/helper.h b/firmware/include/pentabug/helper.h index 275e3da..d46fc5f 100644 --- a/firmware/include/pentabug/helper.h +++ b/firmware/include/pentabug/helper.h @@ -3,4 +3,9 @@ #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array)) +#define MAX(a, b) (a > b ? a : b) +#define MIN(a, b) (a < b ? a : b) + +#define ever (;;) + #endif /* HELPER_H */