// After 2 seconds have passed, stop ignoring the button.
// If the button is pressed, call the checkbutton function.
if (millis() > ignore && digitalRead(0) == LOW)
{
checkbutton();
}
}
// This function waits for the button to be released,
// then waits for it to be pressed to start the next run.
void checkbutton(){
delay (50); // Button pressed, debounce.
while (digitalRead(0) == LOW) // While button is pressed,
{} // do nothing while waiting.
delay (50); // Button pressed, debounce.
while (digitalRead(0) == HIGH)// While button is released,
{} // do nothing while waiting.
ignore = 2000 + millis(); // Set the now ignore time,
} // and return to the main loop.
1 Answer
You are using checkbutton()
before you have told the program what checkbutton()
is.
You need to move the whole method definition void checkbutton(){ ... }
more to the top, i.e. in front of any call to it (checkbutton();
).
Another option would be a forward declaration, but I doubt it's widely used in Arduino projects.
-
@jsotola: that's true. I don't think this is widely used in Arduino projects. Anyway, I added that to the answer Commented Mar 4, 2020 at 10:33
-
1The only reason it isn't widely used is because the IDE does it for you - invisibly. While that helps people just learning C and C++ to get something up and running quickly, they miss learning about forward declarations, which inevitably bites them when they move to another environment.– JRobertCommented Mar 4, 2020 at 14:12
setup()
andloop()
function, then add your code to it with proper formatting.{}
button to do the formatting ... also, please ask a question