Maker Pro
Maker Pro

push button on-off and more...

gatoulisss

Jan 23, 2015
36
Joined
Jan 23, 2015
Messages
36
hello guys!
i want to use a button as on-off switch but not only.
when i press the button for 3 sec then it becomes on and it starts checking a sensor but if i dont release it then i want to make it select between 3 modes for example push button on for 5sec then mode a,push button on for 7sec then mode b,push button on for 9sec then mode c.if i release it and press it again for 3 sec then it coming to off state. any ideas with the code? thank you very much!
 

CDRIVE

Hauling 10' pipe on a Trek Shift3
May 8, 2012
4,960
Joined
May 8, 2012
Messages
4,960
Wouldn't it be more practical to use a logic scheme more like this...

ButtonPress: Sensor On
ButtonPress again(<1sec): Mode A
ButtonPress again(<1sec): Mode B
ButtonPress again(<1sec): Mode C
ButtonPress again(>1sec): Sensor Off

1sec is much longer than you think. Each period (......) represents a single key press. There's 6 of them there. I did it within 1sec.

Chris
 

Bluejets

Oct 5, 2014
6,901
Joined
Oct 5, 2014
Messages
6,901
You will need some indicators in there as well otherwise you will never know which mode you are in....
(assuming press and hold like you say initially)....... "but if i dont release it then i want to make it select between 3 modes"
 

gatoulisss

Jan 23, 2015
36
Joined
Jan 23, 2015
Messages
36
Wouldn't it be more practical to use a logic scheme more like this...

ButtonPress: Sensor On
ButtonPress again(<1sec): Mode A
ButtonPress again(<1sec): Mode B
ButtonPress again(<1sec): Mode C
ButtonPress again(>1sec): Sensor Off

1sec is much longer than you think. Each period (......) represents a single key press. There's 6 of them there. I did it within 1sec.

Chris
so how i can do this in code for the microcontroller? my problem is that once the sensor loop starts then i cant get out for the off state... or when on i cant enter to the modes... im using pic16f88 and mikro c


You will need some indicators in there as well otherwise you will never know which mode you are in....
(assuming press and hold like you say initially)....... "but if i dont release it then i want to make it select between 3 modes"

its mode its change the sensor settings so i will know which mode i have select also i will use a bip sound to inform me what i have choose
 

Bluejets

Oct 5, 2014
6,901
Joined
Oct 5, 2014
Messages
6,901
Don't think people here are prepared to write code for you.
 

CDRIVE

Hauling 10' pipe on a Trek Shift3
May 8, 2012
4,960
Joined
May 8, 2012
Messages
4,960
Why not? If I could I would gladly post code snippets but C is not my forte.

gatoulisss, regardless of the progamming language certain procedures are common to all of them. It's just the syntax that's different. MikroC will undoubtedly provide you with a large library of functions. These are pre-written code blocks provided by Mikrobasic. These functions and procedures do things such as debouncing a switch via code vs. a hardware solution. The odds are the function will be named ButtonPress, SwPress or something similar. Mikrobasic also provides sample code for all their functions.

I would highly recommend reading through your library to familiarize yourself with it.

Chris
 

jayanthd

Jul 4, 2015
43
Joined
Jul 4, 2015
Messages
43
I can help you with a code for PIC or AVR microcontroller. The solution is using a Timer interrupt. If you still need a C Code then I can write a code for you.
 
Top