#include <FastLED.h>
// staker machine layers 1 - 3 = platformenght of 3
// layers 4 - 9 = platformlenghtr of 2 abs8
// the rest are 1
// layer 11 is the minor prize
// 15 is the major
//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 = 15; // the debounce time; increase if the output flickers
// Define the array of leds
CRGB leds[NUM_LEDS];
bool Direction = false;
int P[3] ={0,1,2};
int P2[2] ={0,1};
int P3[1] ={0};
/////////////////////////////////////////////////
int platformLenght = 1;
int Platform = 1;
//if P is not = to previous P - P
/////////////////////////////////////////////////
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);
Serial.println("Running");
}
void loop() {
drawPlatform();
Animation();
bigPress();
//Next();
ledState = LOW;
Serial.print(Platform);
Serial.print(",");
Serial.print(levelStart);
Serial.print(",");
Serial.println(levelEnd);
//Serial.print(platformLenght);
} // end main loop
void drawPlatform(){
unsigned long currentTime = millis();
//sets the clock to a var
switch(platformLenght){
case 1:
leds[P[0]] = CRGB::LightBlue;
FastLED.show();
leds[P[1]] = CRGB::LightBlue;
FastLED.show();
leds[P[2]] = CRGB::LightBlue;
FastLED.show();
break;
case 2:
leds[P[0]] = CRGB::Yellow;
FastLED.show();
leds[P[1]] = CRGB::Yellow;
FastLED.show();
break;
case 3:
leds[P[0]] = CRGB::Red;
FastLED.show();
break;
default:
leds[0]= CRGB::Green;
FastLED.show();
break;
}
///////////////////////////////////////////////
}
void Next(){
}// Next end
void Animation(){
unsigned long currentTime = millis();
switch(platformLenght){
case 1:
if(currentTime - previousTime >= eventInterval && Direction == false){
P[0] = P[0] + 1;
P[1] = P[1] + 1;
P[2] = P[2] + 1;
previousTime = currentTime;
if(P[2] == levelEnd-1){
Direction = true;
}
}
if(currentTime - previousTime >= eventInterval && Direction == true){
P[0] = P[0] - 1;
P[1] = P[1] - 1;
P[2] = P[2] - 1;
previousTime = currentTime;
if(P[0] == levelStart){ // might ned to go to levelStart - 1 maybe
Direction = false;
}
}
if(P[0] != levelStart){
leds[P[0]-1] = CRGB::Black;
FastLED.show();
}
if(P[2] != levelEnd-1){
leds[P[2]+1] = CRGB::Black;
FastLED.show();
}
break;
case 2:
if(currentTime - previousTime >= eventInterval && Direction == false){
P[0] = P[0] + 1;
P[1] = P[1] + 1;
previousTime = currentTime;
if(P[2] == levelEnd-1){
Direction = true;
}
}
if(currentTime - previousTime >= eventInterval && Direction == true){
P[0] = P[0] - 1;
P[1] = P[1] - 1;
previousTime = currentTime;
if(P[0] == levelStart){ // might ned to go to levelStart - 1 maybe
Direction = false;
}
}
if(P[0] != levelStart){
leds[P[0]-1] = CRGB::Black;
FastLED.show();
}
if(P[2] != levelEnd-1){
leds[P[1]+1] = CRGB::Black;
FastLED.show();
}
break;
}
}
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;
Platform = Platform + 1;
levelStart = levelStart + 7;
levelEnd = levelEnd + 7;
}
}
}
// set the LED:
digitalWrite(ledPin, ledState);
// save the reading. Next time through the loop, it'll be the lastButtonState:
lastButtonState = reading;
}