the problem i am having is in this current state i press the button and it goes into the while loop, but it completely ignores the nested "if" statement and increments the i variable regardless of the state of the push button and will stay in the while loop "x" number of times i have the while(i<=x) set for.
const int led = 10; //led pin 10
int pb = 7; //push button pin 7
int i;
void setup()
{
pinMode(led,OUTPUT);
pinMode(pb,INPUT);
}
void loop()
{
pb=digitalRead(7); //pb = pushbutton state high or low
i=1; // counting variable
if(pb==HIGH) //if pb is pressed
{
while(i<=4)
{
delay(500);
digitalWrite(led,HIGH);
delay(500);
digitalWrite(led,LOW);
if(pb==HIGH)
{
i++;
}
}
}
}
int pb = 7; //push button pin 7
pb=digitalRead(7); //pb = pushbutton state high or low
So, is pb a pin number or a state? Get your story straight.
How IS your switch wired? Using the internal pullup resistor makes wiring the switch so much easier. One leg to the digital pint; the other leg to ground.
pb=digitalRead(7); //pb = pushbutton state high or low
So, is pb a pin number or a state? Get your story straight.
How IS your switch wired? Using the internal pullup resistor makes wiring the switch so much easier. One leg to the digital pint; the other leg to ground.
My switch is being run into a debounce IC
pb is the variable that i want my digitalRead(7) stored in, so i guess i dont need that int pb 7?
To the other guy, it doesnt really matter if it is responding to the push, or the push and release, i was just clarifying that it is being released.
and it goes into the while loop, but it completely ignores the nested "if" statement and increments the i variable regardless of the state of the push button and will stay in the while loop "x" number of times i have the while(i<=x) set for.
You never read the state of the switch after the while loop starts. Since pb had to be HIGH for the while loop to start, it is HIGH in the while loop, too.