Shop OBEX P1 Docs P2 Docs Learn Events
Basic1 programming problem — Parallax Forums

Basic1 programming problem

Gary HoffmannGary Hoffmann Posts: 10
edited 2009-11-27 10:58 in BASIC Stamp
Hello all,

I have been fiddling with a very simple program off and on for some time and I can't seem to get a "handle" on this "problem"..Basic Stamp1 is looking at an input pin and depending on the state of the pin (high/low) is supposed to go into two different routines.· I am not looking for someone to "write the program for me, but I am miseralbly failing somewhere...I have posted a request before but was not too successful with it..
I'll post the unfinished routine here and attemt to "remark" what I am attempting to do... Please understand that I am very "green" with this soooo· patience if you please, however any constructive help would be greatly appreciated.

Thanks,

Gary


Dirs = %00001111
Start:
IF PIN0 = 0 then relayroutine1
IF PIN0 = 1 then relayroutine2

relayroutine1:

HIGH 5······················· 'Pulling pin5 high
Pause 800
High 6························ 'Pulling pin6 high
Pause 800
LOW 6
Pause 800
LOW 5

All very simple...however if I get the program to go back to start and pin 0 is still 0 or·1 (as the case may be)·it obviously continues to do this loop which I do not want.. I want this to be executed only one time, regardless how long pin0 is "0" or "1"
However, if I don't put a "pointer" back to start, the processor will "hang at the bottom of this routine and "that is it"...

Now for the relayroutine2 it is basically the same thing, it is supposed to toggle through the routine and than ·sit, look at·pin0 and ONLY act upon a chance in level on pin0..

Where am I going wrong here or what am I not "getting" ???

Any help would be super..

Thanks a bunch

Gary




·

Comments

  • Mike2545Mike2545 Posts: 433
    edited 2009-11-27 03:35
    You need some goto start in the code to make it not hang at the bottom

    Dirs = %00001111
    Start:
    IF PIN0 = 0 then relayroutine1
    IF PIN0 = 1 then relayroutine2
    GOTO START
    relayroutine1:

    HIGH 5 'Pulling pin5 high
    Pause 800
    High 6 'Pulling pin6 high
    Pause 800
    LOW 6
    Pause 800
    LOW 5
    GOTO START

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mike2545

    This message sent to you on 100% recycled electrons.
  • Gary HoffmannGary Hoffmann Posts: 10
    edited 2009-11-27 05:17
    Hello Mike,

    that is true what you are stating..however, if I do that the program will loop ad infinitum and that is not what is needed.· I had a "goto" in there and of course it jumped up to the "if-then" line...seeing that pin0 was still "0" and it went right through the program, making pin6 and 5 high or low as requested in the program..again not what is needed..it needs to do one turn, go back up, look at the pin0 state, if it is still the same as before do nothing, if it has chanced do the second routine and whe it comes back and sees that nothing (secound routine) has not chanced ..wait until another event on pin0 occurs..

    Thanks for your time Mike


    GH
    ·
  • Mike2545Mike2545 Posts: 433
    edited 2009-11-27 06:53
    How many times do you want the program to look at the state of the pins¿

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Mike2545

    This message sent to you on 100% recycled electrons.
  • ChilesChiles Posts: 15
    edited 2009-11-27 10:58
    just add a variable to be used as a flag start/on/off
    when the progran begins it is set to 0, until it sees what which condition the pin is in. have program update this flag to 1 if condition one is true or 2. Then when the program comes back again to repeat if condition is same skip main portion of program, maybe pause a little then chech condition again. If condition has changed then have program change flag to match new condition until it changes.
    Good luck!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    pan33.gif

    this is the way I pan one of my cameras from the internet - RS232 from security program
Sign In or Register to comment.