From ed5a276f9b8a5da636e5cda4f3e33a54b0382bdf Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Mon, 23 Dec 2019 08:13:14 -0800 Subject: minor adjustments and fixes --- config.h | 16 ++++++++-------- eq.c | 12 +++++++----- eq.h | 2 +- main.c | 21 ++++++++++++--------- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/config.h b/config.h index 72357e3..ffe99a0 100644 --- a/config.h +++ b/config.h @@ -3,20 +3,20 @@ #define F_CPU 8000000UL -#define LED_COUNT 50 +#define LED_COUNT 100 #define LED_PIN PB3 #define EQ_PIN_INPUT PB2 #define EQ_PIN_RESET PB0 #define EQ_PIN_STROBE PB1 #define EQ_THRESHOLDS \ - {16, 82}, \ - {24, 130}, \ - {24, 99}, \ - {24, 79}, \ - {24, 77}, \ - {24, 87}, \ - {26, 37} + {0x76, 0xFF}, \ + {0x82, 0xFF}, \ + {0x58, 0xFF}, \ + {0x5F, 0xFF}, \ + {0x40, 0xAA}, \ + {0x3D, 0x88}, \ + {0x1F, 0x66} #define ISR_PIN PB4 diff --git a/eq.c b/eq.c index eb7febd..846e1fa 100644 --- a/eq.c +++ b/eq.c @@ -27,7 +27,7 @@ static unsigned char map_level(unsigned char val, unsigned char min, unsigned ch else if (val >= max) return 255; else - return val * 255 / (max - min); + return (val - min) * 255 / (max - min); } void eq_read() { @@ -42,10 +42,12 @@ void eq_read() { } } -void eq_decay() { - reset(); +void eq_decay(int cycles) { + for (int i = 0; i < cycles; ++i) { + reset(); - for (int i = 0; i < 7; ++i) { - strobe(); + for (int i = 0; i < 7; ++i) { + strobe(); + } } } diff --git a/eq.h b/eq.h index fd28b25..52ea3d8 100644 --- a/eq.h +++ b/eq.h @@ -3,7 +3,7 @@ extern unsigned char eq_levels[]; -void eq_decay(); +void eq_decay(int); void eq_read(); #endif diff --git a/main.c b/main.c index 06c585e..7f64e30 100644 --- a/main.c +++ b/main.c @@ -2,7 +2,6 @@ #include "eq.h" #include "led.h" -#include #include #include #include @@ -59,6 +58,8 @@ void rainbow() { void sound_reactive() { memset(seq, 0, 3 * sizeof(seq[0])); + int offset = 0; + while (1) { if (interrupted == true) { interrupted = false; @@ -69,18 +70,20 @@ void sound_reactive() { seq[0].r = (eq_levels[0] > eq_levels[1]) ? eq_levels[0] : eq_levels[1]; unsigned char t = (eq_levels[2] > eq_levels[3]) ? eq_levels[2] : eq_levels[3]; - seq[1].g = (t > eq_levels[4]) ? t : eq_levels[4]; - seq[2].b = (eq_levels[5] > eq_levels[6]) ? eq_levels[5] : eq_levels[6]; - - led_signal_sequence(LED_COUNT, seq, 3, 1, 0); - for (int i = 0; i < 20; ++i) { - eq_decay(); - } + t = (t > eq_levels[4]) ? t : eq_levels[4]; + seq[1].r = t; + seq[1].g = t * 170 / 255; + seq[1].b = t * 65 / 255; + seq[2].g = (eq_levels[5] > eq_levels[6]) ? eq_levels[5] : eq_levels[6]; + + led_signal_sequence(LED_COUNT, seq, 3, 1, offset/60); + if (++offset == 180) + offset = 0; + eq_decay(10); _delay_ms(50); } } - int main() { DDRB |= (1 << LED_PIN); PORTB &= ~(1 << LED_PIN); -- cgit v1.2.3-70-g09d2