Shop OBEX P1 Docs P2 Docs Learn Events
DIRS — Parallax Forums

DIRS

tedroberson9tedroberson9 Posts: 5
edited 2013-11-22 05:44 in General Discussion
I want to control outputs P13,14,and 15 to manually switch 3 LEDs on and off sequentially, using momentary switches at in2,3 and 4. as control source. LED 1 is on by default. Pushing any switch after activation should turn on corresponding LED, turn off all others. I've tried using the DO LOOP,IF...then... else but not quite what I need, each time the loop cycles the led blanks; I need solid on and off. How do I setup the DIRS and IN to achieve this?????HELP!!!!!!!blank.gif

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-11-20 09:15
    Start with "What's a Microcontroller?" and also have the "Basic Stamp Syntax and Reference Manual" on hand. These are readily available for free download and you can buy a paper copy if you need that form. Look at the webstore page for books. Each book's webstore page has a link to the PDF version of the book.

    "What's a Microcontroller?" has code examples for working with various switches and other code examples deal with turning something like an LED on and off. Nuts and Volts Column #6 shows how to use a transistor to turn a relay or motor on and off. Column #6 is in Volume #1.
  • lanternfishlanternfish Posts: 366
    edited 2013-11-20 23:21
    One really important thing to do is to post your code with your question. By doing this it is easier for others to see where your coding may be in error or can be fine tuned,
  • ercoerco Posts: 20,256
    edited 2013-11-21 17:36
    Maybe easier without DIRS. Untested, but try this, assuming your pushbuttons are normally low and go high when pressed:
    do
    if in2=1 then high 13: low 14:low 15:endif 
    if in3=1 then low 13: high 14:low 15:endif
    if ????  ' you get to write this line!
    loop
    
  • tedroberson9tedroberson9 Posts: 5
    edited 2013-11-21 22:40
    Thank you so much Erco for steering me in the right direction. With a few corrections I came up with a perfect program that working exactly how I wanted it. I had to add parentheses around statements in3 to in4.. Set default that LED #1 comes on at power up.In4 resets everything to beginning. I can randomly switch between any output. THANKS AGAIN!!! HERE IS MY VERSION
    HIGH 15 (red LED ON)
    DO
    IF IN3=(1) THEN LOW 15: HIGH 14:LOW 13:ENDIF ( Green LED ON) ( Red and yellow LED OFF)

    IF IN4=(1) THEN HIGH 13: LOW 14:LOW 15:ENDIF ( Yellow LED ON) ( Red and green OFF)
    IF IN5=(1) THEN HIGH 15: LOW 14:LOW 13:ENDIF (Reset)
    LOOP

    Thanks again.
  • tedroberson9tedroberson9 Posts: 5
    edited 2013-11-22 05:10
    Thanks Mike Green for yr valuable info,it gave me a good place to start.
  • ercoerco Posts: 20,256
    edited 2013-11-22 05:44
    Ted: Congrats, welcome to our geeky family of programmers. It"s pretty sweet when things click and you type in some code and good things happen. Carry on!
Sign In or Register to comment.