Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <BlynkSimpleEsp8266.h>
- #include <Arduino.h>
- #include <IRremoteESP8266.h>
- #include <IRsend.h>
- #include <WiFiUdp.h>
- #include <NTPClient.h>
- const uint16_t kIrLed = 5;
- const char* ssid = "SMITHCOM";
- const char* pass = "jugbogdan63";
- char auth[] = "TFobICoCdjPDz5wgxEQP3bM9iusES5HL";
- const long utcOffsetInSeconds = 3600;
- volatile int gomb = 0;
- volatile bool tick = false;
- volatile int minutes;
- volatile bool flag = false;
- unsigned long StartTime;
- IRsend irsend(kIrLed);
- WiFiUDP ntpUDP;
- NTPClient timeClient(ntpUDP, "1.rs.pool.ntp.org", utcOffsetInSeconds);
- bool checkTime(){
- timeClient.begin();
- timeClient.update();
- if(timeClient.getHours() > 10 && timeClient.getHours() < 21 || timeClient.getHours() == 11) {
- return false;
- }else{
- Serial.println("Between 11 and 22");
- return true;
- }
- }
- void setup() {
- tick = false;
- gomb = 0;
- irsend.begin();
- Serial.begin(115200);
- Serial.println("\nSerial up...");
- Blynk.begin(auth,ssid,pass,"SMITHPI",8080);
- Serial.println("Connecting to blynk...");
- checkTime();
- StartTime = millis();
- minutes = 0;
- }
- BLYNK_WRITE(V1){
- gomb = param.asInt();
- tick = true;
- Serial.println("\nRecieved: "+String(gomb));
- delay(10);
- }
- void loop() {
- Blynk.run();
- if(tick){
- switch(gomb){
- case 1: {
- irsend.sendNEC(0xF7C03F,32,1);
- Serial.println("\nIR send on");
- tick = false;
- delay(10);
- break;
- }
- case 2: {
- irsend.sendNEC(0xF740BF,32,1);
- Serial.println("\nIR send off");
- tick = false;
- delay(10);
- break;
- }
- case 3: {
- irsend.sendNEC(0xF700FF,32,1);
- Serial.println("\nIR send B+");
- tick = false;
- delay(10);
- break;
- }
- case 4: {
- irsend.sendNEC(0xF7807F,32,1);
- Serial.println("\nIR send B-");
- tick = false;
- delay(10);
- break;
- }
- case 5: {
- irsend.sendNEC(0xF7D02F,32,1);
- Serial.println("\nIR send Flash");
- tick = false;
- delay(10);
- break;
- }
- case 6: {
- irsend.sendNEC(0xF7F00F,32,1);
- Serial.println("\nIR send Strobe");
- tick = false;
- delay(10);
- break;
- }
- case 7: {
- irsend.sendNEC(0xF7C837,32,1);
- Serial.println("\nIR send Fade");
- tick = false;
- delay(10);
- break;
- }case 8: {
- irsend.sendNEC(0xF7E817,32,1);
- Serial.println("\nIR send Smooth");
- tick = false;
- delay(10);
- break;
- }
- case 9: {
- irsend.sendNEC(0xF720DF,32,1);
- Serial.println("\nIR send red");
- tick = false;
- delay(10);
- break;
- }
- case 10: {
- irsend.sendNEC(0xF7A05F,32,1);
- Serial.println("\nIR send Green");
- tick = false;
- delay(10);
- break;
- }
- case 11: {
- irsend.sendNEC(0xF7609F,32,1);
- Serial.println("\nIR send Blue");
- tick = false;
- delay(10);
- break;
- }
- case 12: {
- irsend.sendNEC(0xF7E01F,32,1);
- Serial.println("\nIR send White");
- tick = false;
- delay(10);
- break;
- }
- }
- }
- if((millis() - StartTime) > 5000){//felora 1800000
- StartTime = millis();
- Serial.println("An hour has passed checking time...");
- if(checkTime()){
- irsend.sendNEC(0xF7C03F,32,1);
- Serial.println("\nIR send on");
- tick = false;
- delay(10);
- }
- if(!checkTime() && flag == false){
- irsend.sendNEC(0xF740BF,32,1);
- Serial.println("\nIR send off");
- tick = false;
- flag = true;
- delay(10);
- }
- }
- delay(10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement