led_fuel_gauge.ino 664 B

1234567891011121314151617181920212223242526272829
  1. #include <Automaton.h>
  2. // Turning a pot on A0 will change a led gauge on pins 4, 5, 6, 7, 8, 9
  3. Atm_comparator cmp;
  4. Atm_led led[6];
  5. Atm_step step;
  6. static uint16_t threshold_list[] = { 100, 300, 500, 700, 900, 1000 };
  7. static short pin_list[] = { 4, 5, 6, 7, 8, 9 };
  8. void setup() {
  9. cmp.begin( A0, 50 )
  10. .threshold( threshold_list, sizeof( threshold_list ), true )
  11. .onChange( true, step, Atm_step::EVT_STEP )
  12. .onChange( false, step, Atm_step::EVT_BACK );
  13. step.begin();
  14. for ( short i = 0; i <= 5; i++ ) {
  15. led[i].begin( pin_list[i] );
  16. step.onStep( i, led[i], Atm_led::EVT_TOGGLE );
  17. }
  18. }
  19. void loop() {
  20. automaton.run();
  21. }