Skip to content

Add features #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 91 additions & 7 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

#ifndef LENGTH
#define LENGTH 30
#define LENGTH 33
#endif

#ifndef F_CPU
Expand Down Expand Up @@ -57,14 +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);
}
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mäh 😒

void doColorRotation(uint16_t rotation) {
// Convert HSV (h = rotation, s = 255, v = 255; saturation and lightness not regarded)
uint8_t r, g, b;
Expand Down Expand Up @@ -157,9 +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 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;
}
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;
}


int main(void) {
// initialize UART
uart_init();
uart_init();
uint16_t doStrobe_next_call = 0;

_delay_ms(1000);
Expand All @@ -182,9 +259,12 @@ int main(void) {
ws2812_setleds(leds, LENGTH);
_delay_ms(1000);

rainbow();

// uint8_t hardness = 0;

while (1) {
/**
// handle UART command
if (uart_rcv_complete == 1) {
switch(command[0]) {
Expand All @@ -198,9 +278,10 @@ int main(void) {
doSingleColor(0, 0, 255);
break;
}
}

}**/
// delay 800 µs -> loop needs ~1ms per iteration
_delay_us(800);
_delay_us(8000);
//////////////////////
//doColorRotation(counter);
//////////////////////
Expand All @@ -216,6 +297,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);
////////////////////////
rotate(counter);
// Refresh LED strip every loop
ws2812_setleds(leds, LENGTH);
// toggle led for debugging
Expand Down