Shop OBEX P1 Docs P2 Docs Learn Events
bs2 program help — Parallax Forums

bs2 program help

MYMMYM Posts: 9
edited 2005-11-29 12:55 in BASIC Stamp
I would like to know is there anyone could help me with the following program

This program is supposed to simulate a model elevator. Where when an input from pin3 is detected it counts the floors while output on pin9 and pin10 is supposed to turn on and off the motor as the shaft on the motor passes through a interupter that detected from pin3.




' {$STAMP BS2}
' {$PBASIC 2.5}

cf VAR Byte
df VAR Byte

cf = 0
df = 0

Start:
DEBUG CLS
DEBUG DEC cf
DEBUG "Current Floor = ",cf ,CR
DEBUG "Enter Destination",CR
DEBUGIN NUM df

  IF df > cf AND df <=9 THEN GOTO Up
  IF df < cf AND df >=0 THEN GOTO Down
  IF df = cf THEN GOTO Start

Up:
DEBUG "Elevator ascending", CR
DO
  cf = cf+1
  PAUSE(1000)
  HIGH 10
  LOW 9
  DEBUG "Current Floor is ", DEC cf ,CR
  LOOP UNTIL df = cf
  PAUSE (500)
  GOTO Start

Down:
DEBUG "Elevator Descending" ,CR
DO
  cf = cf-1
  PAUSE(1000)

  IF NOT IN3 = 1 THEN EXIT

  HIGH 9
  LOW 10
  DEBUG "Current Floor is ", DEC cf ,CR
  LOOP UNTIL df = cf
  PAUSE (500)

GOTO Start
END

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-20 20:35
    It would be helpful if you posted your schematic -- their may be a disconnect between it and your code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • MYMMYM Posts: 9
    edited 2005-11-25 20:00
    here is the schematic in jpg format

    sorry for the delay.
    1169 x 850 - 86K
  • TiboTibo Posts: 81
    edited 2005-11-26 19:50
    well, this program works, may be you failed on wiring....is the interruptor a 'course end' detector ?
    You should also limit the number os levels the elevator can reach...

    Post Edited (Tibot) : 11/26/2005 8:00:07 PM GMT
  • Benjamin_bakerBenjamin_baker Posts: 18
    edited 2005-11-27 18:22
    DO
    cf = cf+1
    PAUSE(1000)
    HIGH 10
    LOW 9
    DEBUG "Current Floor is ", DEC cf ,CR
    LOOP UNTIL df = cf
    PAUSE (500)
    GOTO Start

    It looks like that part would just turn the motor on, cycle through the code, and head on back to start without actually looking at the elevator itself, leaving the elevator on.
  • MYMMYM Posts: 9
    edited 2005-11-28 13:24
    Thats true. when i connect the circuit to the basic stamp the motor just turns on. Could you please tell me away for the motor to look for an input.

    I think it is the

    IF NOT IN3=1 THEN EXIT
  • TiboTibo Posts: 81
    edited 2005-11-28 18:42
    Yes it is :
    if not LOW on PIN N°3 then EXIT

    similar to

    if IN3=0 THEN EXIT

    It means at this step, the Basic Stamp is looking at the PIN n°3 state.
    If it is high, then EXIT the loop.

    ++
  • MYMMYM Posts: 9
    edited 2005-11-29 12:55
    Thanks a lot for the info.
Sign In or Register to comment.