nuclear_missile_launcher.ino 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <Automaton.h>
  2. // Safe controller for a Nuclear Missile Launcher
  3. Atm_led countdown, ignition;
  4. Atm_button button1, button2;
  5. Atm_bit bit1, bit2;
  6. Atm_timer timer1, timer2;
  7. Atm_controller ctrl;
  8. const int pinButton1 = 2;
  9. const int pinButton2 = 3;
  10. const int pinCountdownLed = 8;
  11. const int pinIgnitionLed = 9;
  12. const int buttonIntervalMax = 2000;
  13. const int countdownCount = 10;
  14. const int countdownFlashOn = 100;
  15. const int countdownFlashOff = 900;
  16. void setup() {
  17. // Self resetting button 1
  18. button1.begin( pinButton1 )
  19. .onPress( bit1, bit1.EVT_ON );
  20. timer1.begin( buttonIntervalMax )
  21. .onTimer( bit1, bit1.EVT_OFF );
  22. bit1.begin( false ).led( 4 )
  23. .onChange( true, timer1, timer1.EVT_START );
  24. // Self resetting button 2
  25. button2.begin( pinButton2 )
  26. .onPress( bit2, bit2.EVT_ON );
  27. timer2.begin( buttonIntervalMax )
  28. .onTimer( bit2, bit2.EVT_OFF );
  29. bit2.begin( false ).led( 5 )
  30. .onChange( true, timer2, timer2.EVT_START );
  31. // Controller
  32. ctrl.begin( false )
  33. .IF( bit1 ).AND( bit2 )
  34. .onChange( true, countdown, countdown.EVT_BLINK );
  35. // Countdown led
  36. countdown.begin( pinCountdownLed )
  37. .blink( countdownFlashOn, countdownFlashOff, countdownCount )
  38. .onFinish( ignition, ignition.EVT_ON );
  39. // Ignition
  40. ignition.begin( pinIgnitionLed );
  41. }
  42. void loop() {
  43. automaton.run();
  44. }