// Servo Sweep example for the ESP32
// https://wokwi.com/arduino/projects/323706614646309460
#include <ESP32Servo.h>
#include <FastLED.h>
#define NUM_LEDS 1
#define LEDPIN 33
int clockPin = 6;
int servoPin = 32;
Servo servo;
CRGB leds[NUM_LEDS];
void setup() {
Serial.begin(115200);
servo.attach(servoPin);
servo.write(0);
FastLED.addLeds<NEOPIXEL, LEDPIN>(leds, NUM_LEDS);
leds[0] = CRGB::Black;
FastLED.show();
}
void loop() {
//Get input data
while(!Serial.available());
String input = Serial.readStringUntil('\n');
//Use input
if(input.equals("happy")){
leds[0] = CRGB(178, 223, 198);
FastLED.show();
servo.write(180);
}
else if(input.equals("content")){
leds[0] = CRGB(254, 221, 196);
FastLED.show();
servo.write(180);
}
else if(input.equals("anxious")){
leds[0] = CRGB(255, 171, 215);
FastLED.show();
servo.write(360);
}
else if(input.equals("sad")){
leds[0] = CRGB(193, 239, 251);
FastLED.show();
servo.write(180);
}
else if(input.equals("irritable")){
leds[0] = CRGB(255, 172, 174);
FastLED.show();
servo.write(180);
}
else if(input.equals("stressed")){
leds[0] = CRGB::Red;
FastLED.show();
servo.write(180);
}
else if(input.equals("miserable")){
leds[0] = CRGB(228, 199, 247);
FastLED.show();
servo.write(180);
}
else if(input.equals("off")){
leds[0] = CRGB::Black;
FastLED.show();
servo.write(0);
}
/*
leds[0] = CRGB::Red;
FastLED.show();
for(int j = 0; j<180; j++){
servo.write(j);
delay(5);
}
leds[0] = CRGB::Black;
FastLED.show();
for(int j = 180; j>0; j--){
servo.write(j);
delay(5);
}
*/
}