Bounce.h issue

Hi all,

I have been trying to use the bounce library and have hit a small issue. I want to use the "duration" to find out how long the button has been pressed for, but it doesn't seem to work. Whereas all the other commands turn orange the duration stays black. Even the example from the zip file doesn't work, is it me?!

Whereas all the other commands turn orange the duration stays black

What does this mean, please?

Can you post your code?

Sorry re-reading that doesn't make sense now :stuck_out_tongue:

char button_read() {
static int up_old = 1;

up.update();
down.update();
select.update();

if (up.read() == 1 && up_old == 0) {
Serial.println(up.duration());
if (up.duration() > 1000) Serial.println("Long Press");
else Serial.println("Short Press");
}

up_old = up.read();
}

for all the other calls (up.update(), up.read()) the "update" or "read" turns orange as the IDE recognises them as a command. the up.duration() doesn't seem the be recognised and doesn't work. I have limited knowledge of how the library system works and checked the "duration" is declared and it is. I pulled the lib from here: Arduino Playground - HomePage

smartroad:
...
for all the other calls (up.update(), up.read()) the "update" or "read" turns orange...

The syntax coloration is just a visual aid has nothing to do with whether the function "works." The author of that Bounce library apparently forgot to put a line in the library's keywords.txt file that would clue the IDE to turn the identifier duration orange. See Footnote.

Now if you would tell us exactly what happens and what you expected to happen with your sketch (and what you don't understand about the difference), maybe someone can help show you how to learn to get to the bottom of things.

Regards,

Dave

Footnote:
Open keywords.txt in the Bounce library directory and insert the following line right after the "rebounce..." line:

duration	 KEYWORD2

Restart the Arduino IDE and look for orange durations.

Cheers for the help, found the keyword.txt file and updated (hadn't updated here at that time).

The problem is that the "duration" command doesn't return the time that the button has been pressed for like it is meant too. I have come up with my own solution but it would be nice to simplify my code a little more if I could use it.

So in that code the button (up) should be pressed and if it is held for more then a second it reports a long press and less then a second, a short one. Currently it only reports a short press as when you call "up.duration()" it only ever reports '0'.

I use the bounce library, the duration call does work as documented.