SHARE
TWEET

Untitled

a guest Dec 10th, 2018 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define BLYNK_PRINT stdout
  2. #ifdef RASPBERRY
  3.  #include <BlynkApiWiringPi.h>
  4. #else
  5.  #include <BlynkApiLinux.h>
  6. #endif
  7. #include <BlynkSocket.h>
  8. #include <BlynkOptionsParser.h>
  9. static BlynkTransportSocket _blynkTransport;
  10. BlynkSocket Blynk(_blynkTransport);
  11. #include <BlynkWidgets.h>
  12. #include <ctime>
  13. #include <string>
  14.  
  15. long lastChangeTime = 0;
  16. int pulse = 0;
  17. bool state;
  18. bool stopb = false;
  19. long m;
  20. long sb;
  21. long under_target = 0;
  22. int active = 0;
  23. int turno;
  24. int target;
  25. int calibration;
  26. string stringa1 = "";
  27. string stringa2 = "";
  28.  
  29.  
  30. void setup()
  31. {
  32.   pinMode(21, INPUT);
  33.   m = millis();
  34. }
  35.  
  36. void loop()
  37. {
  38.  Blynk.run();
  39.  
  40.  time_t now = time(0);
  41.  tm *ltm = localtime(&now);
  42.  int mese = 1 + ltm->tm_mon;
  43.  int giorno = ltm->tm_mday;
  44.  int ora = 1 + ltm->tm_hour;
  45.  int minuti = 1 + ltm->tm_min;
  46.  
  47.  if (ora == 5 && minuti == 1) {
  48.   stringa1 = "";
  49.   stringa1.append(to_string(giorno));
  50.   stringa1.append(to_string(mese));
  51.   stringa1.append(to_string(turno));
  52.  
  53.   stringa2 = "";
  54.   stringa2.append(to_string(giorno));
  55.   stringa2.append("/");
  56.   stringa2.append(to_string(mese));
  57.   stringa2.append(" ");
  58.   stringa2.append(to_string(turno));
  59.  
  60.   Blynk.virtualWrite(V1, "add", stoi(stringa1), stringa2, (100-under_target));
  61.   turno = 1;
  62.   active = 0;
  63.   under_target = 0;
  64.   Blynk.virtualWrite(V6, turno);
  65.  }
  66.  
  67.  if (ora == 13 && minuti == 1){
  68.   stringa1 = "";
  69.   stringa1.append(to_string(giorno));
  70.   stringa1.append(to_string(mese));
  71.   stringa1.append(to_string(turno));
  72.  
  73.   stringa2 = "";
  74.   stringa2.append(to_string(giorno));
  75.   stringa2.append("/");
  76.   stringa2.append(to_string(mese));
  77.   stringa2.append(" ");
  78.   stringa2.append(to_string(turno));
  79.  
  80.   Blynk.virtualWrite(V1, "add", stoi(stringa1), stringa2, (100-under_target));
  81.   turno = 2;
  82.   active = 0;
  83.   under_target = 0;
  84.   Blynk.virtualWrite(V6, turno);
  85.  }
  86.  
  87.  if (ora == 21 && minuti == 1) {
  88.   stringa1 = "";
  89.   stringa1.append(to_string(giorno));
  90.   stringa1.append(to_string(mese));
  91.   stringa1.append(to_string(turno));
  92.  
  93.   stringa2 = "";
  94.   stringa2.append(to_string(giorno));
  95.   stringa2.append("/");
  96.   stringa2.append(to_string(mese));
  97.   stringa2.append(" ");
  98.   stringa2.append(to_string(turno));
  99.  
  100.   Blynk.virtualWrite(V1, "add", stoi(stringa1), stringa2, (100-under_target));
  101.   turno = 3;
  102.   active = 0;
  103.   under_target = 0;
  104.   Blynk.virtualWrite(V6, turno);
  105. }
  106.   long t = millis();
  107.   while (millis() - t < 5000) {
  108.     state = digitalRead(21);
  109.     if (state && stopb == false) {
  110.         sb = millis();
  111.         stopb = true;
  112.         pulse++;
  113.     }
  114.  
  115.     if (millis() - sb > 50){
  116.          stopb = false;
  117.     }
  118.   }
  119.   if (pulse > 40) pulse = 0;
  120.   if (pulse*12 <= target) under_target+=5;
  121.   if (pulse*12 > 5) active+=5;
  122.  
  123.  
  124.   Blynk.virtualWrite(V5, ((under_target*100)/28800)); //pin under target
  125.   Blynk.virtualWrite(V4, ((active*100)/28800)); //pin attiva
  126.   Blynk.virtualWrite(V3, (100 - ((under_target*100)/28800))); //pin performance
  127.   Blynk.virtualWrite(V1, (pulse*12*calibration)); //
  128.   Blynk.virtualWrite(V8, (target)); //Assegna a V8 il valore target
  129.   pulse = 0;
  130. }
  131.  
  132. BLYNK_WRITE(V2) //pin del target
  133. {
  134.    target = param.asInt();
  135. }
  136. BLYNK_WRITE(V7) //pin calibration
  137. {
  138.    calibration = param.asInt();
  139. }
  140.  
  141. int main(int argc, char* argv[])
  142. {
  143.   const char *auth, *serv;
  144.   uint16_t port;
  145.   parse_options(argc, argv, auth, serv, port);
  146.  
  147.   Blynk.begin(auth, serv, port);
  148.  
  149.   setup();
  150.   while(true) {
  151.     loop();
  152.  
  153.   }
  154.  
  155.   return 0;
  156. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top