Add octave switching to pentatonic app

This commit is contained in:
Thammi 2013-09-05 02:05:23 +02:00
parent f866f05e00
commit e4f778d01e
3 changed files with 45 additions and 29 deletions

40
firmware/apps/tonic.c Normal file
View File

@ -0,0 +1,40 @@
#include <pentabug/app.h>
#include <pentabug/pentatonic.h>
#include <pentabug/hal.h>
#include <pentabug/music.h>
#include <pentabug/helper.h>
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);

View File

@ -1,29 +0,0 @@
#include <pentabug/app.h>
#include <pentabug/pentatonic.h>
#include <pentabug/hal.h>
#include <pentabug/music.h>
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);

View File

@ -3,4 +3,9 @@
#define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array)) #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 */ #endif /* HELPER_H */