#include <FastLED.h>
#define NUM_LEDS 30//to see
#define DATA_PIN 2 //How boring and obvious!
#define COLOR_ORDER GRB //Green (G), Red (R), Blue (B)
#define CHIPSET WS2812B
#define BRIGHTNESS 60
#define VOLTS 5
#define MAX_AMPS 500 //value in milliamps
#define DELAY 5
#define FLASH_COLOR CRGB::White
#define HEX "0x00FFBA"
CRGB leds[NUM_LEDS];
char recvBuff[80];
int charCount = 0;
bool recvDone = false;
void setup() {
// put your setup code here, to run once:
//serial setup:
Serial.begin(9600);
//LED setup
FastLED.addLeds<CHIPSET, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setMaxPowerInVoltsAndMilliamps(VOLTS, MAX_AMPS);
FastLED.setBrightness(BRIGHTNESS);
FastLED.clear();
FastLED.show();
Serial.println("Ready");
}
void loop() {
if (Serial.available())
{
while (Serial.available())
{
char incomingChar = Serial.read();
if (incomingChar != 10 && incomingChar != 13)
{
recvBuff[charCount] = incomingChar;
charCount++;
} else if (incomingChar == 10) {
recvDone = true;
}
}
}
if (charCount > 0 && recvDone)
{
char input = recvBuff[0];
Serial.println(recvBuff);
Serial.print(":"); // show what was received
Serial.print(input);
Serial.print(": ");
if (input == 'a') {
int middleIndex = {NUM_LEDS / 2 - 1};
for (int i = 0; i <= (middleIndex + 1); i++) {
int forwardIndex = {middleIndex + i};
int backwardIndex = {middleIndex - i};
leds[forwardIndex - 3] = CRGB::Black;
leds[backwardIndex + 3] = CRGB::Black;
leds[forwardIndex] = FLASH_COLOR;
leds[backwardIndex] = FLASH_COLOR;
FastLED.show();
delay(10);
}
}
FastLED.clear();
FastLED.show();
if (input == 'r') {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::Red;
}
}
FastLED.show();
if (input == 'g') {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::Green;
}
}
FastLED.show();
if (input == 'b') {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::Blue;
}
}
// This is where i have a problem.
FastLED.show();
if (input == 't') {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = HEX;
}
}
FastLED.show();
if (input == '0') {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = recvBuff;
}
}
FastLED.show();
//reset counter and bool var
charCount = 0;
recvDone = false;
}
}