Emakerz

Robot domotique ESP

Oct 9th, 2020 (edited)
1,386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // VIA CHAINE YOUTUBE EMAKERZ, https://www.youtube.com/channel/UCnNRQGz1SSgMGgFZzZRi8PA?view_as=subscriber
  2. #include <Arduino.h>
  3. #include <ESP8266WiFi.h>
  4. #include <BlynkSimpleEsp8266.h>
  5. #include "fauxmoESP.h"
  6. #include <Servo.h>  
  7.  
  8. char auth[] = "code blink";
  9. char WIFI_SSID[] = "nom wifi";
  10. char WIFI_PASS[] = "mdp wifi";
  11.  
  12. Servo servo;
  13. fauxmoESP fauxmo;
  14.  
  15. BLYNK_WRITE(V1) {
  16.   if( param.asInt() == 1 ){
  17.     servo.write(0);
  18.     delay(500);
  19.     servo.write(70);
  20.   }
  21. }
  22.  
  23. BLYNK_WRITE(V2) {
  24.   if( param.asInt() == 2 ){
  25.     servo.write(70);
  26.   }
  27.   else if ( param.asInt() == 3 ){
  28.     servo.write(0);
  29.   }
  30. }
  31.  
  32. void wifiSetup() {
  33.      WiFi.mode(WIFI_STA);
  34.  
  35.     // Connect
  36.     WiFi.begin(WIFI_SSID, WIFI_PASS);
  37.  
  38.     while (WiFi.status() != WL_CONNECTED) {
  39.         delay(100);
  40.     }
  41. }
  42.  
  43. void setup() {
  44.   servo.attach(0);
  45.  
  46.   Serial.begin(115200);
  47.   Blynk.begin(auth, WIFI_SSID, WIFI_PASS);
  48.  
  49.   // Wifi
  50.   wifiSetup();
  51.  
  52.   fauxmo.addDevice("emakerz");
  53.   fauxmo.setPort(80);
  54.   fauxmo.enable(true);
  55.  
  56.   fauxmo.onSetState([](unsigned char device_id, const char * device_name, bool state, unsigned char value) {
  57.     if(state) {
  58.       servo.write(0);
  59.     }
  60.     else {
  61.       servo.write(70);
  62.     }
  63.   });
  64. }
  65.  
  66. void loop() {
  67.   fauxmo.handle();
  68.   Blynk.run();
  69. }
  70. // VIA CHAINE YOUTUBE EMAKERZ, https://www.youtube.com/channel/UCnNRQGz1SSgMGgFZzZRi8PA?view_as=subscriber
Add Comment
Please, Sign In to add comment