Advertisement
prampec

SoftTimer - Delay example

Apr 20th, 2018
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <PciManager.h>
  2. #include <SoftTimer.h>
  3. #include <Debouncer.h>
  4. #include <DelayRun.h>
  5.  
  6. #define INPUT_PIN 3
  7.  
  8. // -- Define method signatures.
  9. void onPinChanged();
  10. // -- Define method signatures.
  11. boolean doDelayed(Task* task);
  12.  
  13. Debouncer debouncer(INPUT_PIN, MODE_CLOSE_ON_PUSH, onPinChanged, NULL);
  14. // -- Runs after 3 seconds
  15. DelayRun delayTask(3000, doDelayed);
  16.  
  17. boolean waitingSecondEvent = false;
  18.  
  19. void setup() {
  20.   Serial.begin(9800);
  21.   PciManager.registerListener(INPUT_PIN, &debouncer);
  22.   Serial.println("Ready.");
  23.  
  24. }
  25.  
  26. void onPinChanged() {
  27.   if (!waitingSecondEvent)
  28.   {
  29.     Serial.println("First event detected");
  30.     delayTask.startDelayed();
  31.     waitingSecondEvent = true;
  32.   }
  33.   Serial.println("Second event occurred");
  34.   waitingSecondEvent = false;
  35.   SoftTimer.remove(&delayTask);
  36. }
  37.  
  38. boolean doDelayed(Task* task) {
  39.   Serial.println("No second event within 3 secs");
  40.   waitingSecondEvent = false;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement