Shop OBEX P1 Docs P2 Docs Learn Events
Know its easy (programing) — Parallax Forums

Know its easy (programing)

mike_leramike_lera Posts: 5
edited 2012-04-29 10:12 in BASIC Stamp
is it possable to add a varable string to a stamp program such as
a=1
a+1=b
if b = 500 then high 13
b = new a
or something along that line
thanks in advance
Mike

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-04-18 14:19
    I don't quite understand what you want to do when you say "add a variable string to a Stamp program". Your examples don't really illuminate this. Can you give some context?
  • mike_leramike_lera Posts: 5
    edited 2012-04-19 13:20
    Hi Mike
    thanks for responding!
    what I am tring to do is count for a time base (say 3 min.) and the only way I know how to do it is to use "gosub" and make a variable that and a count to it then releases the processor to look at a switch for closer, if I let it count and the switch closes during the time it counts, the stamp never sees it, ( I havent programed anything sence collage 1982 LOL) just working my way thrue it
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    HIGH 14
    DO
    DEBUG ? IN0
    DEBUG ? IN1
    IF (IN1 = 1) THEN
    LOW 14
    HIGH 15
    HIGH 12
    GOSUB timer_timer
    ELSEIF (IN0 = 1) THEN
    LOW 15
    HIGH 14




    ENDIF

    LOOP
    flash_lights:
    LOW 11
    HIGH 12
    PAUSE 250
    LOW 12
    HIGH 11
    PAUSE 250

    RETURN

    timer_timer:
    a=1
    a+1=b
    IF b = 200 THEN
    HIGH 13
    PAUSE 200
    b=a

    RETURN


    Thanks again
    Mike
  • Mike GreenMike Green Posts: 23,101
    edited 2012-04-19 14:20
    Typically, you'd use a PAUSE for a time base. In your case, where the total time involved is on the order of minutes, a good time "tick" is something between 100ms and 1s. Your program would test each switch in turn. If none are pressed, the program would do something like PAUSE 250, increment a variable, and go back to the top of the loop if the count is less than your time limit (720 for 3 mins at 1/4s per "tick").
  • ercoerco Posts: 20,256
    edited 2012-04-19 15:03
    Mike_lera: You can use the PBasic editor to check for syntax errors. For instance, your section

    timer_timer:
    a=1
    a+1=b
    IF b = 200 THEN
    HIGH 13
    PAUSE 200
    b=a
    RETURN

    needs a few tweaks. It might be rewritten several ways, including defining a and b as word or byte variables, or simply using the default variables b0-b15:

    timer_timer:
    b0=1 'was a=1
    b1=b0+1 ' was a+1=b
    IF b1 = 200 THEN HIGH 13 'was b=200
    PAUSE 200
    b1=b0 'was b=a
    RETURN
  • mike_leramike_lera Posts: 5
    edited 2012-04-20 07:50
    Mike and Erco
    Thank you for your replies
    Here is what I am trying to accomplish
    Initial power on= high 14 (red indicator "stop")
    Start =high 15 (green indication)
    Timer activation = high 13, pause 50, low 13 (yellow indication)
    timer=upon IN1 activation time is started (approx. 3 min.) at end of time HIGH 12, pause 250, LOW 12, HIGH 15 and timer restart
    Start sw = IN1
    stop sw = IN0 (if activated HIGH 14, LOW 15, LOW 13, LOW 12) this sw needs to be monitored once or twice a second (this activation is highest priority)

    This is for my dust collector
    after 3 min if running I want to turn off the blower motor, activate air solenoid, (to shake the dust into the bag) and then automatically start the blower motor again, over and over
    The stop (IN0) has to have the highest priority to turn it off
    Thank You for your input
    Mike
  • mike_leramike_lera Posts: 5
    edited 2012-04-29 08:46
    If you would please take another look
  • Mike GreenMike Green Posts: 23,101
    edited 2012-04-29 10:12
    You'll have to do the rest yourself, but here's a 3 minute timer that checks for a stop condition. "time" is declared as a word variable. You have to provide a "stopTiming" label somewhere that will handle the case where the stop button is pressed.

    time3Minutes:
    time = 720 ' initialize time to 3 minutes at 1/4 second per "tick"
    basicTimeLoop:
    pause 250 ' 1/4 second "tick"
    time = time - 1 ' decrement time-to-go
    if in0 = 1 then goto stopTiming ' check for stop button (active high)
    if time > 0 then goto basicTimeLoop ' keep going if time not over
    ' program comes here at end of 3 minutes

    Remember that after a test for either IN0 or IN1 pushbuttons being pressed, that you need a loop to check whether they're released like

    DO : LOOP WHILE IN0 = 1
Sign In or Register to comment.