Hi I'm new to the world of Arduino I've gone through tutorials but I'm stuck on how I should declare more than one button switch input and output pin. I would like to ask how I can implement the above and how it should be structured in the sketch. I'm a complete novice but hope to learn a lot more as I go.
So for my project I'm trying to replicate a car indicator system, so one button for left indication and one for right.
I have the buttons and leds setup, Button 1 is on pin 2 and button 2 is on pin 3, Led output on pin 11 and 12.
Thank you.
int inPin = 2; // the number of the input pin
int outPin = 11; // the number of the output pin
int state = HIGH; // the current state of the output pin
int reading; // the current reading from the input pin
int previous = LOW; // the previous reading from the input pin
// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers
void setup()
{
pinMode(inPin, INPUT);
pinMode(outPin, OUTPUT);
}
void loop()
{
reading = digitalRead(inPin);
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
if (state == HIGH)
state = LOW;
else
state = HIGH;
time = millis();
}
digitalWrite(outPin, state);
previous = reading;
}