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 */ diff --git a/firmware/lib/hal.c b/firmware/lib/hal.c index 2f25ec3..fc04d6a 100644 --- a/firmware/lib/hal.c +++ b/firmware/lib/hal.c @@ -8,13 +8,12 @@ #include static volatile uint8_t ir_active = 0; -static uint16_t int_skip = 0; static volatile int16_t wait_time = 0; -static uint16_t button_count[2]; +static uint8_t button_count[2]; static uint8_t button_pressed[2]; -// interrupt for button handling, every 5ms +// interrupt for button handling, every 10ms ISR(TIMER2_COMPA_vect) { uint8_t i = 0; @@ -22,7 +21,7 @@ ISR(TIMER2_COMPA_vect) { // button pressed? if(PINB & (1 << i)) { // pressed for more than 50ms is a click - if(button_count[i] > 10 && button_count[i] < 200) { + if(button_count[i] > 5 && button_count[i] < 100) { button_pressed[i] = 1; } @@ -34,7 +33,7 @@ ISR(TIMER2_COMPA_vect) { } // 1s pressed, request next app - if(button_count[i] == 200) { + if(button_count[i] == 100) { next_app(i ? 1 : -1); } } @@ -73,7 +72,7 @@ void init_hw(void) { TIMSK2 |= (1 << OCIE2A); - OCR2A = 35; + OCR2A = 70; TCCR2A = (1 << WGM01); TCCR2B = (1 << CS22) | (1 << CS21) | (1 << CS20);