Advertisement
Guest User

Eitan Rabinovitch hagever

a guest
Jan 18th, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #define readPin 2
  2. void setup(void) {
  3. pinMode(13, OUTPUT); // 13 has a built-in LED
  4. pinMode(2, INPUT);
  5. Serial.begin(9600);
  6. }
  7. int trueCode = 0;
  8. void loop() {
  9. if(digitalRead(readPin) == 0) {
  10. start();
  11. }
  12. if(trueCode == 1) {
  13. digitalWrite(13, HIGH);
  14. }
  15. }
  16. void start() {
  17. delay(300);
  18. if(checkFor(300) == true) {
  19. trueCode = 1;
  20. }
  21. }
  22. boolean checkFor(int delayTime) {
  23. unsigned long int lastMil = millis();
  24. boolean ret = false;
  25. while(true) {
  26. if(digitalRead(readPin) == 0) {
  27. ret = true;
  28. }
  29. if(millis() - lastMil >= delayTime) {
  30. return ret;
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement