1
0

SwitchCallbackExample.ino 976 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include "Arduino.h"
  2. #include "avdweb_Switch.h"
  3. const byte toggleSwitchpin = 4;
  4. const byte multiresponseButtonpin = 12;
  5. Switch toggleSwitch = Switch(toggleSwitchpin);
  6. Switch multiresponseButton = Switch(multiresponseButtonpin);
  7. void buttonCallbackFunction(void* s) {
  8. Serial.print("Button: ");
  9. Serial.println((char*)s);
  10. }
  11. void toggleCallbackFunction(void* s) {
  12. Serial.print("Toggle: ");
  13. Serial.println((char*)s);
  14. }
  15. void setup()
  16. {
  17. Serial.begin(9600);
  18. toggleSwitch.setPushedCallback(&toggleCallbackFunction, (void*)"turned on");
  19. toggleSwitch.setReleasedCallback(&toggleCallbackFunction, (void*)"turned off");
  20. multiresponseButton.setLongPressCallback(&buttonCallbackFunction, (void*)"long press");
  21. multiresponseButton.setDoubleClickCallback(&buttonCallbackFunction, (void*)"double click");
  22. multiresponseButton.setSingleClickCallback(&buttonCallbackFunction, (void*)"single click");
  23. }
  24. void loop()
  25. {
  26. toggleSwitch.poll();
  27. multiresponseButton.poll();
  28. }