Shop OBEX P1 Docs P2 Docs Learn Events
Switch/Leds Problem — Parallax Forums

Switch/Leds Problem

bluejaybluejay Posts: 131
edited 2012-12-19 21:02 in BASIC Stamp
When sw0 is closed, led0 turns on, and when sw0 is open led0 turns off.

However when sw0 stays on I cannot turn on the rest of led,s (led1, led2, and led3) when their appropriate switches are on.

Can someone please tell me what am I doing wrong? Thanks.
1024 x 1408 - 93K
432 x 1120 - 55K

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-12-18 21:21
    The wiring is ok. You have two types of problems in your program.

    1) You have IF ... THEN <label> when you should have IF ... THEN GOSUB <label>

    2) You set the I/O pins HIGH, but you never set them LOW (turn them off). What do you want to do about that?

    Note that you have RETURNs, but you never do a GOSUB. That's a serious programming error. A GOSUB calls a subroutine and a RETURN returns from that GOSUB.
  • bluejaybluejay Posts: 131
    edited 2012-12-18 21:43
    Thanks Mike. Attached is the revised code which works. The more I use the Stamp the more I appreciate it!. What a great product!.
    1024 x 1408 - 58K
  • Mike GreenMike Green Posts: 23,101
    edited 2012-12-19 06:48
    The DEBUG statement will never execute. Is that what you want?

    Be careful about indenting. The indented statements after each IF THEN statement look like they're controlled by the IF THEN statement because they're indented. They're actually at the same "level" as the IF THEN and will always be executed. In Spin (for the Propeller), the indenting works and statements indented after an IF are controlled by the IF's condition, but not in Basic.
  • bluejaybluejay Posts: 131
    edited 2012-12-19 08:31
    The DEBUG statements are supposed to show the status content of each inputs.

    I don't understand your comments on the indentation. I idented so that the IF...THEN... statements stands out clearly.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-12-19 11:01
    I'm talking about the " Program Running!" DEBUG statement.

    It's ok to use indenting to make the IF THEN statement stand out. Some programming languages (like Spin and Python) use indenting to show statement dependency. Most others do not. In Stamp Basic, there's another form of the IF THEN statement where the THEN is paired with a subsequent ENDIF and everything in-between is controlled by the IF condition. Often indenting is used between the IF and ENDIF statements to clarify which statements are controlled by the IF.
  • bluejaybluejay Posts: 131
    edited 2012-12-19 21:02
    I understand. Thanks Mike.
Sign In or Register to comment.