Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FastLED.h"
- #include "Arduino.h"
- #include "SoftwareSerial.h"
- #include "DFRobotDFPlayerMini.h"
- #define NUM_LEDS 50
- #define DATA_PIN 5
- #define CLOCK_PIN 13 //You probably don't need to worry about this
- #define BRIGHTNESS 48 //I believe this setting is over-ridden by the
- // third number in all the parentheses below
- // CHSV(#, #, BRIGHTNESS#)
- SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
- DFRobotDFPlayerMini myDFPlayer;
- void printDetail(uint8_t type, int value);
- // Define the array of leds
- CRGB leds[NUM_LEDS];
- int ledPin = 13; // choose the pin for the LED
- int inputPin = 2; // choose the input pin (for PIR sensor)
- int pirState = LOW; // we start, assuming no motion detected
- int val = 0; // variable for reading the pin status
- unsigned long detectTime; //the time we started the app, compared ot millis
- unsigned long resetTime;
- //the time we give the sensor to calibrate (10-60 secs according to the datasheet)
- int calibrationTime = 15;
- void setup() {
- Serial.begin(115200);
- delay(50);
- mySoftwareSerial.begin(9600);
- Serial.println(F("DFRobot DFPlayer Mini Demo"));
- Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
- if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
- Serial.println(F("Unable to begin:"));
- Serial.println(F("1.Please recheck the connection!"));
- Serial.println(F("2.Please insert the SD card!"));
- while(true){
- delay(0); // Code to compatible with ESP8266 watch dog.
- }
- }
- Serial.println(F("DFPlayer Mini online."));
- pinMode(inputPin, INPUT); // declare sensor as input
- pinMode(ledPin, OUTPUT); // declare LED as output
- //give the sensor some time to calibrate
- Serial.print("calibrating sensor ");
- for(int i = 0; i < calibrationTime; i++){
- Serial.print(".");
- delay(10);
- }
- Serial.println(" done");
- Serial.println("SENSOR ACTIVE");
- delay(50);
- //myDFPlayer.volume(25); //Set volume value. From 0 to 30
- delay(50);
- //Lights
- Serial.println("Lights...");
- FastLED.addLeds<WS2811, DATA_PIN>(leds, NUM_LEDS);
- delay(50);
- Serial.println(".....Online");
- //MouthSmile();
- }
- void loop()
- {
- val = digitalRead(inputPin); // read input value
- Serial.println(val);
- if (val == HIGH) { // check if the input is HIGH
- digitalWrite(ledPin, HIGH); // turn LED ON
- Serial.println("Motion detected!");
- detectTime = millis();
- //myDFPlayer.play(1);
- MouthOh();
- EyesLookLeft();
- EyesLookRight();
- MouthNo();
- EyesBlink();
- Eyes();
- EyesBlink();
- MouthSmile();
- Eyes();
- }
- else {
- digitalWrite(ledPin, LOW); // turn LED OFF
- Eyes();
- delay(50);
- EyesBlink();
- MouthSmile();
- Eyes();
- }
- }
- void Eyes()
- {
- //eyes
- fill_gradient(leds,NUM_LEDS-13,CHSV(1,1,200),NUM_LEDS,CHSV(1,1,200),SHORTEST_HUES);
- fill_solid(leds+(NUM_LEDS-7),4,CHSV(160,255,250));
- fill_solid(leds+(NUM_LEDS-9),2,CHSV(160,255,250));
- fill_solid(leds+(NUM_LEDS-14),2,CHSV(160,255,250));
- FastLED.show();
- delay(1000);
- }
- void EyesBlink()
- {
- Serial.println("Blink!");
- //eyes
- fill_gradient(leds,NUM_LEDS-14,CHSV(96,200,200),NUM_LEDS,CHSV(96,200,200),SHORTEST_HUES);
- //fill_solid(leds+(NUM_LEDS-7),4,CHSV(96,1,250));
- //fill_solid(leds+(NUM_LEDS-9),2,CHSV(96,1,250));
- //fill_solid(leds+(NUM_LEDS-14),2,CHSV(96,1,250));
- FastLED.show();
- delay(1000);
- //White/Blue
- //fill_gradient(leds,NUM_LEDS-13,CHSV(1,1,200),NUM_LEDS,CHSV(1,1,200),SHORTEST_HUES);
- //fill_solid(leds+(NUM_LEDS-7),4,CHSV(160,255,250));
- //fill_solid(leds+(NUM_LEDS-9),2,CHSV(160,255,250));
- //fill_solid(leds+(NUM_LEDS-14),2,CHSV(160,255,250));
- //FastLED.show();
- //delay(1000);
- }
- void EyesLookRight()
- {
- Serial.println("Eyes Right!");
- //eyes
- fill_gradient(leds,NUM_LEDS-13,CHSV(1,1,200),NUM_LEDS,CHSV(1,1,200),SHORTEST_HUES);
- fill_solid(leds+(NUM_LEDS-7),1,CHSV(1,1,250));
- fill_solid(leds+(NUM_LEDS-6),3,CHSV(160,255,250));
- fill_solid(leds+(NUM_LEDS-9),2,CHSV(160,255,250));
- fill_solid(leds+(NUM_LEDS-14),1,CHSV(160,255,250));
- FastLED.show();
- delay(2000);
- }
- void EyesLookLeft()
- {
- Serial.println("Eyes Left!");
- //eyes
- fill_gradient(leds,NUM_LEDS-13,CHSV(1,1,200),NUM_LEDS,CHSV(1,1,200),SHORTEST_HUES);
- fill_solid(leds+(NUM_LEDS-4),1,CHSV(160,255,250));
- fill_solid(leds+(NUM_LEDS-5),1,CHSV(1,1,250));
- fill_solid(leds+(NUM_LEDS-7),2,CHSV(160,255,250));
- fill_solid(leds+(NUM_LEDS-9),1,CHSV(160,255,250));
- fill_solid(leds+(NUM_LEDS-14),2,CHSV(160,255,250));
- FastLED.show();
- delay(2000);
- }
- void MouthSmile()
- {
- //mouth smile
- fill_solid(leds+16,20,CHSV(3,250,255));
- FastLED.show();
- delay (2000);
- }
- void MouthNo()
- {
- //mount no
- fill_solid(leds+16,20,CHSV(3,250,255));
- //fill_gradient(leds,(NUM_LEDS-13),CHSV(0,0,0),(NUM_LEDS-13),CHSV(0,0,0),SHORTEST_HUES);
- fill_gradient(leds,(NUM_LEDS-16),CHSV(0,0,0),(NUM_LEDS-15),CHSV(0,0,0),SHORTEST_HUES);
- fill_gradient(leds,(NUM_LEDS-25),CHSV(0,0,0),(NUM_LEDS-25),CHSV(0,0,0),SHORTEST_HUES);
- fill_gradient(leds,(NUM_LEDS-19),CHSV(0,0,0),(NUM_LEDS-21),CHSV(0,0,0),SHORTEST_HUES);
- fill_gradient(leds,(NUM_LEDS-23),CHSV(0,0,0),(NUM_LEDS-23),CHSV(0,0,0),SHORTEST_HUES);
- fill_gradient(leds,(NUM_LEDS-28),CHSV(0,0,0),(NUM_LEDS-27),CHSV(0,0,0),SHORTEST_HUES);
- fill_gradient(leds,(NUM_LEDS-31),CHSV(0,0,0),(NUM_LEDS-31),CHSV(0,0,0),SHORTEST_HUES);
- FastLED.show();
- delay (6000);
- }
- void MouthOh()
- {
- //mouth oh
- fill_solid(leds+16,20,CHSV(0,0,0));
- fill_gradient(leds,(NUM_LEDS-23),CHSV(3,250,255),(NUM_LEDS-23),CHSV(3,250,255),SHORTEST_HUES);
- fill_gradient(leds,(NUM_LEDS-28),CHSV(3,250,255),(NUM_LEDS-27),CHSV(3,250,255),SHORTEST_HUES);
- fill_gradient(leds,(NUM_LEDS-31),CHSV(3,250,255),(NUM_LEDS-31),CHSV(3,250,255),SHORTEST_HUES);
- FastLED.show();
- delay (6000);
- }
Advertisement
Add Comment
Please, Sign In to add comment