Merge branch 'master' of github.com:c3d2/pentabug

This commit is contained in:
twobit 2013-09-05 02:17:56 +02:00
commit 6e09daced6
4 changed files with 50 additions and 35 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 */

View File

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