Advertisement
Krzyspx

BLYNK - Test pinów wirtualnych

Aug 16th, 2017
1,286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.46 KB | None | 0 0
  1. #define BLYNK_PRINT Serial
  2. #include <ESP8266WiFi.h>
  3. #include <BlynkSimpleEsp8266.h>
  4.  
  5. #include "dallas.h"
  6. #include <OneWire.h>
  7. #include <DallasTemperature.h>
  8. #include <Timers.h> //  my favorite timer
  9. Timers <2> akcja; //
  10.  
  11. char auth[] = "f845be3b89e74d28b164bd8a9c1d38ba"; //konto na local server konto blynk.pl@gmail.com
  12. char ssid[] = "xxxxxxxxxx";
  13. char pass[] = "yyyyyyyyyyyyyy";
  14.  
  15. #define led_blue 14
  16. #define led_bialy 12
  17. #define klaw1 4
  18. #define klaw2 5
  19.  
  20. #define BLYNK_GREEN     "#23C48E"
  21. #define BLYNK_BLUE      "#04C0F8"
  22. #define BLYNK_YELLOW    "#ED9D00"
  23. #define BLYNK_RED       "#D3435C"
  24. #define BLYNK_DARK_BLUE "#5F7CD8"
  25. #define _RED            "#FF0000"
  26. #define _GREEN          "#00FF00"
  27.  
  28. int button1=0;
  29.  
  30. void testklaw();
  31.  
  32. void setup()
  33. {
  34.   pinMode(led_blue, OUTPUT); //LED niebieski
  35.   pinMode(led_bialy, OUTPUT); //LED bialy
  36.   pinMode(klaw1, INPUT);
  37.   pinMode(klaw2, INPUT);
  38.  
  39.   Serial.begin(115200);
  40.   delay(100);
  41.   Serial.println();
  42.   Serial.println();
  43.   Serial.println(F(__FILE__));  //BLYNK .4.8 Arduino IDE.cc 1.8.3
  44.  
  45.   akcja.attach(0, 1000, timer1sek); //  1 sek
  46.   setdallas(); //setup for ds18b20
  47.  
  48.   Blynk.begin(auth, ssid, pass, IPAddress(192, 168, 2, 19));
  49. }
  50.  
  51. void loop()
  52. {
  53.   akcja.process(); // timer
  54.   Blynk.run();
  55. }
  56.  
  57. void timer1sek() { //różne rzeczy wykonywane cyklicznie
  58.   sensorT();    //dallas
  59.   testklaw();
  60. }
  61.  
  62. void testklaw()
  63. {
  64.   int  k1 = digitalRead(klaw1);
  65.   if (k1 == 1) {
  66.  
  67.   } else {
  68.     Blynk.virtualWrite(V1, HIGH);
  69.     Blynk.setProperty(V1, "onLabel", "press klaw1");
  70.  
  71.   }
  72.   int  k2 = digitalRead(klaw2);
  73.   if (k2 == 1) {
  74.     Blynk.setProperty(V1, "color", BLYNK_GREEN);
  75.   } else {
  76.     Blynk.virtualWrite(V1, HIGH);
  77.     Blynk.setProperty(V1, "onLabel", "press klaw2");
  78.     Blynk.setProperty(V1, "color", _RED);
  79.   }
  80.   if(button1 == 4){
  81.         Blynk.setProperty(V1, "onLabel", tempstr);
  82.   }
  83. }
  84.  
  85. //  Blynk.setProperty(V0, "color", gaugeColor); onLabel
  86. BLYNK_WRITE(V1)
  87. {
  88.    button1 = param.asInt(); // assigning incoming value from pin V1 to a variable
  89.   // You can also use: String i = param.asStr(); double d = param.asDouble();
  90.   if (button1 == 0) {
  91.     digitalWrite(led_blue, HIGH);
  92.     digitalWrite(led_bialy, HIGH);
  93.         Blynk.setProperty(V1, "onLabel", "on");
  94.   };
  95.   if (button1 == 1) {
  96.     digitalWrite(led_blue, LOW);
  97.   };
  98.   if (button1 == 2) {
  99.     digitalWrite(led_bialy, LOW);
  100.   };
  101.   if (button1 == 3) {
  102.     digitalWrite(led_blue, LOW);
  103.     digitalWrite(led_bialy, LOW);
  104.   };
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement