#include <FastLED.h>
//defines for millis
const unsigned long eventInterval = 200;
unsigned long previousTime = 0;
// Defines for fast led
#define NUM_LEDS 98
#define DATA_PIN 12
int levelStart = 0;
int levelEnd = 7;
// Button stuff
// constants won't change. They're used here to set pin numbers:
const int buttonPin = 10; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// Variables will change:
int ledState = LOW; // the current state of the output pin
int buttonState; // the current reading from the input pin
int lastButtonState = HIGH; // the previous reading from the input pin
// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
// Define the array of leds
CRGB leds[NUM_LEDS];
int i = levelStart;
bool Direction = false;
/////////////////////////////////////////////////
/////////////////////////////////////////////////
void setup() {
Serial.begin(9600);
Serial.println("Starting Up");
LEDS.addLeds<WS2811,DATA_PIN,GRB>(leds,NUM_LEDS);
LEDS.setBrightness(84);
FastLED.clear();
//Button.
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
// set initial LED state
digitalWrite(ledPin, ledState);
leds[0] = CRGB::Black;
FastLED.show();
Serial.println("Running");
}
void loop() {
bigPress();
Next();
drawPlatform();
///////////////////////////////////////////////////
//////////////////////////////////////////////////
} // end main loop
void bigPress(){
// read the state of the switch into a local variable:
int reading = digitalRead(buttonPin);
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited long enough
// since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer than the debounce
// delay, so take it as the actual current state:
// if the button state has changed:
if (reading != buttonState) {
buttonState = reading;
// only toggle the LED if the new button state is HIGH
if (buttonState == HIGH) {
ledState = !ledState;
}
}
}
// set the LED:
digitalWrite(ledPin, ledState);
// save the reading. Next time through the loop, it'll be the lastButtonState:
lastButtonState = reading;
}
void drawPlatform(){
//sets the clock to a var
unsigned long currentTime = millis();
if (i <= levelEnd -1 && currentTime - previousTime >= eventInterval && Direction == false){
//Serial.println(i);
leds[i] = CRGB::Green;
FastLED.show();
leds[i-2] = CRGB::Black;
FastLED.show();
i++;
previousTime = currentTime;
if (i >= levelEnd){
Direction = true;
}
}
if (i >= levelStart +1 && currentTime - previousTime >= eventInterval && Direction == true){
//Serial.println(i);
leds[i-2] = CRGB::Green;
FastLED.show();
leds[i] = CRGB::Black;
FastLED.show();
i--;
previousTime = currentTime;
if (i <= levelStart +1){
Direction = false;
}
}
}
void Next(){
if(ledState != buttonState ){
//Serial.println(ButtonState);
levelStart = levelStart + 7;
levelEnd = levelEnd + 7;
ledState = LOW;
i = i + 7;
}
}