CAN SOMEONE WITH MORE EXPERIENCE THAN ME HELP WITH THE MISTAKE WITH THIS CODE.
THE PROBLEM IS THAT EITHER PINS 2 OR 3 WILL TOGGLE PINS 12 OR 13.
WHAT I WANT IS PNE 2 TOGGLE PIN 12 AND PIN 3 TOGGLE PIN 13
THANKS. GARY
/*
Button
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.
*/
// constants won't change. They're used here to set pin numbers:
const int buttonPin2 = 2; // the number of the pushbutton pin
const int ledPin13 = 13; // the number of the LED pin
const int buttonPin3 = 3; // the number of the pushbutton pin
const int ledPin12 = 12; // the number of the LED pin
// variables will change:
int buttonState2 = 0; // variable for reading the pushbutton status
int buttonState3 = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin13, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin2, INPUT);
// initialize the LED pin as an output:
pinMode(ledPin12, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin3, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState2 = digitalRead(buttonPin2);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState2 == HIGH) {
digitalWrite(13, !digitalRead(13)); // toggle state
delay(500); // wait around for 1 sec (1000 ms)
}
// read the state of the pushbutton value:
buttonState3 = digitalRead(buttonPin3);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState3 == HIGH) {
digitalWrite(12, !digitalRead(12)); // toggle state
delay(500); // wait around for 1 sec (1000 ms)
}else {
}
}