Shop OBEX P1 Docs P2 Docs Learn Events
one button, multi LED control help...newb — Parallax Forums

one button, multi LED control help...newb

T.EllisT.Ellis Posts: 2
edited 2006-04-20 20:55 in Learn with BlocklyProp
I have a project i'm working on. I want one button to be able to toggle 3 lights. When button is pushed first time led 1 comes on, then on second push led 1 of then 2 on, then led 2 off led 3 on, then led 2 and 3 on, then back to 1.

I know how to toggle one led jusst need to understand how to go through al 3. If any one can provide some input or some sample codes it would greatly be appreciated.

Thanks
Trae

Comments

  • edited 2006-04-18 20:55
    Declare a variable and add 1 to it each time the button is been pressed.

    Use either IF...THEN of SELECT...CASE statements to decide which LED to turn on based on the variables value.

    When the value gets to 5, remember to set it to 0 again so that the sequence is repeated as you continue to press/release the button.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-04-19 02:05
    Another possibility would be to put the values in binary in a DATA table and read through them sequentially with each press of the button.· Each time you output the binary data to a port and increment the counter.

    Your DATA table could look like:

    DATA %001, %010, %100, %110
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-04-19 02:06
    You can use LOOKUP too -- see, PBASIC is very flexible.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • jeremyajeremya Posts: 26
    edited 2006-04-19 23:45
    Here is what I came up with:

    counter VAR Word
    counter = 0
    
    DO
    
    IF (IN3 = 1) THEN
      counter = counter + 1
      PAUSE 250
    ENDIF
    
    SELECT counter
      CASE = 1
        HIGH 15
      CASE = 2
        LOW 15
        HIGH 14
      CASE = 3
        LOW 14
        HIGH 13
      CASE = 4
        LOW 13
        counter = 0
    ENDSELECT
    
    LOOP
    
    



    -- Jeremy
  • T.EllisT.Ellis Posts: 2
    edited 2006-04-20 20:55
    Thanks alot for the help. I think I'll be able to manage with the IF THEN with the variable.
    Thanks for the example code Jeremy I had come up with something simular after I got the info from Andy.

    Thanks Again
    Trae
Sign In or Register to comment.