Guest User

Untitled

a guest
Sep 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1.  
  2. #include <Arduino.h>
  3. #include "Switch.h"
  4.  
  5. Switch::Switch(unsigned char pin)
  6. {
  7. this->pin = pin;
  8. this->set = false;
  9. pinMode(pin, INPUT); // set pin to input
  10. digitalWrite(pin, HIGH); // turn on pullup resistors
  11. }
  12.  
  13. boolean Switch::isSet()
  14. {
  15. return 0==digitalRead(this->pin);
  16. }
  17.  
  18. // if changed returns true, check sw.set for new value
  19. boolean Switch::changed()
  20. {
  21. boolean wasSet = this->set;
  22. this->set = this->isSet();
  23. return (this->set != wasSet);
  24. }
Add Comment
Please, Sign In to add comment