diff --git a/firmware/Makefile b/firmware/Makefile index 3010f0c..e47cfcd 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -1,6 +1,6 @@ PROJECT=pentabug -APPS = buggy mariotheme geiger ducklings blinker +APPS = buggy jumpy mariotheme geiger ducklings wuerfel blinker OPTIMIZATION = -Os MCU = atmega88pa diff --git a/firmware/apps/blinker.c b/firmware/apps/blinker.c index f2b9012..2929ea1 100644 --- a/firmware/apps/blinker.c +++ b/firmware/apps/blinker.c @@ -2,6 +2,7 @@ #include #include +#include #ifdef MATRIX uint8_t inv = 0; diff --git a/firmware/apps/jumpy.c b/firmware/apps/jumpy.c new file mode 100644 index 0000000..2b14084 --- /dev/null +++ b/firmware/apps/jumpy.c @@ -0,0 +1,61 @@ +#include +#include +#include +#include +#include +#include + +#define SENSITIVITY_FACT 4 + +static uint16_t max_sound; +static uint8_t first; + +static void init(void) { + pentatonic_direction(ALL_OUT); + listen_init(); + + max_sound = 5; + first = 0; +} + +static void run(void) { + uint16_t sound = listen_measure(); + + pentatonic_all_led_set(max_sound >> 5); + + if(!first && sound > max_sound / SENSITIVITY_FACT) { + int8_t intensity = SENSITIVITY_FACT + 1 - max_sound / sound; + + intensity = MIN(intensity, SENSITIVITY_FACT + 1); + + motor_on(); + + set_note(NOTE_C, (rand() & 3) + 3); + + for(size_t i = 0; i < intensity; ++i) { + led_set(RIGHT, rand() & 1); + led_set(LEFT, rand() & 1); + + wait_ms(100); + } + + // turn everything off + + stop_note(); + + motor_off(); + + led_off(RIGHT); + led_off(LEFT); + + wait_ms(100); + } else { + first = 0; + } + + if(sound > max_sound) { + max_sound = sound; + } +} + +REGISTER(run, init, NULL); diff --git a/firmware/apps/wuerfel.c b/firmware/apps/wuerfel.c new file mode 100644 index 0000000..399c4a0 --- /dev/null +++ b/firmware/apps/wuerfel.c @@ -0,0 +1,100 @@ +#include + +#include +#include +#include +#include + +static uint8_t randm = 0; + +static void init(void) { + matrix_start(); +} +static void wuerfel(void) { + + void w_eins(void){ + matrix_set(1,1,1); + } + void w_zwei(void){ + matrix_set(0,0,1); + matrix_set(2,2,2); + } + void w_drei(void){ + matrix_set(0,0,1); + matrix_set(2,2,1); + matrix_set(1,1,1); + } + void w_vier(void){ + matrix_set(0,0,1); + matrix_set(0,2,1); + matrix_set(2,2,1); + matrix_set(2,0,1); + } + void w_funf(void){ + matrix_set(1,1,1); + matrix_set(0,0,1); + matrix_set(0,2,1); + matrix_set(2,2,1); + matrix_set(2,0,1); + } + void w_sechs(void){ + matrix_set(1,0,1); + matrix_set(0,0,1); + matrix_set(0,2,1); + matrix_set(2,2,1); + matrix_set(2,0,1); + matrix_set(1,2,1); + } + void clear(void){ + for(uint8_t x = 0; x < 3; ++x){ + for(uint8_t y = 0; y < 3; ++y){ + matrix_set(x,y,0); + } + } + } + + if(button_clicked(RIGHT)) { + for(uint8_t c = 110; c < 140; c = 10 + c){ + clear(); + w_eins(); + wait_ms(c); + clear(); + w_zwei(); + wait_ms(c); + clear(); + w_drei(); + wait_ms(c); + clear(); + w_vier(); + wait_ms(c); + clear(); + w_funf(); + wait_ms(c); + clear(); + w_sechs(); + wait_ms(c); + } + randm = rand()%6; + clear(); + } + if(randm==0){ + w_eins(); + } + else if(randm==1){ + w_zwei(); + } + else if(randm==2){ + w_drei(); + } + else if(randm==3){ + w_vier(); + } + else if(randm==4){ + w_funf(); + } + else if(randm==5){ + w_sechs(); + } +} + +REGISTER(wuerfel, init, NULL); diff --git a/firmware/include/pentabug/listen.h b/firmware/include/pentabug/listen.h new file mode 100644 index 0000000..f75b572 --- /dev/null +++ b/firmware/include/pentabug/listen.h @@ -0,0 +1,12 @@ +#ifndef LISTEN_H +#define LISTEN_H + +#include + +void listen_init(void); + +void listen_stop(void); + +uint16_t listen_measure(void); + +#endif /* LISTEN_H */ diff --git a/firmware/lib/listen.c b/firmware/lib/listen.c new file mode 100644 index 0000000..8fb3254 --- /dev/null +++ b/firmware/lib/listen.c @@ -0,0 +1,66 @@ +#include + +#include + +#include +#include + +void listen_init(void) { + ADCSRA |= (1 << ADEN); +} + +void listen_stop(void) { + ADCSRA &= ~(1 << ADEN); +} + +uint16_t listen_measure(void) { + // save previous state + + uint8_t prev_state = PINC & (1 << 0); + + // set to ground for discharge + + DDRC |= 1 << 0; + PORTC &= ~(1 << 0); + + // wait for discharge + + wait_ms(1); + + // set direction to input for measurement + + DDRC &= ~(1 << 0); + + // collect some sound waves + + wait_ms(1); + + // start measurement + + // TODO: why can't i move this to the initialization? + ADMUX = (1 << REFS0) | (1 << ADLAR); + ADCSRA |= (1 << ADPS2) | (1 << ADPS1); + + ADMUX = (ADMUX & ~(0x1F)) | 0; + + ADCSRA |= (1 << ADSC); + + // wait for measurement to finish + + while (ADCSRA & (1 << ADSC)) test_stop_app(); + + uint16_t res = ADCL; + res |= ADCH << 8; + + // restore state + + if(prev_state) { + PORTC |= 1 << 0; + } + + DDRC |= 1 << 0; + + // done + + return res; +} diff --git a/hardware/v2/pentabug_v2.brd b/hardware/v2/pentabug_v2.brd index 73d48e3..85e54db 100644 --- a/hardware/v2/pentabug_v2.brd +++ b/hardware/v2/pentabug_v2.brd @@ -1,6 +1,6 @@ - + @@ -28,13 +28,13 @@ - + - + - + - + @@ -219,6 +219,8 @@ for pentabug 2.0 ledmatrix + + @@ -1120,7 +1122,7 @@ design rules under a new name. - + @@ -1666,7 +1668,7 @@ design rules under a new name. - + @@ -1679,7 +1681,7 @@ design rules under a new name. - + @@ -1843,7 +1845,7 @@ design rules under a new name. - + @@ -1856,7 +1858,7 @@ design rules under a new name. - + @@ -1871,7 +1873,7 @@ design rules under a new name. - + @@ -1885,7 +1887,7 @@ design rules under a new name. - + @@ -1899,7 +1901,7 @@ design rules under a new name. - + @@ -1931,7 +1933,7 @@ design rules under a new name. - + @@ -1942,7 +1944,7 @@ design rules under a new name. - + @@ -1953,7 +1955,7 @@ design rules under a new name. - + @@ -1964,7 +1966,7 @@ design rules under a new name. - + @@ -1977,7 +1979,7 @@ design rules under a new name. - + @@ -1992,7 +1994,7 @@ design rules under a new name. - + diff --git a/hardware/v2/pentabug_v2.sch b/hardware/v2/pentabug_v2.sch index 5d8dfd4..7a3d345 100644 --- a/hardware/v2/pentabug_v2.sch +++ b/hardware/v2/pentabug_v2.sch @@ -1,6 +1,6 @@ - + @@ -7995,7 +7995,7 @@ Source: www.kingbright.com - + @@ -8019,12 +8019,16 @@ Source: www.kingbright.com - - - - - - + + + + + + + + + + @@ -8049,8 +8053,8 @@ Source: www.kingbright.com - - @@ -8082,12 +8086,12 @@ Source: www.kingbright.com - + - + @@ -8187,7 +8191,7 @@ Source: www.kingbright.com - + @@ -8202,7 +8206,7 @@ Source: www.kingbright.com - + @@ -8274,8 +8278,8 @@ Source: www.kingbright.com - - @@ -8404,11 +8408,11 @@ Source: www.kingbright.com - + - - @@ -8416,11 +8420,11 @@ Source: www.kingbright.com - + - - @@ -8451,8 +8455,8 @@ Source: www.kingbright.com - - @@ -8463,8 +8467,8 @@ Source: www.kingbright.com - - @@ -8527,11 +8531,11 @@ Source: www.kingbright.com - - - - - + + + + + @@ -8560,6 +8564,7 @@ Source: www.kingbright.com + @@ -8591,12 +8596,12 @@ Source: www.kingbright.com - + - + @@ -8634,11 +8639,11 @@ Source: www.kingbright.com - + - - @@ -8653,11 +8658,11 @@ Source: www.kingbright.com - + - - @@ -8672,11 +8677,11 @@ Source: www.kingbright.com - + - - @@ -8691,11 +8696,11 @@ Source: www.kingbright.com - + - - @@ -8710,11 +8715,11 @@ Source: www.kingbright.com - + - - @@ -8735,12 +8740,12 @@ Source: www.kingbright.com - - - - - - + + + + + + @@ -8774,11 +8779,11 @@ Source: www.kingbright.com - + - - @@ -8795,11 +8800,11 @@ Source: www.kingbright.com - + - - @@ -8816,11 +8821,11 @@ Source: www.kingbright.com - + - - @@ -8837,11 +8842,11 @@ Source: www.kingbright.com - + - - @@ -8855,11 +8860,11 @@ Source: www.kingbright.com - + - - @@ -8873,11 +8878,11 @@ Source: www.kingbright.com - + - -