#include <FastLED.h>
#include <PubSubClient.h>
#define NUM_LEDS_EYES 2
#define NUM_LEDS_LIGHT 1
#define DATA_PIN_EYES 4
#define DATA_PIN_LIGHT 2
#define BTN_PIN 5
CRGB eyes[NUM_LEDS_EYES];
CRGB light[NUM_LEDS_LIGHT];
// previous time for the tasks depending upon time.
unsigned long prevTime_T1 = millis();
long interval_T1 = 1000;
enum EyeSide {
RIGHT,
LEFT,
};
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(BTN_PIN, INPUT_PULLUP);
FastLED.addLeds<NEOPIXEL, DATA_PIN_EYES>(eyes, NUM_LEDS_EYES);
FastLED.addLeds<NEOPIXEL, DATA_PIN_LIGHT>(light, NUM_LEDS_LIGHT);
// Eyes open
eyes[0] = CHSV(145, 255, 255);
eyes[1] = CHSV(145, 255, 255);
}
void EyesBlink()
{
// Close eyes
eyes[0] = CHSV(145, 255, 0);
eyes[1] = CHSV(145, 255, 0);
FastLED.show();
// Open eyes
for (int i = 0; i < 255; i+=5)
{
eyes[0] = CHSV(145, 255, i);
eyes[1] = CHSV(145, 255, i);
FastLED.show();
}
interval_T1 = random(800, 8000); // generate a new random interval after each blink
}
void MouthAction()
{
if (digitalRead(BTN_PIN) == LOW)
{
light[0] = CRGB::SkyBlue;
}
else
{
light[0] = CRGB::Red;
}
FastLED.show();
}
void loop()
{
unsigned long currentTime = millis();
// Task 1 : Blink LED1 (T1)
if (currentTime - prevTime_T1 > interval_T1)
{
EyesBlink();
prevTime_T1 = currentTime;
//Serial.println(interval_T1);
}
MouthAction();
delay(10);
}