#define FASTLED_INTERNAL
#define FASTLED_INTERNAL
#include <FastLED.h>
#define NUM_LEDS 45
#define DATA_PIN 7
#define COLOR_ORDER GRB
#define CHIPSET WS2812B
#define BRIGHTNESS 255
#define VOLTS 5
#define MAX_AMPS 7000
CRGBArray<NUM_LEDS> leds;
#include "rizeutils.h"
#include "step.h"
#include "stepmanager.h"
extern Step steps[];
StepManager stepManager(steps, 9);
#include "effectmanager.h"
EffectManager effectManager;
int buttonPin = 23;
int ledPin = 8;
int oldButtonValue = LOW;
bool commandColonFound = false;
String commandFirst = "";
String commandSecond = "";
void setup() {
Serial.begin(115200);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
FastLED.addLeds<CHIPSET,DATA_PIN,COLOR_ORDER>(leds,NUM_LEDS);
FastLED.setMaxPowerInVoltsAndMilliamps(VOLTS,MAX_AMPS);
FastLED.setBrightness(BRIGHTNESS);
FastLED.clear();
FastLED.show();
effectManager.Run(EffectType::STEP_PROGRESS);
// effectManager.Configure("effectSpeed", "3");
// effectManager.Configure("offset", "10");
// effectManager.Configure("mode", "2");
}
void loop() {
EVERY_N_MILLIS_I(timer, 100) {
effectManager.Update(&timer);
FastLED.show();
}
EVERY_N_MILLIS_I(timer2, 100) {
int newButtonValue = digitalRead(buttonPin);
if(newButtonValue != oldButtonValue) {
if(newButtonValue == LOW) {
Serial.println("The button is pressed.");
effectManager.Run(EffectType::STEP_PROGRESS);
} else {
Serial.println("The button is released.");
}
oldButtonValue = newButtonValue;
}
if (oldButtonValue == 0) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}
if (Serial.available() > 0) {
do {
char incomingByte = Serial.read();
if (incomingByte == '\n') {
break;
}
Serial.print("Char read: ");
Serial.print(incomingByte);
if (incomingByte == ':') {
Serial.println(". Colon found!");
commandColonFound = true;
break;
}
if (incomingByte == '$') {
Serial.print(". Command: ");
Serial.print(commandFirst);
Serial.print(", Value: ");
Serial.println(commandSecond);
if (commandFirst == "run") {
effectManager.Run((EffectType)commandSecond.toInt());
} else {
effectManager.Configure(commandFirst.c_str(), commandSecond.c_str());
}
commandColonFound = false;
commandFirst = "";
commandSecond = "";
break;
}
if (commandColonFound) {
commandSecond += incomingByte;
Serial.print(". Added to commandSecond: ");
Serial.println(commandSecond);
} else {
commandFirst += incomingByte;
Serial.print(". Added to commandFirst: ");
Serial.println(commandFirst);
}
} while (Serial.available() > 0);
}
delay(1);
}