#include <mechButton.h> // Add a button manager library..
// DEFINE ALL PINS
const int BUTTON_GREEN_PIN = 5;
const int BUTTON_RED_PIN = 6;
const int LED_GREEN_PIN = 7;
const int LED_RED_PIN = 8;
// DEFINE HIGH/LOW STATE VARIABLES
bool LED_GREEN_STATE = false;
bool LED_RED_STATE = false;
mechButton greenBtn(BUTTON_GREEN_PIN);
mechButton redBtn(BUTTON_RED_PIN);
void setup() {
pinMode(LED_GREEN_PIN, OUTPUT);
pinMode(LED_RED_PIN, OUTPUT);
greenBtn.setCallback(greenClk);
redBtn.setCallback(redClk);
}
// When green changes state, this is called.
void greenClk(void) {
if (!greenBtn.getState()) { // Check if the green button was pressed.
LED_GREEN_STATE = !LED_GREEN_STATE; // Flip the green state.
digitalWrite(LED_GREEN_PIN,LED_GREEN_STATE); // Set the green LED.
} // And we are done.
}
void redClk(void) {
if (!redBtn.getState()) { // Check if the red button was pressed.
LED_RED_STATE = !LED_RED_STATE; // Flip the red state.
digitalWrite(LED_RED_PIN,LED_RED_STATE); // Set the red LED.
} // And we are done.
}
void loop() {
idle(); // Runs the background tasks, like the buttons, for you.
// Do whatever else you like here..
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
led1:A
led1:C
led2:A
led2:C
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r
btn2:1.l
btn2:2.l
btn2:1.r
btn2:2.r