Advertisement
mealsowheels

Untitled

Mar 26th, 2021
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. Servo servo;
  4.  
  5. #define potInput A0
  6. int relayOutput = 15;
  7. int buttonInput = 13;
  8. int servoOutput = 12;
  9. uint32_t servoSetLeft;
  10.  
  11. void setup()
  12. {
  13. pinMode(relayOutput, OUTPUT);
  14. pinMode(buttonInput, INPUT);
  15. pinMode(potInput, INPUT);
  16.  
  17. servo.attach(servoOutput);
  18. }
  19.  
  20. void loop()
  21. {
  22. ESP.rtcUserMemoryRead(33, &servoSetLeft, sizeof(servoSetLeft));
  23. if(digitalRead(buttonInput) == LOW)
  24. {
  25. if(servoSetLeft == 0x00)
  26. {
  27. servoSetLeft = 0xff;
  28. ESP.rtcUserMemoryWrite(33, &servoSetLeft, sizeof(servoSetLeft));
  29. digitalWrite(relayOutput, HIGH);
  30. delay(100);
  31. servo.write(50);
  32. delay(1500);
  33. digitalWrite(relayOutput, LOW);
  34. }
  35. else if(servoSetLeft == 0xff)
  36. {
  37. digitalWrite(relayOutput, HIGH);
  38. delay(100);
  39. servo.write(140);
  40. delay(1500);
  41. digitalWrite(relayOutput, LOW);
  42. servoSetLeft = 0x00;
  43. ESP.rtcUserMemoryWrite(33, &servoSetLeft, sizeof(servoSetLeft));
  44. }
  45. }
  46. ESP.deepSleep(60e6);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement