Guest User

christmas tree

a guest
Dec 15th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.89 KB | None | 0 0
  1. #include "FastLED.h"
  2. #include "Arduino.h"
  3. #include "SoftwareSerial.h"
  4. #include "DFRobotDFPlayerMini.h"
  5. #define NUM_LEDS 50
  6. #define DATA_PIN 5
  7. #define CLOCK_PIN 13 //You probably don't need to worry about this
  8. #define BRIGHTNESS 48 //I believe this setting is over-ridden by the
  9. // third number in all the parentheses below
  10. // CHSV(#, #, BRIGHTNESS#)
  11.  
  12.  
  13. SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
  14. DFRobotDFPlayerMini myDFPlayer;
  15. void printDetail(uint8_t type, int value);
  16.  
  17. // Define the array of leds
  18. CRGB leds[NUM_LEDS];
  19.  
  20. int ledPin = 13; // choose the pin for the LED
  21. int inputPin = 2; // choose the input pin (for PIR sensor)
  22. int pirState = LOW; // we start, assuming no motion detected
  23. int val = 0; // variable for reading the pin status
  24. unsigned long detectTime; //the time we started the app, compared ot millis
  25. unsigned long resetTime;
  26.  
  27. //the time we give the sensor to calibrate (10-60 secs according to the datasheet)
  28. int calibrationTime = 15;
  29.  
  30.  
  31. void setup() {
  32. Serial.begin(115200);
  33. delay(50);
  34.  
  35. mySoftwareSerial.begin(9600);
  36. Serial.println(F("DFRobot DFPlayer Mini Demo"));
  37. Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
  38.  
  39. if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
  40. Serial.println(F("Unable to begin:"));
  41. Serial.println(F("1.Please recheck the connection!"));
  42. Serial.println(F("2.Please insert the SD card!"));
  43. while(true){
  44. delay(0); // Code to compatible with ESP8266 watch dog.
  45. }
  46. }
  47. Serial.println(F("DFPlayer Mini online."));
  48.  
  49.  
  50.  
  51. pinMode(inputPin, INPUT); // declare sensor as input
  52. pinMode(ledPin, OUTPUT); // declare LED as output
  53.  
  54. //give the sensor some time to calibrate
  55. Serial.print("calibrating sensor ");
  56. for(int i = 0; i < calibrationTime; i++){
  57. Serial.print(".");
  58. delay(10);
  59. }
  60. Serial.println(" done");
  61. Serial.println("SENSOR ACTIVE");
  62. delay(50);
  63.  
  64. //myDFPlayer.volume(25); //Set volume value. From 0 to 30
  65.  
  66. delay(50);
  67.  
  68. //Lights
  69. Serial.println("Lights...");
  70.  
  71. FastLED.addLeds<WS2811, DATA_PIN>(leds, NUM_LEDS);
  72. delay(50);
  73. Serial.println(".....Online");
  74.  
  75. //MouthSmile();
  76.  
  77.  
  78.  
  79. }
  80.  
  81. void loop()
  82. {
  83. val = digitalRead(inputPin); // read input value
  84. Serial.println(val);
  85.  
  86. if (val == HIGH) { // check if the input is HIGH
  87. digitalWrite(ledPin, HIGH); // turn LED ON
  88. Serial.println("Motion detected!");
  89. detectTime = millis();
  90.  
  91. //myDFPlayer.play(1);
  92. MouthOh();
  93. EyesLookLeft();
  94. EyesLookRight();
  95. MouthNo();
  96. EyesBlink();
  97. Eyes();
  98. EyesBlink();
  99. MouthSmile();
  100. Eyes();
  101.  
  102. }
  103. else {
  104. digitalWrite(ledPin, LOW); // turn LED OFF
  105. Eyes();
  106. delay(50);
  107. EyesBlink();
  108. MouthSmile();
  109. Eyes();
  110. }
  111. }
  112.  
  113.  
  114.  
  115.  
  116.  
  117. void Eyes()
  118. {
  119. //eyes
  120. fill_gradient(leds,NUM_LEDS-13,CHSV(1,1,200),NUM_LEDS,CHSV(1,1,200),SHORTEST_HUES);
  121. fill_solid(leds+(NUM_LEDS-7),4,CHSV(160,255,250));
  122. fill_solid(leds+(NUM_LEDS-9),2,CHSV(160,255,250));
  123. fill_solid(leds+(NUM_LEDS-14),2,CHSV(160,255,250));
  124. FastLED.show();
  125. delay(1000);
  126.  
  127. }
  128.  
  129.  
  130. void EyesBlink()
  131. {
  132.  
  133. Serial.println("Blink!");
  134. //eyes
  135. fill_gradient(leds,NUM_LEDS-14,CHSV(96,200,200),NUM_LEDS,CHSV(96,200,200),SHORTEST_HUES);
  136. //fill_solid(leds+(NUM_LEDS-7),4,CHSV(96,1,250));
  137. //fill_solid(leds+(NUM_LEDS-9),2,CHSV(96,1,250));
  138. //fill_solid(leds+(NUM_LEDS-14),2,CHSV(96,1,250));
  139. FastLED.show();
  140. delay(1000);
  141. //White/Blue
  142. //fill_gradient(leds,NUM_LEDS-13,CHSV(1,1,200),NUM_LEDS,CHSV(1,1,200),SHORTEST_HUES);
  143. //fill_solid(leds+(NUM_LEDS-7),4,CHSV(160,255,250));
  144. //fill_solid(leds+(NUM_LEDS-9),2,CHSV(160,255,250));
  145. //fill_solid(leds+(NUM_LEDS-14),2,CHSV(160,255,250));
  146. //FastLED.show();
  147. //delay(1000);
  148. }
  149.  
  150.  
  151.  
  152. void EyesLookRight()
  153. {
  154. Serial.println("Eyes Right!");
  155. //eyes
  156. fill_gradient(leds,NUM_LEDS-13,CHSV(1,1,200),NUM_LEDS,CHSV(1,1,200),SHORTEST_HUES);
  157. fill_solid(leds+(NUM_LEDS-7),1,CHSV(1,1,250));
  158. fill_solid(leds+(NUM_LEDS-6),3,CHSV(160,255,250));
  159. fill_solid(leds+(NUM_LEDS-9),2,CHSV(160,255,250));
  160. fill_solid(leds+(NUM_LEDS-14),1,CHSV(160,255,250));
  161. FastLED.show();
  162. delay(2000);
  163. }
  164.  
  165.  
  166. void EyesLookLeft()
  167. {
  168. Serial.println("Eyes Left!");
  169. //eyes
  170. fill_gradient(leds,NUM_LEDS-13,CHSV(1,1,200),NUM_LEDS,CHSV(1,1,200),SHORTEST_HUES);
  171. fill_solid(leds+(NUM_LEDS-4),1,CHSV(160,255,250));
  172. fill_solid(leds+(NUM_LEDS-5),1,CHSV(1,1,250));
  173. fill_solid(leds+(NUM_LEDS-7),2,CHSV(160,255,250));
  174. fill_solid(leds+(NUM_LEDS-9),1,CHSV(160,255,250));
  175. fill_solid(leds+(NUM_LEDS-14),2,CHSV(160,255,250));
  176. FastLED.show();
  177. delay(2000);
  178.  
  179. }
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186. void MouthSmile()
  187. {
  188. //mouth smile
  189. fill_solid(leds+16,20,CHSV(3,250,255));
  190. FastLED.show();
  191. delay (2000);
  192. }
  193.  
  194. void MouthNo()
  195. {
  196. //mount no
  197. fill_solid(leds+16,20,CHSV(3,250,255));
  198. //fill_gradient(leds,(NUM_LEDS-13),CHSV(0,0,0),(NUM_LEDS-13),CHSV(0,0,0),SHORTEST_HUES);
  199. fill_gradient(leds,(NUM_LEDS-16),CHSV(0,0,0),(NUM_LEDS-15),CHSV(0,0,0),SHORTEST_HUES);
  200. fill_gradient(leds,(NUM_LEDS-25),CHSV(0,0,0),(NUM_LEDS-25),CHSV(0,0,0),SHORTEST_HUES);
  201. fill_gradient(leds,(NUM_LEDS-19),CHSV(0,0,0),(NUM_LEDS-21),CHSV(0,0,0),SHORTEST_HUES);
  202. fill_gradient(leds,(NUM_LEDS-23),CHSV(0,0,0),(NUM_LEDS-23),CHSV(0,0,0),SHORTEST_HUES);
  203. fill_gradient(leds,(NUM_LEDS-28),CHSV(0,0,0),(NUM_LEDS-27),CHSV(0,0,0),SHORTEST_HUES);
  204. fill_gradient(leds,(NUM_LEDS-31),CHSV(0,0,0),(NUM_LEDS-31),CHSV(0,0,0),SHORTEST_HUES);
  205. FastLED.show();
  206. delay (6000);
  207. }
  208.  
  209.  
  210. void MouthOh()
  211. {
  212. //mouth oh
  213. fill_solid(leds+16,20,CHSV(0,0,0));
  214. fill_gradient(leds,(NUM_LEDS-23),CHSV(3,250,255),(NUM_LEDS-23),CHSV(3,250,255),SHORTEST_HUES);
  215. fill_gradient(leds,(NUM_LEDS-28),CHSV(3,250,255),(NUM_LEDS-27),CHSV(3,250,255),SHORTEST_HUES);
  216. fill_gradient(leds,(NUM_LEDS-31),CHSV(3,250,255),(NUM_LEDS-31),CHSV(3,250,255),SHORTEST_HUES);
  217. FastLED.show();
  218. delay (6000);
  219. }
Advertisement
Add Comment
Please, Sign In to add comment