Advertisement
Guest User

i hate obudna

a guest
Aug 23rd, 2019
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.75 KB | None | 0 0
  1. #include <BlynkSimpleEsp8266.h>
  2. #include <Arduino.h>
  3. #include <IRremoteESP8266.h>
  4. #include <IRsend.h>
  5. #include <WiFiUdp.h>
  6. #include <NTPClient.h>
  7.  
  8. const uint16_t kIrLed = 5;
  9. const char* ssid = "SMITHCOM";
  10. const char* pass = "jugbogdan63";
  11. char auth[] = "TFobICoCdjPDz5wgxEQP3bM9iusES5HL";
  12.  
  13. const long utcOffsetInSeconds = 3600;
  14.  
  15. volatile int gomb = 0;
  16. volatile bool tick = false;
  17. volatile int minutes;
  18.  
  19. volatile bool flag = false;
  20.  
  21. unsigned long StartTime;
  22.  
  23. IRsend irsend(kIrLed);
  24. WiFiUDP ntpUDP;
  25. NTPClient timeClient(ntpUDP, "1.rs.pool.ntp.org", utcOffsetInSeconds);
  26.  
  27. bool checkTime(){
  28.   timeClient.begin();
  29.   timeClient.update();
  30.   if(timeClient.getHours() > 10 && timeClient.getHours() < 21 || timeClient.getHours() == 11) {
  31.     return false;
  32.   }else{
  33.     Serial.println("Between 11 and 22");
  34.     return true;
  35.   }
  36. }
  37.  
  38.  
  39. void setup() {
  40.   tick = false;
  41.   gomb = 0;
  42.   irsend.begin();
  43.   Serial.begin(115200);
  44.   Serial.println("\nSerial up...");
  45.   Blynk.begin(auth,ssid,pass,"SMITHPI",8080);
  46.   Serial.println("Connecting to blynk...");
  47.   checkTime();
  48.   StartTime = millis();
  49.   minutes = 0;
  50.  
  51. }
  52. BLYNK_WRITE(V1){
  53.   gomb = param.asInt();
  54.   tick = true;
  55.   Serial.println("\nRecieved: "+String(gomb));
  56.   delay(10);
  57. }
  58. void loop() {
  59.   Blynk.run();
  60.   if(tick){
  61.     switch(gomb){
  62.       case 1: {
  63.         irsend.sendNEC(0xF7C03F,32,1);
  64.         Serial.println("\nIR send on");
  65.         tick = false;
  66.         delay(10);
  67.         break;
  68.       }
  69.       case 2: {
  70.         irsend.sendNEC(0xF740BF,32,1);
  71.         Serial.println("\nIR send off");
  72.         tick = false;
  73.         delay(10);
  74.         break;
  75.       }
  76.       case 3: {
  77.         irsend.sendNEC(0xF700FF,32,1);
  78.         Serial.println("\nIR send B+");
  79.         tick = false;
  80.         delay(10);
  81.         break;
  82.       }
  83.       case 4: {
  84.         irsend.sendNEC(0xF7807F,32,1);
  85.         Serial.println("\nIR send B-");
  86.         tick = false;
  87.         delay(10);
  88.         break;
  89.       }
  90.       case 5: {
  91.         irsend.sendNEC(0xF7D02F,32,1);
  92.         Serial.println("\nIR send Flash");
  93.         tick = false;
  94.         delay(10);
  95.         break;
  96.       }
  97.       case 6: {
  98.         irsend.sendNEC(0xF7F00F,32,1);
  99.         Serial.println("\nIR send Strobe");
  100.         tick = false;
  101.         delay(10);
  102.         break;
  103.       }
  104.       case 7: {
  105.         irsend.sendNEC(0xF7C837,32,1);
  106.         Serial.println("\nIR send Fade");
  107.         tick = false;
  108.         delay(10);
  109.         break;
  110.       }case 8: {
  111.         irsend.sendNEC(0xF7E817,32,1);
  112.         Serial.println("\nIR send Smooth");
  113.         tick = false;
  114.         delay(10);
  115.         break;
  116.       }
  117.       case 9: {
  118.         irsend.sendNEC(0xF720DF,32,1);
  119.         Serial.println("\nIR send red");
  120.         tick = false;
  121.         delay(10);
  122.         break;
  123.       }
  124.       case 10: {
  125.         irsend.sendNEC(0xF7A05F,32,1);
  126.         Serial.println("\nIR send Green");
  127.         tick = false;
  128.         delay(10);
  129.         break;
  130.       }
  131.       case 11: {
  132.         irsend.sendNEC(0xF7609F,32,1);
  133.         Serial.println("\nIR send Blue");
  134.         tick = false;
  135.         delay(10);
  136.         break;
  137.       }
  138.       case 12: {
  139.         irsend.sendNEC(0xF7E01F,32,1);
  140.         Serial.println("\nIR send White");
  141.         tick = false;
  142.         delay(10);
  143.         break;
  144.       }
  145.     }
  146.   }
  147.   if((millis() - StartTime) > 5000){//felora 1800000
  148.     StartTime = millis();
  149.     Serial.println("An hour has passed checking time...");
  150.     if(checkTime()){
  151.       irsend.sendNEC(0xF7C03F,32,1);
  152.       Serial.println("\nIR send on");
  153.       tick = false;
  154.       delay(10);
  155.     }
  156.     if(!checkTime() && flag == false){
  157.       irsend.sendNEC(0xF740BF,32,1);
  158.       Serial.println("\nIR send off");
  159.       tick = false;
  160.       flag = true;
  161.       delay(10);
  162.     }
  163.   }
  164.   delay(10);
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement