Not sure what im doing wrong here. No compile errors but when the arduino runs it never seems to recognize that I have a loop going on. It does the 2 second delay and skips the void sensitivity() function. Also i have tried not using a function and just having the while loop right where the void sensitivity call is made. Copied the while loop syntax right from the tutorial on this website. Any help would be greatly appreciated.
Thanks!
if(button1 > 540 && button2 == 0) // 2 analog signal buttons being pressed at the same time. (different switch types, one gives high signal other goes to zero)
{
delay(2000);
void sensitivity();
}
//then out of the void loop() section I have this code-
void sensitivity()
{
while(button1 < 540 && button2 > 0) //while both buttons are not being pressed
{
if(button1 > 540) //press button1 and +1 to sense
{
sense++;
Serial.print("sense = ");
Serial.println(sense);
delay(500);
}
if(button2 == 0) //press button2 and -1 to sense
{
sense--;
Serial.print("sense = ");
Serial.println(sense);
delay(500);
}
}
}
I have also tried it this way but it did not work either though the code compiled fine.
if(button1 > 540 && button2 == 0) // 2 analog signal buttons being pressed at the same time. (different switch types, one gives high signal other goes to zero)
{
delay(2000);
void sensitivity();
loopEnd = 0; //loopEnd is declared at the top equal to zero.
}
//then out of the void loop() section I have this code-
while(button1 < 540 && button2 > 0) //while both buttons are not being pressed
{
if(button1 > 540) //press button1 and +1 to sense
{
...
}
if(button2 == 0) //press button2 and -1 to sense
{
Ok you've got 2 buttons, if the button1 is pressed the value is > 540; if the second one is pressed the value is 0.
I suppose that theses 2 buttons are wired on 2 differents pins of the arduino (analog ones).
If you press one button you want a counter to be incremented, and decremented with the other button.
If one of the 2 buttons is pressed, you want a daly of 2 seconds before analyse the result.
so from, something like that can works.
Don't forget that in your sensitivity function, you must continue to read the state of each button...
if(button1 > 540 && button2 == 0) // 2 analog signal buttons being pressed at the same time. (different switch types, one gives high signal other goes to zero)
{
delay(2000);
sensitivity();
}
//then out of the void loop() section I have this code-
void sensitivity()
{
while(button1 > 540 && button2==0) // loop while 2 buttons still pressed together, but Read for an changing state !!!
{
button1 = analogRead(pinButton1);
button2 = analogRead(pinButton2);
}
// if we are here it means one or two buttons is/are released
if(button1 > 540) // button1 still pressed, ok increment sens
{
sense++;
Serial.print("sense = ");
Serial.println(sense);
delay(500);
}
if(button2 == 0) // button2 still pressed, ok decrement sens.
{
sense--;
Serial.print("sense = ");
Serial.println(sense);
delay(500);
}
}
}
Thank you everyone so far for your insights. I think that i am not continuing to read the sensitivity of both buttons. I will try that. Also Ill fix the button sensitivity values thing. I had been trying all sorts of things editing and deleting code and nothing seemed to work so it was late at night and i thought id ask for help so i probably just typed it in wrong cause i was tired and frustrated lol. Thank you again for the responses and ill let you know if i get it working!
yes thank you all got it fixed and working. When calling void sensitivity(); taking out the void made it work and then fixing those coding mistakes also mentioned helped. Thank you all for your help.