'button_on_release' was not declared in this scope

I have a little problem with the GFButton library, with the advanced configuration of the button it keeps telling me that 'button_on_release' is not declared and I don't know what it could be, here I leave the complete code

#include <Arduino.h>
#include "GFButton.h"

//Estas variables son para detectar el estado del boton
GFButton secP = GFButton(2);
GFButton secM = GFButton(3);


int sec = 1;

int oPins[]= {4, 5, 6, 7, 8, 9, 10, 11};
  
void setup()
{
  secP.setReleaseHandler(button_on_release);
  secM.setReleaseHandler(button_on_release);

  Serial.begin(9600);
  //esta funcion inicializa de forma corta todos los pines del array como output
  for(int i=0; i<8; i++){
    pinMode(oPins[i], OUTPUT);
  }
}

void loop()
{
  //este if detecta cual boton se apreta y añade o sustrae segun el caso
  /*if(secP.wasPressed()){
  	if(sec==4){
      sec=1;
    }else{
      sec++;
    }
  }else if(secM.wasPressed()){
    if(sec==1){
      sec=4;
    }else{
      sec--;
    }
  }*/
  
  secP.process();
  secM.process();
  
    if(sec==1){
      int i = 0, j=0;
  
    for ( i = 0; i < 256; i++)
      {
        for ( j = 0; j < 8; j++)
        {  
          if ( ( (i >> j) & 1 )  == 1 )
              digitalWrite(oPins[j], HIGH);
          else digitalWrite(oPins[j], LOW);
        }
        delay(250);
        
      }
    }  
  
  
}

void button_on_release(GFButton & secP)
  {


  }

If they see things that they do not understand such as the if(secP.wasPressed()), it is part of a test nothing more, the important thing is that it throws me that error

Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

I installed the GFButton library through the library manager and attempted to verify your code. The code compiled with no errors, but a few warnings. My system is Win 10, IDE 1.8.12.

I suggest that you try to delete and re-install the library.

I am going to do that, by the way I am not using the IDE I am using Visual Studio Code

here is the error that it gives to me

src\main.cpp: In function 'void setup()':
src\main.cpp:15:26: error: 'button_on_releaseP' was not declared in this scope
   secP.setReleaseHandler(button_on_releaseP);
                          ^~~~~~~~~~~~~~~~~~
src\main.cpp:15:26: note: suggested alternative: 'buttonmodes'
   secP.setReleaseHandler(button_on_releaseP);
                          ^~~~~~~~~~~~~~~~~~
                          buttonmodes
src\main.cpp:16:26: error: 'button_on_releaseM' was not declared in this scope
   secM.setReleaseHandler(button_on_releaseM);
                          ^~~~~~~~~~~~~~~~~~
src\main.cpp:16:26: note: suggested alternative: 'buttonmodes'
   secM.setReleaseHandler(button_on_releaseM);
                          ^~~~~~~~~~~~~~~~~~
                          buttonmodes
*** [.pio\build\nanoatmega328\src\main.cpp.o] Error 1

That is information that should always be included in your original post. Maybe have a look at the how to get the best from the forum post again.

I don't know for sure, but I wonder if this is one of those cases where you need the function prototype to be declared before you can reference the function.

The Arduino IDE automatically defines function prototypes. Perhaps your environment requires them.

I'll see, thanks for the help, I feel better knowing that my code has nothing wrong

any idea how to do that? I am quite new to programming

I know nothing of Visual Studio so could be totally wrong. This is my best guess, though.

Maybe this discussion of function prototypes and definitions will help.

I am no expert but I think a prototype for the button_on_release handler function would look like:

void button_on_release(GFButton);  

You would put that line above the place where you first reference the function.

int oPins[]= {4, 5, 6, 7, 8, 9, 10, 11};

void button_on_release(GFButton);    

void setup()
{
  secP.setReleaseHandler(button_on_release);

It worked, thank you very much, you are the best

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.