Shop OBEX P1 Docs P2 Docs Learn Events
Basic Programming Help — Parallax Forums

Basic Programming Help

Jason GulbinasJason Gulbinas Posts: 17
edited 2007-02-22 03:15 in BASIC Stamp
hello:

· I am new to Basic programming and·am currently geting through both·"What's a Microcontroller" and "Applied Sensors" ... both very helpful.· I am wondering what the logic would be behind a very simple program I am working on.· The program would take the current temperature (I know this part of the program) and would make a beep with the transducer once a temperature is passed though (I know this part too).· The problem I am having is that once the "target temperature" is passed I want the program to enter a new area where it will not keep beeping if the temperature is fluctuating ariund the target.·

So:

- Once target temperature is hit (Something like IF Temp (Variable) > 21 THEN...make a beep (FREQUOUT)

BUT once that is done don't do it again until the program is restarted totally.· Therefore, if the Tepm variates around 21, say, I don't want it to keep beeping.· Once it gets there and keeps rising it is okay if the sensor goes down and up a few times but I don't want the command to be initiated again.

I guess I might be able to accomplish this with a Subroutine that is entered after the "Target temp" is reached and cannot get out of since it is on it's own DO...LOOP routine?

Or perhaps make an index where the index can only reach 1 and it does not happen again?

Any help would be appreciated!· Thanks in advance!

Comments

  • NewzedNewzed Posts: 2,503
    edited 2007-02-21 21:55
    You could try something like this:

    if temp =< target temp + 1·or temp=> target temp -1 then
    frequout pin, 0
    endif

    It's difficult to help without your complete program.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Yesterday is history, tomorrow is a mystery, and today is a gift.

    That is why they call it the present.

    Don't have VGA?
    Newzed@aol.com
    ·
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-21 21:57
    You've got the basic idea. Your main program has two sections, call them "startup" and "maintain". "startup" is first and "maintain" is second. You can use a DO ... LOOP for each section or a label at the beginning of each section (say "startup:" and "maintain:") and GOTOs within the sections (or both conventions). I wouldn't call these subroutines. Reserve that term for routines called with a GOSUB and ending with a RETURN.
    ' initialization code
    startup:
    GOSUB takeTemp
    IF temp < limit then
      GOSUB increase
      GOTO startup
    ENDIF
    ' do beep
    maintain:
    GOSUB takeTemp
    IF temp < limit THEN
      GOSUB increase
      GOTO maintain
    IF temp > limit THEN
      GOSUB decrease
      GOTO maintain
    ENDIF
    GOTO maintain
    takeTemp:
    ' do stuff
    RETURN
    increase:
    ' do stuff
    RETURN
    decrease:
    ' do stuff
    RETURN
    
    
  • NewzedNewzed Posts: 2,503
    edited 2007-02-21 21:57
    Had to edit my post.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Yesterday is history, tomorrow is a mystery, and today is a gift.

    That is why they call it the present.

    Don't have VGA?
    Newzed@aol.com
    ·
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2007-02-21 22:30
    I like to use a flag for this purpose. Flag=0 to start.

    IF Temp (Variable) > 21 AND flag=0 THEN
    ' make a beep (FREQUOUT)
    flag = 1
    ENDIF

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Jason GulbinasJason Gulbinas Posts: 17
    edited 2007-02-22 03:15
    Okay! These are great solutions...I will put them to work and see which works best for my application...which is still developing. Thanks so much all of you for your input.
Sign In or Register to comment.