This is what I have so far. Thanks
/*
The circuit:
Buttons:
* 5V -> 220 ohm resistor -> A Button + -> A Button - -> pin 2 & GND
* 5V -> 220 ohm resistor -> B Button + -> B Button - -> pin 4 & GND
* 5V -> 220 ohm resistor -> c Button + -> c Button - -> pin 6 & GND
LEDs:
* 5V -> 220 ohm resistor -> A LED + -> A LED - -> pin 3 ??No Ground??
* 5V -> 220 ohm resistor -> B LED + -> B LED - -> pin 5
* 5V -> 220 ohm resistor -> c LED + -> c LED - -> pin 7
*/
// this constant won't change:
const int AButton = 2; // the pin that the pushbutton is attached to
const int ALed = 3; // the pin that the LED is attached to
const int BButton = 4;
const int BLed = 5;
const int cButton = 6;
const int cLed = 13;
// Variables will change:
int AButtonPushCounter = 0; // counter for the number of button presses
int AButtonState = 0; // current state of the button
int ALastButtonState = 0; // previous state of the button
int BButtonPushCounter = 0; // counter for the number of button presses
int BButtonState = 0; // current state of the button
int BLastButtonState = 0; // previous state of the button
int cButtonPushCounter = 0; // counter for the number of button presses
int cButtonState = 0; // current state of the button
int cLastButtonState = 0; // previous state of the button
void setup() {
// initialize the button pin as a input:
pinMode(AButton, INPUT);
pinMode(BButton, INPUT);
pinMode(cButton, INPUT);
// initialize the LED as an output:
pinMode(ALed, OUTPUT);
pinMode(BLed, OUTPUT);
pinMode(cLed, OUTPUT);
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
// read the pushbutton input pin:
AButtonState = digitalRead(AButton);
delay(50);
BButtonState = digitalRead(BButton);
delay(50);
cButtonState = digitalRead(cButton);
delay(50);
// compare the AButtonState to its previous state
if (AButtonState != ALastButtonState) {
// if the state has changed, increment the counter
if (AButtonState == HIGH) {
// if the current state is HIGH then the button
// went from off to on:
AButtonPushCounter++;
Serial.println("A On");
Serial.println("A Button Pushed In");
Serial.print("number of button cycles: ");
Serial.println(AButtonPushCounter);
}
else {
// if the current state is LOW then the button
// went from on to off:
Serial.println("A Button Released");
}
}
// save the current state as the last state,
//for next time through the loop
ALastButtonState = AButtonState;
// turns on the LED every other button pushs by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
if (AButtonPushCounter % 2 == 0) {
digitalWrite(ALed, HIGH);
}
else {
digitalWrite(ALed, LOW);
}
if (BButtonState != BLastButtonState) {
// if the state has changed, increment the counter
if (BButtonState == HIGH) {
// if the current state is HIGH then the button
// went from off to on:
BButtonPushCounter++;
Serial.println("B Button Pushed In");
Serial.print("number of button cycles: ");
Serial.println(BButtonPushCounter);
}
else {
// if the current state is LOW then the button
// wend from on to off:
Serial.println("B Button Released");
}
}
// save the current state as the last state,
//for next time through the loop
BLastButtonState = BButtonState;
// turns on the LED every other button pushs by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
if (BButtonPushCounter % 2 == 0) {
digitalWrite(BLed, HIGH);
}
else {
digitalWrite(BLed, LOW);
}
if (cButtonState !=cLastButtonState) {
// if the state has changed, increment the counter
if (cButtonState == HIGH) {
// if the current state is HIGH then the button
// went from off to on:
cButtonPushCounter++;
Serial.println("c Button Pushed In");
Serial.print("number of button cycles: ");
Serial.println(cButtonPushCounter);
}
else {
// if the current state is LOW then the button
// went from on to off:
Serial.println("c Button Released");
}
}
// save the current state as the last state,
//for next time through the loop
cLastButtonState = cButtonState;
// turns on the LED every other button pushs by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
if (cButtonPushCounter % 2 == 0) {
digitalWrite(cLed, HIGH);
}
else {
digitalWrite(cLed, LOW);
}
}