Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. #include <WiFi.h>
  2. #include <WiFiClient.h>
  3. #include <BlynkSimpleEsp32.h>
  4. #include "LEDStripDriver.h"
  5. #include <WiFiUdp.h>
  6. #include <NTPClient.h>
  7.  
  8.  
  9. WiFiUDP ntpUDP;
  10. NTPClient timeClient(ntpUDP);
  11.  
  12. // Variables to save date and time
  13. String formattedDate;
  14. String dayStamp;
  15. String timeStamp;
  16.  
  17. char auth[] = "UxAwK2hKxigEcSrPznFVc8chjHdEJR5b";
  18. char ssid[] = "OnePlus 5T";
  19. char pass[] = "bummelum";
  20.  
  21. LEDStripDriver led = LEDStripDriver(32, 33);
  22.  
  23. int red;
  24. int green;
  25. int blue;
  26. int toggle;
  27.  
  28. String wakeuptime;
  29. String currenttime;
  30. String sleeptime;
  31.  
  32. BLYNK_WRITE(V0){
  33. red = param[0].asInt();
  34. green = param[1].asInt();
  35. blue = param[2].asInt();
  36.  
  37. led.setColor(red, green, blue);
  38. }
  39.  
  40. BLYNK_WRITE(V1){
  41. toggle = param.asInt(); // assigning incoming value from pin V1 to a variabl
  42. if(toggle == 0){
  43. led.setColor(0,0,0);
  44. }
  45. }
  46.  
  47. BLYNK_WRITE(V2) {
  48. TimeInputParam t(param);
  49.  
  50. // Process start time
  51.  
  52. if (t.hasStartTime())
  53. {
  54. Serial.println(String("Start: ") + t.getStartHour() + ":" + t.getStartMinute() + ":" + t.getStartSecond());
  55. wakeuptime = String(t.getStartHour() + t.getStartMinute());
  56. }
  57. else if (t.isStartSunrise())
  58. {
  59. Serial.println("Start at sunrise");
  60. }
  61. else if (t.isStartSunset())
  62. {
  63. Serial.println("Start at sunset");
  64. }
  65. else
  66. {
  67. // Do nothing
  68. }
  69.  
  70. // Process stop time
  71.  
  72. if (t.hasStopTime())
  73. {
  74. Serial.println(String("Stop: ") + t.getStopHour() + ":" + t.getStopMinute() + ":" + t.getStopSecond());
  75. sleeptime = String(t.getStopHour() + t.getStopMinute());
  76. }
  77. else if (t.isStopSunrise())
  78. {
  79. Serial.println("Stop at sunrise");
  80. }
  81. else if (t.isStopSunset())
  82. {
  83. Serial.println("Stop at sunset");
  84. }
  85. else
  86. {
  87. // Do nothing: no stop time was set
  88. }
  89.  
  90. // Process timezone
  91. // Timezone is already added to start/stop time
  92.  
  93. Serial.println(String("Time zone: ") + t.getTZ());
  94.  
  95. // Get timezone offset (in seconds)
  96. Serial.println(String("Time zone offset: ") + t.getTZ_Offset());
  97.  
  98. // Process weekdays (1. Mon, 2. Tue, 3. Wed, ...)
  99.  
  100. for (int i = 1; i <= 7; i++) {
  101. if (t.isWeekdaySelected(i)) {
  102. Serial.println(String("Day ") + i + " is selected");
  103. }
  104. }
  105.  
  106. Serial.println();
  107. }
  108.  
  109. void setup(){
  110. Serial.begin(9600);
  111. timeClient.begin();
  112. timeClient.setTimeOffset(3600);
  113. Blynk.begin(auth, ssid, pass);
  114. led.setColor(255,255,255);
  115. }
  116.  
  117. void loop(){
  118. Blynk.run();
  119.  
  120. while(!timeClient.update()) {
  121. timeClient.forceUpdate();
  122. }
  123.  
  124. formattedDate = timeClient.getFormattedDate();
  125. currenttime = String(timeClient.getHours() + timeClient.getMinutes());
  126. if(currenttime == wakeuptime){
  127. led.setColor(113, 47, 0);
  128. }
  129.  
  130. if(currenttime == sleeptime){
  131. led.setColor(0,0,0);
  132. }
  133.  
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement