Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * simple led / push button based Arduino puzzle.
- */
- #include <Arduino.h>
- #include "Led.hh"
- #include "Button.hh"
- Led internal(13);
- Led lamp[] = { Led(3), Led(4), Led(5), Led(7), Led(8) };
- const int nlamp = sizeof(lamp) / sizeof(*lamp);
- Button button[] = { Button(10), Button(11), Button(12) };
- const int nbutton = sizeof(button) / sizeof(*button);
- void setup() {
- internal.turn_on();
- // init
- internal.turn_off();
- }
- void loop() {
- const int btn0 = (button[0].probe() == Button::CHANGED_AND_PRESSED);
- const int btn1 = (button[1].probe() == Button::CHANGED_AND_PRESSED);
- const int btn2 = (button[2].probe() == Button::CHANGED_AND_PRESSED);
- /* toggle 0, 1, 2 if button 0, 1, 2 is pressed (respectively) */
- if (btn0)
- lamp[0].toggle();
- if (btn1)
- lamp[1].toggle();
- if (btn2)
- lamp[2].toggle();
- /* toggle 3 if any of the button is pressed */
- if (btn0 | btn1 | btn2)
- lamp[3].toggle();
- /* toggle 4 if more than one button is pressed */
- if (btn0 + btn1 + btn2 > 1)
- lamp[4].toggle();
- delay(100); /* FIXME */
- }
Add Comment
Please, Sign In to add comment