Last active
June 4, 2016 10:32
-
-
Save focalintent/78eb3411de3b879c8600ff276a000470 to your computer and use it in GitHub Desktop.
Lighting up one by one
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "FastLED.h" | |
#include <SPI.h> | |
#define NumPixels 1500 // number of LEDs in strip - count starts at 0, not 1 | |
#define Datapin 11 // datapin - green on apa102 | |
#define Clockpin 13 // clockpin - blue on apa102 | |
#define DataRate_Mhz 15 | |
CRGB leds[NumPixels]; | |
int g, r, b, z; | |
int head=-1, tail=(head-6); | |
float Speed; | |
float previousmicros; | |
void setup() | |
{ | |
FastLED.addLeds<APA102,Datapin,Clockpin,BGR,DATA_RATE_MHZ(DataRate_Mhz)>(leds,NumPixels); // data rate is worth playing around with, if left untouched it goes mental | |
Serial.begin(115200); // set the speed at which serial monitor will write at | |
fill_solid(leds, NumPixels, CRGB(0,0,0)); // clear lights | |
FastLED.show(); // show the blank | |
delay(3000); // delay so everything can be ready | |
} | |
void loop() | |
{ | |
Speed = 8.47*1000000, g=255, r=0, b=255; //speed is how long I would like for it to complete from LED 0 to the last LED | |
while(head<=NumPixels-1) | |
{ | |
float currentmicros = micros(); | |
float LEDInterval = (Speed/NumPixels); | |
if(currentmicros-previousmicros>= LEDInterval) | |
{ | |
Serial.print("Head Equals "); | |
Serial.println(head); | |
Serial.print("Interval Should be "); | |
Serial.println(LEDInterval); | |
Serial.print("Interval Equals "); | |
Serial.println(currentmicros-previousmicros); | |
Serial.print("Time Equals "); | |
Serial.println(micros()); | |
Serial.println(""); | |
previousmicros = currentmicros; | |
leds[head] = CRGB(g,r,b); // head | |
leds[tail] = CRGB(0,0,0); // tail | |
FastLED.show(); // show | |
++head; // further the lights | |
++tail; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment