-1
// 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.
4
  • Please update your sketch to add a setup() and loop() function, then add your code to it with proper formatting.
    – VE7JRO
    Commented Mar 3, 2020 at 20:27
  • please do not be offended, but i downvoted your question because you posted a complete mess ... did you not look at what you posted? ... please format your code ... use the {} button to do the formatting ... also, please ask a question
    – jsotola
    Commented Mar 3, 2020 at 20:34
  • You need to provide a fully functional code, not only a snippet of your code. That will not work alone. Also you need to include the complete error message, including the line number, where the error happened.
    – chrisl
    Commented Mar 3, 2020 at 20:37
  • Are you using the Arduino IDE to compile? It will automatically add function prototypes to the top of your code. When you are using something else to compile, you need to declare every function above where you are using it
    – chrisl
    Commented Mar 3, 2020 at 21:28

1 Answer 1

2

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.

2
  • @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
  • 1
    The 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.
    – JRobert
    Commented Mar 4, 2020 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.