Shop OBEX P1 Docs P2 Docs Learn Events
Code help — Parallax Forums

Code help

MichelBMichelB Posts: 154
edited 2009-06-01 16:55 in Accessories
Hi to all,
in the attached code, when an out of range temperature is entered the message is showed noticed that temperature is out of range but program continues to run, where is my error? Thanks in advance.

Comments

  • VaatiVaati Posts: 712
    edited 2009-06-01 13:56
    So... It just continuously says, "Temperature out of range. Enter a different one." after you enter a temp that is out of range, or what.... ?

    Thanks.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Quit buying all those fixed voltage regulators, and·get an Adjustable Power Supply·for your projects!· Includes an LED testing terminal!
  • MichelBMichelB Posts: 154
    edited 2009-06-01 15:56
    Even with a temperature out of range program continues, how to ask to enter a temperature in the range before the program continues?
  • Jessica UelmenJessica Uelmen Posts: 490
    edited 2009-06-01 16:42
    Hi MichelB,

    The program continues because you don't tell it to return to the beginning of the program. So even though it will tell you the number is out of range, it is programmed to continue through the code. One solution would be to use subroutines, for example:

    Main:
    DO
      DEBUG CLS, "Enter temperature in degrees C (Min 18, Max 32)", CR
      DEBUGIN DEC degrees
      [b]GOSUB get_constant[/b]                               [i]' Program continues[/i]
    LOOP
    
    [b]get_constant:[/b]                                       [i]' Subroutine heading[/i]
    SELECT degrees
      CASE 18
      CmConstant = 2243
      [b]GOSUB display_distance[/b]                           [i]' Program continues, add to each case statement[/i]
    
      ...
    
      DEBUG CR, "Temperature out of range.", CR,
                "Enter a different one."
      [b]RETURN[/b]                                             [i]' Returns to Main to get another temperature value[/i]
    
      ...
    
      [b]display_distance:[/b]
      [i]Rest of code continues here[/i]
    
    
    



    Putting the main routine in a DO...LOOP ensures that the code will get another value each time the program receives a value that is out of the range of temperatures. Then, when the program receives a temperature that's in range, it continues to the "display_distance" subroutine (you can re-name them whatever you like) to get readings from the PING.

    For more information on subroutines, look up "GOSUB" in the BASIC Stamp Syntax and Reference Manual.

    Hope this helps!

    Jessica

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jessica Uelmen
    Education Department
    Parallax, Inc.

    Post Edited (Jessica Uelmen (Parallax)) : 6/1/2009 4:50:26 PM GMT
  • MichelBMichelB Posts: 154
    edited 2009-06-01 16:55
    Thank you very much Jessica.
Sign In or Register to comment.