Shop OBEX P1 Docs P2 Docs Learn Events
Begineer Problem — Parallax Forums

Begineer Problem

aklaakla Posts: 2
edited 2005-02-15 16:10 in BASIC Stamp
Hi ! iam begineer in microcontroller. iam using BS2sx for controlling my final year project.
i want my output5 high when input1 on and off for·5 times. please someone check my program. its not working.counter is not·accurate.


INPUT 1
OUTPUT 5
cnt VAR Byte
cnt = 0
MAIN :
····· IF IN1=1 THEN ADD
····· GOTO MAIN
ADD:
····· PAUSE 1000
····· cnt = cnt +·5
····· IF cnt <·5 THEN MAIN
····· HIGH 5
····· DEBUG " OK "
····· GOTO MAIN

regards
aklaken.

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-02-15 06:09
    aklaken -

    I'm a bit surprised it's not more intuitive that if you want to increment a counter by one, you add one to it, not 2, 5 or anything else:

    cnt = cnt + 1 'Increment the counter by one

    Regards,

    Bruce Bates
  • aklaakla Posts: 2
    edited 2005-02-15 06:39
    thanks bruce, i not reliase it, now its working
    thanks again
    regards
    aklaken·
  • achilles03achilles03 Posts: 247
    edited 2005-02-15 15:04
    Also, is the input on pin 1 transitioning from high to low no faster than once a second? If not, that "pause 1000" statement might need fine tuning.

    Dave
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-02-15 16:10
    Give this a try.· It's a little more verbose than your code -- you'll find as programs grow this style is easier to read and maintain.·

    You say in your program than you want to "press and release" the button; the code below shows how (one method, there are many) to do that.

    ' {$STAMP BS2sx}
    ' {$PBASIC 2.5}
     
     
    Btn         PIN    1
    Alarm       PIN    5
     
     
    btnCount    VAR    Nib
     
     
    Reset:
      btnCount = 0
      LOW Alarm                      ' make output and off
     
     
    Main:
      DO WHILE (btnCount < 5)        ' monitor until count = 5
        DO : LOOP WHILE (Btn = 0)    ' wait for press
        PAUSE 100                    ' debounce delay
        DO : LOOP UNTIL (Btn = 0)    ' force release
        btnCount = btnCount + 1      ' update count
      LOOP 
     
      HIGH Alarm                     ' turn on
      DEBUG "Alarm", CR
      PAUSE 2000                     ' delay for alarm output
      GOTO Reset                     ' start over 
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
Sign In or Register to comment.