Skip to content

Instantly share code, notes, and snippets.

@mininao
Created May 22, 2015 20:56
Show Gist options
  • Save mininao/23175d69050703a0e1f1 to your computer and use it in GitHub Desktop.
Save mininao/23175d69050703a0e1f1 to your computer and use it in GitHub Desktop.
LED lightning algorithms
for (int i = 0; i < length; ++i)
{
struct LED current_led = leds[i];
if(current_led.color.red != 0) {
on(current_led.pos, true, false,false);
delayMicroseconds(current_led.color.red);
off(current_led.pos);
}
if(current_led.color.green != 0) {
on(current_led.pos, false, true,false);
delayMicroseconds(current_led.color.green);
off(current_led.pos);
}
if(current_led.color.blue != 0) {
on(current_led.pos, false, false,true);
delayMicroseconds(current_led.color.blue);
off(current_led.pos);
}
}
/*for (int i = 0; i < length; ++i)
{
struct LED current_led = leds[i];
for(int k = 0; k < 256; k += 10) {
on(current_led.pos, current_led.color.red > k, current_led.color.green > k,current_led.color.blue > k);
delayMicroseconds(10);
}
}*/
/*for(int k = 0; k < 256; k += 10)
{
for (int i = 0; i < length; ++i) {
struct LED current_led = leds[i];
off(current_led.pos);
int ground_pin = get_ground_pin(current_led.pos);
digitalWrite(ground_pin, LOW);
int red_pin = get_red_pin(current_led.pos);
int green_pin = red_pin + 1;
int blue_pin = green_pin + 1;
digitalWrite(green_pin, current_led.color.green > k);
digitalWrite(red_pin, current_led.color.red > k);
digitalWrite(blue_pin, current_led.color.blue > k);
delayMicroseconds(1);
off(current_led.pos);
}
}*/
for (int i = 0; i < length; ++i)
{
struct LED current_led = leds[i];
//off(current_led.pos);
int ground_pin = get_ground_pin(current_led.pos); //Pin calculation
int red_pin = get_red_pin(current_led.pos);
int green_pin = red_pin + 1;
int blue_pin = green_pin + 1;
analogWrite(ground_pin, 255-current_led.color.red);
digitalWrite(red_pin,true);
delayMicroseconds(baseDelay);
digitalWrite(red_pin,false);
analogWrite(ground_pin, 255-current_led.color.green);
digitalWrite(green_pin,true);
delayMicroseconds(baseDelay);
digitalWrite(green_pin,false);
analogWrite(ground_pin, 255-current_led.color.blue);
digitalWrite(blue_pin,true);
delayMicroseconds(baseDelay);
digitalWrite(blue_pin,false);
off(current_led.pos);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment