OneButton - no compiling

Hi,
the use of the OneButton library seems to be quite useful in my project, so I started to take a nearer look to the library.But even the simple examples, provided with the library, don't compile, e.g.:

//from Mathias Hertel's Github-page (https://github.com/mathertel/OneButton/blob/master/examples/SimpleOneButton/SimpleOneButton.ino)
#include "OneButton.h"

// Setup a new OneButton on pin A1.  
OneButton button(A1, true);


// setup code here, to run once:
void setup() {
  // enable the standard led on pin 13.
  pinMode(13, OUTPUT);      // sets the digital pin as output
  
  // link the doubleclick function to be called on a doubleclick event.   
  button.attachDoubleClick(doubleclick);
} // setup
  

// main code here, to run repeatedly: 
void loop() {
  // keep watching the push button:
  button.tick();

  // You can implement other code in here or just wait a while 
  delay(10);
} // loop


// this function will be called when the button was pressed 2 times in a short timeframe.
void doubleclick() {
  static int m = LOW;
  // reverse the LED 
  m = !m;
  digitalWrite(13, m);
} // doubleclick

// End

I get the following errors:

sketch_nov08b.cpp.o: In function `_GLOBAL__sub_I_button':
/usr/share/arduino/sketch_nov08b.ino:4: undefined reference to `OneButton::attachDoubleClick(void (*)())'
/usr/share/arduino/sketch_nov08b.ino:4: undefined reference to `OneButton::tick()'
/usr/share/arduino/sketch_nov08b.ino:4: undefined reference to `OneButton::OneButton(int, int, bool)'
collect2: error: ld returned 1 exit status

What is wrong with the code? I flashed it to an Arduino Uno. As long as this simple example doesn't run I feel no need using OneButton in my project.

Thanks for helping

-richard

I am sure that it will be of no consolation to you but the code compiles OK for me.

Where did you get the OneButton library from ?

Github: GitHub - mathertel/OneButton: An Arduino library for using a single button for multiple purpose input.

It looks like the OneButton.h was found correctly but the OneButton.cpp was not found in the same place. They should both be in libraries/OneButton/src in your sketch folder.

Did you open the example with File->Examples->OneButton->SimpleOneButton

Yes, both files are at their place:


richard@nuc:~/sketchbook/libraries/OneButton/src$ ls -l
total 12
-rw-rw-r-- 1 richard richard 6285 Nov 8 14:01 OneButton.cpp
-rw-rw-r-- 1 richard richard 3793 Nov 8 14:01 OneButton.h

But nevertheless when opening, as you suggested, with File->Examples->OneButton->SimpleOneButton:

SimpleOneButton.ino:19:23: fatal error: OneButton.h: Datei oder Verzeichnis nicht gefunden [file/directory not found]
compilation terminated.

The Mattias Hertel OneButton library is available in the IDE Library Manager. Which version do you have ? I have 1.3.0 installed

UKHeliBob:
I have 1.3.0 installed

Fwiw, I have that version also, and OP's code compiled on an Uno with IDE 185.

In the library manager of IDE 2.1.0 unfortunately there is no "OneButton", so I have to download a zip file. Besides the library "OneButton-master.zip" there are also "OneButton-1.3.0.zip" down to 1.1.0.zip, the last named you'll find on OneButton - Arduino Libraries, but also linking to M. Hartel's GitHub page.

So I downloaded the 1.3.0 version to my /temp-directory. Calling "Import library" in the IDE gave the following error: "The Library names must contain only alphabetical characters and numbers". So I renamed the file to "OneButton130.zip". Same error. Within the zip file there is a directory named "OneButton-1.3.0", which then became renamed to "OneButton130". Now the import ->seemed<- to work. In my "Add library" menu there is now an item "OneButton130".

But the compiler still doesn't like it. Renaming the library to be imported from "OneButton130.zip" to "OneButton.zip" didn't help. I'm quite frustrated :frowning:

The files "OneButton.h" and "OneButton.cpp" are stored in ~/sketchbook/libraries/OneButton/src/
I'm thinking of using old fashioned code for reading the pushbuttons instead of using the OneButton library.

Greetings,

-richard

In the library manager of IDE 2.1.0

The latest IDE is 1.8.10. https://www.arduino.cc/en/main/software

What is 2.1.0?

Oh, my eyes...
In Help->over it reads (very, very small): 2:1.0.5+dfsg2-4, so at first glance I read 2.1.0. Sorry for that. I'll update.

Now everything is fine, I've updated to 1.8.10
Thanks to all,

-richard