knight_rider1.ino 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include <Automaton.h>
  2. Atm_led led[6];
  3. Atm_timer timer;
  4. Atm_step step;
  5. Atm_analog pot;
  6. // Timer drives step sequencer in sweep mode, step sequencer blinks leds.
  7. short event = Atm_led::EVT_BLINK;
  8. static short pin_list[] = { 4, 5, 6, 7, 8, 9 };
  9. int blink_time = 70;
  10. int interval_time = 50;
  11. void setup() {
  12. // Initialize the step sequencer
  13. step.begin()
  14. .trigger( Atm_step::EVT_SWEEP );
  15. // Add the timer
  16. timer.begin( interval_time )
  17. .onTimer( step, Atm_step::EVT_STEP )
  18. .repeat( ATM_COUNTER_OFF );
  19. // Add the leds and link them to the step sequencer
  20. for ( short i = 0; i <= 5; i++ ) {
  21. led[i].begin( pin_list[i] )
  22. .blink( blink_time, 1, 1 );
  23. step.onStep( i, led[i], event );
  24. }
  25. pot.begin( A0 )
  26. .range( 10, 200 )
  27. .onChange( [] ( int idx, int v, int up ) {
  28. timer.interval( v );
  29. });
  30. // Move last led from step 5 to step 7 to make sweep work properly!
  31. step.onStep( 5 ).onStep( 9, led[5], event );
  32. timer.start();
  33. }
  34. void loop() {
  35. automaton.run();
  36. }