Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <WiFi.h>
- #include <WiFiClient.h>
- #include <BlynkSimpleEsp32.h>
- #include "LEDStripDriver.h"
- #include <WiFiUdp.h>
- #include <NTPClient.h>
- WiFiUDP ntpUDP;
- NTPClient timeClient(ntpUDP);
- // Variables to save date and time
- String formattedDate;
- String dayStamp;
- String timeStamp;
- char auth[] = "UxAwK2hKxigEcSrPznFVc8chjHdEJR5b";
- char ssid[] = "OnePlus 5T";
- char pass[] = "bummelum";
- LEDStripDriver led = LEDStripDriver(32, 33);
- int red;
- int green;
- int blue;
- int toggle;
- String wakeuptime;
- String currenttime;
- String sleeptime;
- BLYNK_WRITE(V0){
- red = param[0].asInt();
- green = param[1].asInt();
- blue = param[2].asInt();
- led.setColor(red, green, blue);
- }
- BLYNK_WRITE(V1){
- toggle = param.asInt(); // assigning incoming value from pin V1 to a variabl
- if(toggle == 0){
- led.setColor(0,0,0);
- }
- }
- BLYNK_WRITE(V2) {
- TimeInputParam t(param);
- // Process start time
- if (t.hasStartTime())
- {
- Serial.println(String("Start: ") + t.getStartHour() + ":" + t.getStartMinute() + ":" + t.getStartSecond());
- wakeuptime = String(t.getStartHour() + t.getStartMinute());
- }
- else if (t.isStartSunrise())
- {
- Serial.println("Start at sunrise");
- }
- else if (t.isStartSunset())
- {
- Serial.println("Start at sunset");
- }
- else
- {
- // Do nothing
- }
- // Process stop time
- if (t.hasStopTime())
- {
- Serial.println(String("Stop: ") + t.getStopHour() + ":" + t.getStopMinute() + ":" + t.getStopSecond());
- sleeptime = String(t.getStopHour() + t.getStopMinute());
- }
- else if (t.isStopSunrise())
- {
- Serial.println("Stop at sunrise");
- }
- else if (t.isStopSunset())
- {
- Serial.println("Stop at sunset");
- }
- else
- {
- // Do nothing: no stop time was set
- }
- // Process timezone
- // Timezone is already added to start/stop time
- Serial.println(String("Time zone: ") + t.getTZ());
- // Get timezone offset (in seconds)
- Serial.println(String("Time zone offset: ") + t.getTZ_Offset());
- // Process weekdays (1. Mon, 2. Tue, 3. Wed, ...)
- for (int i = 1; i <= 7; i++) {
- if (t.isWeekdaySelected(i)) {
- Serial.println(String("Day ") + i + " is selected");
- }
- }
- Serial.println();
- }
- void setup(){
- Serial.begin(9600);
- timeClient.begin();
- timeClient.setTimeOffset(3600);
- Blynk.begin(auth, ssid, pass);
- led.setColor(255,255,255);
- }
- void loop(){
- Blynk.run();
- while(!timeClient.update()) {
- timeClient.forceUpdate();
- }
- formattedDate = timeClient.getFormattedDate();
- currenttime = String(timeClient.getHours() + timeClient.getMinutes());
- if(currenttime == wakeuptime){
- led.setColor(113, 47, 0);
- }
- if(currenttime == sleeptime){
- led.setColor(0,0,0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement