Shop OBEX P1 Docs P2 Docs Learn Events
PushButton control of two LEDs — Parallax Forums

PushButton control of two LEDs

LisaQLisaQ Posts: 33
edited 2010-03-01 21:30 in Learn with BlocklyProp
Attached is a sample program from What's a microcontroller.·I understand the PAUSES in the IF and ELSEIF- they toggle the LEDs.·I don't understand why there is a pause for 50mS after the ELSE. I commented out the PAUSE and reran it- I didn't see any difference. Could someone explain it for me?

Comments

  • cgraceycgracey Posts: 14,152
    edited 2010-02-23 17:29
    I'm not sure why those PAUSE instructions are in there.

    They might be there to slow down or regulate DEBUG message printing.

    In any case, they don't seem necessary.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Chip Gracey
    Parallax, Inc.
  • LisaQLisaQ Posts: 33
    edited 2010-02-23 17:35
    Thanks Chip,

    I thought I was just missing something·that may have been significant.

    Lisa
  • edited 2010-02-24 19:15
    Lisa and Chip,

    If you remove the PAUSE 50 in the ELSE block, the serial messages that report the pushbutton states·repeat more quickly when no buttons are pressed.· At the time the What's a Microcontroller book was written, that lack of pacing·caused software problems in certain computers.· We observed this at some of the computer labs we visited to teach BASIC Stamp Educators Courses.

    I added the PAUSE 50 in the·ELSE·code to prevent the problem.· I also reported·that and all my other "in the field" observations·to·the·software engineer·who·develops and maintains the BASIC Stamp Editor.··The combined documentation and software updates·have reduced·trouble-shooting at these courses to zero.· We also see very few tech support calls as a result, and it's great in general because we know that people can focus on what they are learning without being plagued by frozen software, blue screens, etc.

    We pay similar attention to these forum posts, and since you asked, we'll keep this discussion on file to make sure that nobody else will wonder about this after the next book revision.·

    Andy

    P.S.

    This code does the same job, and eliminates the need for·the your turn section at the end of the activity.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    DO
    · DEBUG HOME, ? IN4, ? IN3
    · IF (IN3 = 1) THEN HIGH 14
    · IF (IN4 = 1) THEN HIGH 15
    · PAUSE 50
    · LOW 14
    · LOW 15
    · PAUSE 50
    LOOP

    My rationale in keeping the code you see in the book was that most students (and teachers) would benefit from consistent use of the·IF...ENDIF code blocks, especially in the earlier chapters.· An example of a one line IF...THEN statement can be found in Chapter 7.·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 3/1/2010 9:19:10 PM GMT
  • LisaQLisaQ Posts: 33
    edited 2010-02-28 22:04
    Hi Andy,

    Thank you for the explanation. It makes me feel better to understand "why".

    Now I have another question, won't that code light the LEDs if I'm not pressing a switch? The cathodes are grounded.

    Lisa
  • edited 2010-03-01 21:30
    Hi Lisa,

    Regarding "...another question..."· Aach!· It looks like in the 2/24 post, I was crossing my i's and dotting my t's!· Alright, code example changed from:

    · ...
    · IF (IN3 = 0) THEN HIGH 14
    · IF (IN4 = 0) THEN HIGH 15
    · ...

    to
    · ...
    · IF (IN3 = 1) THEN HIGH 14
    · IF (IN4 = 1) THEN HIGH 15
    · ...
    It should work correctly now.

    Andy

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 3/1/2010 9:50:41 PM GMT
Sign In or Register to comment.