From 857193ff1da20bc85c1cb088a9b379ab0d55d3f7 Mon Sep 17 00:00:00 2001 From: Dragon_Drop Date: Fri, 13 Sep 2013 15:38:31 +0200 Subject: [PATCH 1/7] Create wuerfel.c --- firmware/apps/wuerfel.c | 100 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 firmware/apps/wuerfel.c diff --git a/firmware/apps/wuerfel.c b/firmware/apps/wuerfel.c new file mode 100644 index 0000000..bc1125d --- /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(){ + matrix_set(1,1,1); + } + void w_zwei(){ + matrix_set(0,0,1); + matrix_set(2,2,2); + } + void w_drei(){ + matrix_set(0,0,1); + matrix_set(2,2,1); + matrix_set(1,1,1); + } + void w_vier(){ + matrix_set(0,0,1); + matrix_set(0,2,1); + matrix_set(2,2,1); + matrix_set(2,0,1); + } + void w_funf(){ + 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(){ + 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(){ + 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); From 76e1c05705a5279c5b4593685e94b83c838e51a2 Mon Sep 17 00:00:00 2001 From: bigalex Date: Fri, 20 Sep 2013 23:29:28 +0200 Subject: [PATCH 2/7] correct labels in schematic for pentatonic fixes #7 --- hardware/v2/pentabug_v2.brd | 22 ++++---- hardware/v2/pentabug_v2.sch | 101 +++++++++++++++++++----------------- 2 files changed, 64 insertions(+), 59 deletions(-) diff --git a/hardware/v2/pentabug_v2.brd b/hardware/v2/pentabug_v2.brd index 73d48e3..dca46ed 100644 --- a/hardware/v2/pentabug_v2.brd +++ b/hardware/v2/pentabug_v2.brd @@ -1,6 +1,6 @@ - + @@ -28,13 +28,13 @@ - + - + - + @@ -1666,7 +1666,7 @@ design rules under a new name. - + @@ -1679,7 +1679,7 @@ design rules under a new name. - + @@ -1843,7 +1843,7 @@ design rules under a new name. - + @@ -1856,7 +1856,7 @@ design rules under a new name. - + @@ -1871,7 +1871,7 @@ design rules under a new name. - + @@ -1885,7 +1885,7 @@ design rules under a new name. - + @@ -1899,7 +1899,7 @@ design rules under a new name. - + diff --git a/hardware/v2/pentabug_v2.sch b/hardware/v2/pentabug_v2.sch index 5d8dfd4..4f03304 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 - + - - From ab05e5e5888f11ec10e5e523d3bdee64eebfbf06 Mon Sep 17 00:00:00 2001 From: bigalex Date: Fri, 20 Sep 2013 23:34:30 +0200 Subject: [PATCH 3/7] correct labels for ledmatrix nets fixes #8 --- hardware/v2/pentabug_v2.brd | 12 +++++----- hardware/v2/pentabug_v2.sch | 48 ++++++++++++++++++------------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/hardware/v2/pentabug_v2.brd b/hardware/v2/pentabug_v2.brd index dca46ed..97947e9 100644 --- a/hardware/v2/pentabug_v2.brd +++ b/hardware/v2/pentabug_v2.brd @@ -1931,7 +1931,7 @@ design rules under a new name. - + @@ -1942,7 +1942,7 @@ design rules under a new name. - + @@ -1953,7 +1953,7 @@ design rules under a new name. - + @@ -1964,7 +1964,7 @@ design rules under a new name. - + @@ -1977,7 +1977,7 @@ design rules under a new name. - + @@ -1992,7 +1992,7 @@ design rules under a new name. - + diff --git a/hardware/v2/pentabug_v2.sch b/hardware/v2/pentabug_v2.sch index 4f03304..7a3d345 100644 --- a/hardware/v2/pentabug_v2.sch +++ b/hardware/v2/pentabug_v2.sch @@ -8740,12 +8740,12 @@ Source: www.kingbright.com - - - - - - + + + + + + @@ -8779,11 +8779,11 @@ Source: www.kingbright.com - + - - @@ -8800,11 +8800,11 @@ Source: www.kingbright.com - + - - @@ -8821,11 +8821,11 @@ Source: www.kingbright.com - + - - @@ -8842,11 +8842,11 @@ Source: www.kingbright.com - + - - @@ -8860,11 +8860,11 @@ Source: www.kingbright.com - + - - @@ -8878,11 +8878,11 @@ Source: www.kingbright.com - + - - From 6b7a49ad28abc13bf425b466137cb8acfdd80fce Mon Sep 17 00:00:00 2001 From: bigalex Date: Fri, 20 Sep 2013 23:49:34 +0200 Subject: [PATCH 4/7] marked cathode for IR led3 and led4, fixes #9 --- hardware/v2/pentabug_v2.brd | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hardware/v2/pentabug_v2.brd b/hardware/v2/pentabug_v2.brd index 97947e9..85e54db 100644 --- a/hardware/v2/pentabug_v2.brd +++ b/hardware/v2/pentabug_v2.brd @@ -30,7 +30,7 @@ - + @@ -219,6 +219,8 @@ for pentabug 2.0 ledmatrix + + @@ -1120,7 +1122,7 @@ design rules under a new name. - + From 0ffd92923661e5b3f18f672b3d952eca66112838 Mon Sep 17 00:00:00 2001 From: Thammi Date: Sat, 21 Sep 2013 02:15:11 +0200 Subject: [PATCH 5/7] Add wuerfel to Makefile --- firmware/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/Makefile b/firmware/Makefile index 3010f0c..fb82ebd 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -1,6 +1,6 @@ PROJECT=pentabug -APPS = buggy mariotheme geiger ducklings blinker +APPS = buggy mariotheme geiger ducklings wuerfel blinker OPTIMIZATION = -Os MCU = atmega88pa From d3c3f928b843cf8fc1e477b0ba31e8607ffa7dd9 Mon Sep 17 00:00:00 2001 From: Thammi Date: Sat, 21 Sep 2013 02:16:31 +0200 Subject: [PATCH 6/7] Remove some compiler warnings --- firmware/apps/blinker.c | 1 + firmware/apps/wuerfel.c | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) 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/wuerfel.c b/firmware/apps/wuerfel.c index bc1125d..399c4a0 100644 --- a/firmware/apps/wuerfel.c +++ b/firmware/apps/wuerfel.c @@ -12,32 +12,32 @@ static void init(void) { } static void wuerfel(void) { - void w_eins(){ + void w_eins(void){ matrix_set(1,1,1); } - void w_zwei(){ + void w_zwei(void){ matrix_set(0,0,1); matrix_set(2,2,2); } - void w_drei(){ + void w_drei(void){ matrix_set(0,0,1); matrix_set(2,2,1); matrix_set(1,1,1); } - void w_vier(){ + 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 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 w_sechs(void){ matrix_set(1,0,1); matrix_set(0,0,1); matrix_set(0,2,1); @@ -45,7 +45,7 @@ static void wuerfel(void) { matrix_set(2,0,1); matrix_set(1,2,1); } - void clear(){ + void clear(void){ for(uint8_t x = 0; x < 3; ++x){ for(uint8_t y = 0; y < 3; ++y){ matrix_set(x,y,0); From 47c93d59f722df990c9e5561bceb2b779ee9a52a Mon Sep 17 00:00:00 2001 From: Thammi Date: Mon, 9 Dec 2013 15:05:44 +0100 Subject: [PATCH 7/7] Add jumpy mode --- firmware/Makefile | 2 +- firmware/apps/jumpy.c | 61 +++++++++++++++++++++++++++ firmware/include/pentabug/listen.h | 12 ++++++ firmware/lib/listen.c | 66 ++++++++++++++++++++++++++++++ 4 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 firmware/apps/jumpy.c create mode 100644 firmware/include/pentabug/listen.h create mode 100644 firmware/lib/listen.c diff --git a/firmware/Makefile b/firmware/Makefile index fb82ebd..e47cfcd 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -1,6 +1,6 @@ PROJECT=pentabug -APPS = buggy mariotheme geiger ducklings wuerfel blinker +APPS = buggy jumpy mariotheme geiger ducklings wuerfel blinker OPTIMIZATION = -Os MCU = atmega88pa 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/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; +}