Created
December 22, 2020 21:51
-
-
Save DanielMerzo/05e18d014364648161d2a03cdad4643c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#include <BlynkSimpleEsp8266.h> | |
#include <SPI.h> | |
#include <TimeLib.h> | |
#include <WidgetRTC.h> | |
#include <FastLED.h> | |
#define BLYNK_PRINT Serial | |
char auth[] = "1rWXweJQvE1YYWdx7fMNPsqt7lOIsxBf"; | |
char ssid[] = "FRITZ!Box_1"; | |
char pass[] = "1M+S7Dx/GT2i3Z%W?8Jd"; | |
BlynkTimer timer; | |
WidgetRTC rtc; | |
void clockDisplay() | |
{ | |
String currentTime = String(hour()) + ":" + minute() + ":" + second(); | |
String currentDate = String(day()) + " " + month() + " " + year(); | |
Serial.print("Current time: "); | |
Serial.print(currentTime); | |
Serial.print(" "); | |
Serial.print(currentDate); | |
Serial.println(); | |
// Send time to the App | |
Blynk.virtualWrite(V1, currentTime); | |
// Send date to the App | |
Blynk.virtualWrite(V2, currentDate); | |
} | |
BLYNK_CONNECTED() { | |
// Synchronize time on connection | |
rtc.begin(); | |
} | |
#define Taster D1 | |
#define NUM_LEDS 3 | |
#define DATA_PIN D7 | |
int Helligkeit = 1; | |
CRGB leds[NUM_LEDS]; | |
BLYNK_WRITE(V4) { | |
TimeInputParam t(param); | |
// Process start time | |
if (t.hasStartTime()) | |
{ | |
Serial.println(String("Start: ") + | |
t.getStartHour() + ":" + | |
t.getStartMinute() + ":" + | |
t.getStartSecond()); | |
} | |
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()); | |
} | |
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(115200); | |
Blynk.begin(auth, ssid, pass, "iot.informatik.uni-oldenburg.de", 8080); | |
pinMode(Taster, INPUT); | |
setSyncInterval(10 * 60); | |
timer.setInterval(1000L, clockDisplay); | |
delay(1000); | |
FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS); | |
FastLED.setMaxPowerInVoltsAndMilliamps(5,400); | |
FastLED.setBrightness(CRGB(0,0,0)); | |
} | |
void loop() | |
{ | |
leds[0] = CRGB(255, 147, 51); | |
leds[1] = CRGB(255, 147, 51); | |
leds[2] = CRGB(255, 147, 51); | |
FastLED.show(); | |
delay(1000); | |
Blynk.run(); | |
timer.run(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment