Connect with us

push button on-off and more...

Discussion in 'Microcontrollers, Programming and IoT' started by gatoulisss, Feb 2, 2015.

Scroll to continue with content
  1. gatoulisss

    gatoulisss

    36
    2
    Jan 23, 2015
    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!
     
  2. CDRIVE

    CDRIVE Hauling 10' pipe on a Trek Shift3

    4,960
    652
    May 8, 2012
    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
     
  3. Bluejets

    Bluejets

    5,254
    1,101
    Oct 5, 2014
    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"
     
  4. gatoulisss

    gatoulisss

    36
    2
    Jan 23, 2015
    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


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

    Bluejets

    5,254
    1,101
    Oct 5, 2014
    Don't think people here are prepared to write code for you.
     
  6. CDRIVE

    CDRIVE Hauling 10' pipe on a Trek Shift3

    4,960
    652
    May 8, 2012
    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
     
  7. jayanthd

    jayanthd

    43
    10
    Jul 4, 2015
    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.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-