#include <ESP32Servo.h>
#include <FastLED.h>
#define numLEDs 1
const int numFlowers = 10;
int clockPin = 6;
int ledPins[numFlowers] = {33, 26, 14, 13, 2, 4, 17, 18, 21, 23};
int servoPins[numFlowers] = {32, 25, 27, 12, 15, 0, 16, 5, 19, 22};
Servo servos[numFlowers];
CRGB leds[numFlowers][numLEDs];
String servoPos = "00000000000";
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
//Attach all the servos + LEDs
for(int i = 0; i<numFlowers; i++){
servos[i].attach(servoPins[i]);
servos[i].write(0);
FastLED.addLeds<NEOPIXEL, 33>(leds[i], numLEDs);
leds[i][0] = CRGB::Black;
FastLED.show();
}
}
void loop() {
//Get input data
while(!Serial.available());
String input = Serial.readStringUntil('\n');
//Split up input data to flower number and function
String strNum = input.substring(0, 2);
int num = strNum.toInt();
String func = input.substring(2);
//Check if num is in range
if((num > (numFlowers-1)) || (num < 0)){
Serial.write("Invalid Number");
}
else{
//Change color and servo position based on input
if(input.equals("happy")){
leds[num][0] = CRGB(178, 223, 198);
FastLED.show();
servos[num].write(180);
}
else if(input.equals("content")){
leds[num][0] = CRGB(254, 221, 196);
FastLED.show();
servos[num].write(180);
}
else if(input.equals("anxious")){
leds[num][0] = CRGB(255, 171, 215);
FastLED.show();
servos[num].write(180);
}
else if(input.equals("sad")){
leds[num][0] = CRGB(193, 239, 251);
FastLED.show();
servos[num].write(180);
}
else if(input.equals("irritable")){
leds[num][0] = CRGB(255, 172, 174);
FastLED.show();
servos[num].write(180);
}
else if(input.equals("stressed")){
leds[num][0] = CRGB::Red;
FastLED.show();
servos[num].write(180);
}
else if(input.equals("miserable")){
leds[num][0] = CRGB(228, 199, 247);
FastLED.show();
servos[num].write(180);
}
//INCLUDE WAY TO CHECK IF FLOWER IS OPEN/CLOSE
else if(input.equals("off")){
leds[num][0] = CRGB::Black;
FastLED.show();
servos[num].write(0);
}
}
}