From 96e4c27ae69c44bfea21d16a8e305dcf9a46b16c Mon Sep 17 00:00:00 2001 From: Leonard Rapp Date: Fri, 26 May 2017 00:01:10 +0200 Subject: [PATCH 1/5] added chasing lights function --- main.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 4c8924b..ee47f52 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ */ #ifndef LENGTH -#define LENGTH 30 +#define LENGTH 33 #endif #ifndef F_CPU @@ -157,6 +157,17 @@ int doStrobe(int min_time, int max_time, int r, int g, int b) { return next_call; } +void chasingLights(int counter, int number, int r, int g, int b, int bg_r, int bg_g, int bg_b) { + doSingleColor(bg_r, bg_g, bg_b); + int i = 0; + for(i = 0; i < number; i++) { + leds[counter%LENGTH+i].r = r; + leds[counter%LENGTH+i].g = g; + leds[counter%LENGTH+i].b = b; + } +} + + int main(void) { // initialize UART uart_init(); @@ -185,6 +196,7 @@ int main(void) { // uint8_t hardness = 0; while (1) { + /** // handle UART command if (uart_rcv_complete == 1) { switch(command[0]) { @@ -198,9 +210,10 @@ int main(void) { doSingleColor(0, 0, 255); break; } - } + + }**/ // delay 800 µs -> loop needs ~1ms per iteration - _delay_us(800); + _delay_us(80000); ////////////////////// //doColorRotation(counter); ////////////////////// @@ -216,6 +229,7 @@ int main(void) { //if (counter == doStrobe_next_call) { // doStrobe_next_call = doStrobe(100, 300, 0, 0, 0) + counter; //} + chasingLights(counter, 5, 255, 0, 0, 0, 0, 255); // Refresh LED strip every loop ws2812_setleds(leds, LENGTH); // toggle led for debugging From c5245c0707ee2f7e8f612c08accfb1eca95498ee Mon Sep 17 00:00:00 2001 From: Leonard Rapp Date: Fri, 26 May 2017 00:24:00 +0200 Subject: [PATCH 2/5] added rainbow function --- main.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index ee47f52..3dba876 100644 --- a/main.c +++ b/main.c @@ -65,6 +65,8 @@ void doBlink(uint16_t counter, uint16_t periode, uint8_t r, uint8_t g, } } + + void doColorRotation(uint16_t rotation) { // Convert HSV (h = rotation, s = 255, v = 255; saturation and lightness not regarded) uint8_t r, g, b; @@ -168,6 +170,64 @@ void chasingLights(int counter, int number, int r, int g, int b, int bg_r, int b } +void rainbow() { + int i; + int rotation; + for( i = 0; i < LENGTH; i++) { + rotation = (360 / LENGTH) * i; + // Convert HSV (h = rotation, s = 255, v = 255; saturation and lightness not regarded) + uint8_t r, g, b; + uint8_t section, section_rotation; + uint16_t q, t; + section = (rotation % 360) / 43; + section_rotation = (rotation % 360) % 43; + // p = 0; + q = (255 * ((10710 - (255 * section_rotation)) / 42)) / 256; + t = (255 * ((10710 - (255 * (42 - section_rotation))) / 42)) / 256; + switch (section) { + case 0: + r = 255; + g = t; + b = 0; + break; + case 1: + r = q; + g = 255; + b = 0; + break; + case 2: + r = 0; + g = 255; + b = t; + break; + case 3: + r = 0; + g = q; + b = 255; + break; + case 4: + r = t; + g = 0; + b = 255; + break; + case 5: + r = 255; + g = 0; + b = q; + break; + default: + r = 0; + g = 0; + b = 0; + break; + } + leds[i].r = r; + leds[i].g = g; + leds[i].b = b; + } +} + + int main(void) { // initialize UART uart_init(); @@ -229,7 +289,9 @@ int main(void) { //if (counter == doStrobe_next_call) { // doStrobe_next_call = doStrobe(100, 300, 0, 0, 0) + counter; //} - chasingLights(counter, 5, 255, 0, 0, 0, 0, 255); + //chasingLights(counter, 5, 255, 0, 0, 0, 0, 255); + //////////////////////// + rainbow(); // Refresh LED strip every loop ws2812_setleds(leds, LENGTH); // toggle led for debugging From abed5e168858984bd54586702c068b2392bcb148 Mon Sep 17 00:00:00 2001 From: Leonard Rapp Date: Fri, 26 May 2017 01:06:33 +0200 Subject: [PATCH 3/5] added rotate function --- main.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 3dba876..9a6fcb0 100644 --- a/main.c +++ b/main.c @@ -227,6 +227,12 @@ void rainbow() { } } +void rotate(counter) { + leds[counter%LENGTH].r = leds[(counter+1)%LENGTH].r; + leds[counter%LENGTH].g = leds[(counter+1)%LENGTH].g; + leds[counter%LENGTH].b = leds[(counter+1)%LENGTH].b; +} + int main(void) { // initialize UART @@ -253,6 +259,8 @@ int main(void) { ws2812_setleds(leds, LENGTH); _delay_ms(1000); + rainbow(); + // uint8_t hardness = 0; while (1) { @@ -273,7 +281,7 @@ int main(void) { }**/ // delay 800 µs -> loop needs ~1ms per iteration - _delay_us(80000); + _delay_us(8000); ////////////////////// //doColorRotation(counter); ////////////////////// @@ -291,7 +299,7 @@ int main(void) { //} //chasingLights(counter, 5, 255, 0, 0, 0, 0, 255); //////////////////////// - rainbow(); + rotate(counter); // Refresh LED strip every loop ws2812_setleds(leds, LENGTH); // toggle led for debugging From 9612686e7f381146ab503947709989d5fc8910ec Mon Sep 17 00:00:00 2001 From: Leonard Rapp Date: Fri, 26 May 2017 01:13:52 +0200 Subject: [PATCH 4/5] var type cleanup --- main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 9a6fcb0..b723d6c 100644 --- a/main.c +++ b/main.c @@ -159,9 +159,9 @@ int doStrobe(int min_time, int max_time, int r, int g, int b) { return next_call; } -void chasingLights(int counter, int number, int r, int g, int b, int bg_r, int bg_g, int bg_b) { +void chasingLights(int counter, uint8_t number, uint8_t r, uint8_t g, uint8_t b, uint8_t bg_r, uint8_t bg_g, uint8_t bg_b) { doSingleColor(bg_r, bg_g, bg_b); - int i = 0; + uint8_t i = 0; for(i = 0; i < number; i++) { leds[counter%LENGTH+i].r = r; leds[counter%LENGTH+i].g = g; @@ -172,7 +172,7 @@ void chasingLights(int counter, int number, int r, int g, int b, int bg_r, int b void rainbow() { int i; - int rotation; + uint16_t rotation; for( i = 0; i < LENGTH; i++) { rotation = (360 / LENGTH) * i; // Convert HSV (h = rotation, s = 255, v = 255; saturation and lightness not regarded) From 6f6b6d6ebace3b319b8f96ccb043f5453a96c8fb Mon Sep 17 00:00:00 2001 From: Leonard Rapp Date: Mon, 12 Jun 2017 20:02:46 +0200 Subject: [PATCH 5/5] main.c: fix indentation --- main.c | 140 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 70 insertions(+), 70 deletions(-) diff --git a/main.c b/main.c index b723d6c..c60a189 100644 --- a/main.c +++ b/main.c @@ -57,16 +57,15 @@ void doSingleColor(uint8_t r, uint8_t g, uint8_t b) { // blink adjustable duty cycle void doBlink(uint16_t counter, uint16_t periode, uint8_t r, uint8_t g, - uint8_t b, float dutycycle) { - if ((counter % periode) == 0) { - doSingleColor(0, 0, 0); + uint8_t b, float dutycycle) { + if ((counter % periode) == 0) { + doSingleColor(0, 0, 0); } else if ((counter % periode) == (uint16_t) (dutycycle * periode)) { doSingleColor(r, g, b); } } - void doColorRotation(uint16_t rotation) { // Convert HSV (h = rotation, s = 255, v = 255; saturation and lightness not regarded) uint8_t r, g, b; @@ -159,84 +158,85 @@ int doStrobe(int min_time, int max_time, int r, int g, int b) { return next_call; } -void chasingLights(int counter, uint8_t number, uint8_t r, uint8_t g, uint8_t b, uint8_t bg_r, uint8_t bg_g, uint8_t bg_b) { - doSingleColor(bg_r, bg_g, bg_b); - uint8_t i = 0; - for(i = 0; i < number; i++) { - leds[counter%LENGTH+i].r = r; - leds[counter%LENGTH+i].g = g; - leds[counter%LENGTH+i].b = b; - } +void chasingLights(int counter, uint8_t number, uint8_t r, uint8_t g, uint8_t b, + uint8_t bg_r, uint8_t bg_g, uint8_t bg_b) { + doSingleColor(bg_r, bg_g, bg_b); + uint8_t i = 0; + for(i = 0; i < number; i++) { + leds[counter%LENGTH+i].r = r; + leds[counter%LENGTH+i].g = g; + leds[counter%LENGTH+i].b = b; + } } void rainbow() { - int i; - uint16_t rotation; - for( i = 0; i < LENGTH; i++) { - rotation = (360 / LENGTH) * i; - // Convert HSV (h = rotation, s = 255, v = 255; saturation and lightness not regarded) - uint8_t r, g, b; - uint8_t section, section_rotation; - uint16_t q, t; - section = (rotation % 360) / 43; - section_rotation = (rotation % 360) % 43; - // p = 0; - q = (255 * ((10710 - (255 * section_rotation)) / 42)) / 256; - t = (255 * ((10710 - (255 * (42 - section_rotation))) / 42)) / 256; - switch (section) { - case 0: - r = 255; - g = t; - b = 0; - break; - case 1: - r = q; - g = 255; - b = 0; - break; - case 2: - r = 0; - g = 255; - b = t; - break; - case 3: - r = 0; - g = q; - b = 255; - break; - case 4: - r = t; - g = 0; - b = 255; - break; - case 5: - r = 255; - g = 0; - b = q; - break; - default: - r = 0; - g = 0; - b = 0; - break; + int i; + uint16_t rotation; + for( i = 0; i < LENGTH; i++) { + rotation = (360 / LENGTH) * i; + // Convert HSV (h = rotation, s = 255, v = 255; saturation and lightness not regarded) + uint8_t r, g, b; + uint8_t section, section_rotation; + uint16_t q, t; + section = (rotation % 360) / 43; + section_rotation = (rotation % 360) % 43; + // p = 0; + q = (255 * ((10710 - (255 * section_rotation)) / 42)) / 256; + t = (255 * ((10710 - (255 * (42 - section_rotation))) / 42)) / 256; + switch (section) { + case 0: + r = 255; + g = t; + b = 0; + break; + case 1: + r = q; + g = 255; + b = 0; + break; + case 2: + r = 0; + g = 255; + b = t; + break; + case 3: + r = 0; + g = q; + b = 255; + break; + case 4: + r = t; + g = 0; + b = 255; + break; + case 5: + r = 255; + g = 0; + b = q; + break; + default: + r = 0; + g = 0; + b = 0; + break; + } + leds[i].r = r; + leds[i].g = g; + leds[i].b = b; } - leds[i].r = r; - leds[i].g = g; - leds[i].b = b; - } } void rotate(counter) { - leds[counter%LENGTH].r = leds[(counter+1)%LENGTH].r; - leds[counter%LENGTH].g = leds[(counter+1)%LENGTH].g; - leds[counter%LENGTH].b = leds[(counter+1)%LENGTH].b; + leds[counter%LENGTH].r = leds[(counter+1)%LENGTH].r; + leds[counter%LENGTH].g = leds[(counter+1)%LENGTH].g; + leds[counter%LENGTH].b = leds[(counter+1)%LENGTH].b; } int main(void) { // initialize UART - uart_init(); + uart_init(); uint16_t doStrobe_next_call = 0; _delay_ms(1000); @@ -259,7 +259,7 @@ int main(void) { ws2812_setleds(leds, LENGTH); _delay_ms(1000); - rainbow(); + rainbow(); // uint8_t hardness = 0;