Advertisement
mealsowheels

Untitled

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