button.ino 852 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include <Automaton.h>
  2. // Start by creating a bunch of state machines
  3. Atm_led led1, led2, led3; // Three Automaton led machines
  4. Atm_button btn; // An Automaton button machine
  5. Atm_fan fan; // To split the trigger in 3
  6. void setup() {
  7. // Initialize the led machines at different rates
  8. led1.begin( 4 ).blink( 100, 100 );
  9. led2.begin( 5 ).blink( 200, 200 );
  10. led3.begin( 6 ).blink( 400, 400 );
  11. // Send one event to many
  12. fan.begin()
  13. .onInput( led1, led1.EVT_TOGGLE_BLINK )
  14. .onInput( led2, led2.EVT_TOGGLE_BLINK )
  15. .onInput( led3, led3.EVT_TOGGLE_BLINK );
  16. // Button triggers the fan
  17. btn.begin( 2 )
  18. .onPress( fan, fan.EVT_INPUT );
  19. // Start the blinking
  20. fan.trigger( fan.EVT_INPUT );
  21. }
  22. // Run the app from the Arduino loop()
  23. // Press the button to toggle the leds on and off
  24. void loop() {
  25. automaton.run();
  26. }