Shop OBEX P1 Docs P2 Docs Learn Events
One button multiple functions — Parallax Forums

One button multiple functions

pcleatspcleats Posts: 11
edited 2008-06-27 13:49 in Propeller 1
Hello all,

I have a project that I would like to convert to the propeller chip. My challenge is that I need to be able to control all the functions with a single switch.

The project is battery powered, and voltage is applied to the circuit when a multiple conductor cable is connected.

1st press turns the power on to the circuit
2nd press turns on a wireless receiver
3rd press ???
4th Press ???
Last press turns off the system if held for more than 3 seconds

I would like to be able to add addition functions to the button such as the ability to activate additional feature/cogs if needed.

Also I need a better way to monitor the current being drawn from the system. I am currently using a circuit that is attached.

If someone would like to see the code I am currently running I would be happy to provide it.

I am very new to the propeller, and just beginning to learn how to use it.

Thanks

Patrick
1100 x 840 - 82K

Comments

  • LeonLeon Posts: 7,620
    edited 2008-06-25 17:56
    You could use a long key press to select different modes. Within modes, use short key presses. Some sort of feedback to the user would be advisable.

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle
  • Ken PetersonKen Peterson Posts: 806
    edited 2008-06-25 18:42
    Morse code! Just kidding....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • BasilBasil Posts: 380
    edited 2008-06-25 21:34
    Hi [noparse]:)[/noparse]

    How about something like this...

    loop:
    timer == 0
    start timer on rising edge of button
    end timer on falling edge of button
    
    if timer > 100ms & timer < 2000ms
       button_state++
       if button_state > 4, then button_state == 0
    
       if buttonstate == 1
         do function 1
       elseif buttonstate ==2
         do function 2
       elseif buttonstate ==3
         do function 3
       elseif buttonstate ==4
         do function 4
    
    if timer > 2000ms
       turn_off
    
    
    repeat loop
    
    



    It is proably the most inefficient way to do this but hey, im at work and my mind is numb :P

    Alec

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Alec

    My our page
  • pcleatspcleats Posts: 11
    edited 2008-06-25 22:23
    Alec,

    I will try this and let you know. Thanks for the info

    Patrick
  • Ken PetersonKen Peterson Posts: 806
    edited 2008-06-27 13:49
    If you are going to maintain a number of states like that, it's a good idea to provide state feedback to the user as Leon suggested, unless the function itself makes it obvious.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sign In or Register to comment.