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.
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
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.
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
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.