ButtonEvent Library

Hi,
I’m trying to use the ButtonEvent library found here: https://github.com/fasteddy516/ButtonEvents

I was unable to search for it in the Libraries and manually dragged and dropped it into my lib folder.

When I try to build my project in PlatformIO, I get the following error:
error: request for member ‘attach’ in ‘ledEyesButton’, which is of non-class type ‘ButtonEvent’

However, if I jump over to Arduino IDE, the project builds.

What am I doing wrong?

Please provide more information:

  • the platformio.ini file
  • the main source file (probably main.cpp)
  • the full build log

Did you get any other errors when compiling?

You copied ButtonEvents.h and ButtonEvents.cpp into your lib folder? You should have created a ButtonEvents folder in lib first, and dropped the two files there.

ButtonEvents.h has this line:

#include <Bounce2.h> // use Thomas Fredericks' button debounce library

So, you will need that library’s source and header files in lib/Bounce2 as well. It’s a dependency. That library is available at PlatformIO Registry so, add this to platformio.ini:

lib_deps=
    thomasfredericks/Bounce2
    https://github.com/fasteddy516/ButtonEvents.git

And remove the code files you dropped into lib, it should work.

I suspect your code failed to include the Bounce2 header and so, failed to compile the ButtonEvents class, hence the error message.

Cheers,
Norm.

The easiest way to deal with libraries is to simply declare them in platformio.ini. So a simple project could look like so. Note that the lib folder is empty.

platformio.ini

[env:uno]
platform = atmelavr
board = uno
framework = arduino
lib_deps = 
	https://github.com/fasteddy516/ButtonEvents.git
	thomasfredericks/Bounce2

main.cpp

#include <Arduino.h>
#include <ButtonEvents.h>

const byte buttonPin = 7;
ButtonEvents myButton;

void setup() {
  pinMode(buttonPin, INPUT_PULLUP);  
  myButton.attach(buttonPin);
  Serial.begin(9600);
  Serial.println("ButtonEvents 'basic' example started");
}

void loop() {
  myButton.update();
  
  if (myButton.tapped() == true) {
    Serial.println("TAP event detected");          
  }

  if (myButton.doubleTapped() == true) {
    Serial.println("DOUBLE-TAP event detected");
  }
  
  if (myButton.held() == true) {
        Serial.println("HOLD event detected");
  }  
}

PlatformIO has a Libraries page that can help you locate libraries. It finds Bounce2 and can even add it to your platformio.ini file.

ButtonEvents is not registered. But you can simply add the Git URL instead.

That was it.

Thanks!