/*
Button
Turns on and off a light emitting diode(LED) connected to digital pin 13,
when pressing a pushbutton attached to pin 2.
The circuit:
- LED attached from pin 13 to ground through 220 ohm resistor
- pushbutton attached to pin 2 from +5V
- 10K resistor attached to pin 2 from ground
- Note: on most Arduinos there is already an LED on the board
attached to pin 13.
created 2005
by DojoDave <http://www.0j0.org>
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/Button
*/
// constants won't change. They're used here to set pin numbers:
const int front_limit = 10; // the number of the pushbutton pin
const int back_limit = 11;
const int dir_change = 12;
const int ledF = 2; // the number of the LED pin
const int ledB = 3; // the number of the LED pin
const int ledD = 4; // the number of the LED pin
byte last_front_limit_State = LOW;
byte last_back_limit_State = LOW;
byte last_dir_change_State = LOW;
byte ledB_State = LOW;
byte ledF_State = LOW;
byte ledD_State = LOW;
void setup() {
// initialize the LED pin as an output:
pinMode(ledF, OUTPUT);
pinMode(ledB, OUTPUT);
pinMode(ledD, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(front_limit, INPUT);
pinMode(back_limit, INPUT);
pinMode(dir_change, INPUT);
}
void loop() {
byte front_limit_State = digitalRead(front_limit);
byte back_limit_State = digitalRead(back_limit);
byte dir_change_State = digitalRead(dir_change);
if (front_limit_State != last_front_limit_State) {
last_front_limit_State = front_limit_State;
if (front_limit_State == HIGH) {
ledF_State = (ledF_State == HIGH) ? LOW: HIGH;
digitalWrite(ledF, ledF_State);
}
}
if (back_limit_State != last_back_limit_State) {
last_back_limit_State = back_limit_State;
if (back_limit_State == HIGH) {
ledB_State = (ledB_State == HIGH) ? LOW: HIGH;
digitalWrite(ledB, ledB_State);
}
}
if (dir_change_State != last_dir_change_State) {
last_dir_change_State = dir_change_State;
if (dir_change_State == HIGH) {
ledD_State = (ledD_State == HIGH) ? LOW: HIGH;
digitalWrite(ledD, ledD_State);
}
}
}