Push Button Hold (1s) Little Help

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 25 times
Been thanked: 188 times
Contact:

Push Button Hold (1s) Little Help

Post by Jordy101091 »

Hi, All

Can somebody help me to figure out on how to make something like this.
To Go out of a menu screen I would like to make the user hold a button for several seconds before turning back the menu will exit.
If the user presses this button quick the program will return to the top of the menu, this menu will not exit.

I hope somebody can figure this out.
I have tryed it but no succes.

Regards Jordy Kleian
the will to learn, should not be stopped by any price

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: Push Button Hold (1s) Little Help

Post by Spanish_dude »

Hi,

You just need to check your input, if it's high for let's say 200ms then it's a short pulse and if it's still on after 700ms it's a long pulse.

Code: Select all

char counter, pulse;

counter = 0;
while ((portb & 0x01) == 1) // check portb pin 0
{
    delay_ms(20); // delay 20ms
    counter++;  // increase counter
}

if (counter <= 10) // 200ms = 20ms * 10
{
    pulse = 0; // short pulse
}
else if (counter >= 35) // 700ms = 20ms * 35
{
    pulse = 1; // long pulse
}
Hope this helps.

Nicolas

EDIT : You just need to change the two if-statements to increase or decrease the time the user needs to push the button. I did it for 200ms and 700ms but you can change that pretty easily.

Post Reply