Atm_blink.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "Atm_blink.h"
  2. Atm_blink & Atm_blink::begin( int attached_pin, uint32_t blinkrate ) {
  3. const static state_t state_table[] PROGMEM = {
  4. /* ON_ENTER ON_LOOP ON_EXIT EVT_TIMER EVT_ON EVT_OFF ELSE */
  5. /* IDLE */ ENT_OFF, -1, -1, -1, LED_ON, -1, -1,
  6. /* LED_ON */ ENT_ON, -1, -1, LED_OFF, -1, IDLE, -1,
  7. /* LED_OFF */ ENT_OFF, -1, -1, LED_ON, -1, IDLE, -1,
  8. };
  9. Machine::begin( state_table, ELSE );
  10. pin = attached_pin;
  11. timer.set( blinkrate );
  12. pinMode( pin, OUTPUT );
  13. return *this;
  14. }
  15. int Atm_blink::event( int id ) {
  16. switch ( id ) {
  17. case EVT_TIMER :
  18. return timer.expired( this );
  19. }
  20. return 0;
  21. }
  22. void Atm_blink::action( int id ) {
  23. switch ( id ) {
  24. case ENT_ON :
  25. digitalWrite( pin, HIGH );
  26. return;
  27. case ENT_OFF :
  28. digitalWrite( pin, LOW );
  29. return;
  30. }
  31. }
  32. Atm_blink & Atm_blink::trace( Stream & stream ) {
  33. Machine::setTrace( &stream, atm_serial_debug::trace,
  34. "BLINK\0EVT_TIMER\0EVT_ON\0EVT_OFF\0ELSE\0IDLE\0LED_ON\0LED_OFF" );
  35. return *this;
  36. }