knight_rider3.ino 878 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <Automaton.h>
  2. Atm_player player; // A player machine
  3. const int ledPinMin = 4; // Use pins 4..9
  4. const int ledPinMax = 9;
  5. int pattern[] = { // Bitmapped pattern
  6. B00100000, 100, 0,
  7. B00010000, 100, 0,
  8. B00001000, 100, 0,
  9. B00000100, 100, 0,
  10. B00000010, 100, 0,
  11. B00000001, 100, 0,
  12. B00000010, 100, 0,
  13. B00000100, 100, 0,
  14. B00001000, 100, 0,
  15. B00010000, 100, 0,
  16. };
  17. void setup() {
  18. player.begin()
  19. .play( pattern, sizeof( pattern ) ) // Set up the pattern
  20. .onNote( true, []( int idx, int v, int up ) { // Called on every note
  21. for ( int i = ledPinMin; i <= ledPinMax; i++ ) {
  22. pinMode( i, OUTPUT ); // LED on/off according to bit
  23. digitalWrite( i, v & ( 1 << ( i - ledPinMin ) ) ? HIGH : LOW );
  24. }
  25. })
  26. .repeat( -1 ) // Repeat forever
  27. .start(); // Kickoff!
  28. }
  29. void loop() {
  30. automaton.run();
  31. }