I think I may have the whole thing solved
take a look
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 14; // the number of the pushbutton pin
// Arduino digital pins used to light up
// corresponding segments on the LED display
#define A 2
#define B 3
#define C 4
#define D 5
// Variables will change:
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
int count = 0; // current display count
int val = 0; // digital input from button
int lastVal = 0; //previous state of the button
// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 250; // the debounce time; increase if the output flickers
void setup() {
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
pinMode(C, OUTPUT);
pinMode(D, OUTPUT);
pinMode(buttonPin, INPUT);
zero();
}
void loop()
//Trigger Function
{
val = digitalRead(buttonPin); //read the pushbutton input pin
if (val != lastVal) { // compare the buttonState to its previous state
if (val == HIGH) { // if the state has changed, increment the counter
count++;
}
lastVal = val;
} // save the current state as the last state, for next time through the loop
switch (count) {
case 0:
zero();
break;
case 1:
one();
break;
case 2:
two();
break;
case 3:
three();
break;
case 4:
four();
break;
// read the state of the switch into a local variable:
int reading = digitalRead(buttonPin);
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited
// long enough since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
buttonState = reading;
}
// save the reading. Next time through the loop,
// it'll be the lastButtonState:
lastButtonState = reading;
}
}
// 0 => Empty
void zero() {
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
digitalWrite(D, LOW);
}
// 1 => Led 1
void one() {
digitalWrite(A, HIGH);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
digitalWrite(D, LOW);
}
// 2 => Led 2
void two() {
digitalWrite(A, LOW);
digitalWrite(B, HIGH);
digitalWrite(C, LOW);
digitalWrite(D, LOW);
}
// 3 => Led 3
void three() {
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, HIGH);
digitalWrite(D, LOW);
}
// 4 => Led 4 empty reload
void four() {
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
digitalWrite(D, HIGH);
}
From what I gathered this should work but I cannot tell
when I press the button the button goes hare and cycles all LED's rapidly
of another case the leds are slow to react but I believe this problem happens because of a few
things:
1)I'm using no resistors in the pushbutton and the noise from the pushbutton causes these effects
2)The button is bad itself
3)I did something wrong in the code...again
perhaps someone can test this code and see what results they get then I can compare to see what i'm doing wrong because I really want to finish this project soon