Shop OBEX P1 Docs P2 Docs Learn Events
need help with basic stamp code — Parallax Forums

need help with basic stamp code

thangngocthangngoc Posts: 23
edited 2010-01-21 20:46 in BASIC Stamp
I have a small alarm project that have to use basic stamp language to determine whether the input to the alarm is 5V or ground (0V) via pin 1. If the input is 5V then the result is logic 1 otherwise the result is logic 0 . How can I put them in basic stamp language?

there is a sample code input/output in the BS2. Not sure if this helps

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

' Program to control Don's cranberry bog pump
' Program watches two 24 volt inputs (reduced to 5 volts by the time it reaches the stamp)
' When both 24 volt inputs are on then the solid state relay will go on
' The solid state relay will stay on until both 24 volt inputs go off.
' Bog Pump 1.bs2
‘ Uncomment DEBUG statements to turn on debugging

check VAR Byte       ' variable for debug output

DO      ' Loop to watch the two 24 volt inputs

  IF( IN3 = 1 AND IN1 = 1) THEN     ' If both 24 volt inputs are on
     HIGH 12                             ' Turn solid state relay on
     check = 1    
     'DEBUG  DEC check   ‘ Send condition state to terminal for debugging information
  ELSEIF( IN3 = 0 AND IN1 = 0) THEN   ' Only turn solid state relay off if both 24 volt inputs are off
      check = 0                             
      'DEBUG DEC check   ‘ Send condition state to terminal for debugging information
      LOW 12                             ' Turn solid state relay off

      '....................Debugging Code..............................
' This is useful if you have bad connections
  ELSEIF( IN3 = 0 AND IN1 = 1) THEN   ' These are just debugging lines to show
      check = 2                         ' what is happening on other 2 possible combinations of input ‘      ‘ line voltages
      'DEBUG DEC check                  ‘ Send condition state to terminal for debugging information
  ELSEIF( IN3 = 1 AND IN1 = 0) THEN  
      check = 3                         ...
      'DEBUG DEC check   ‘ Send condition state to terminal for debugging information                  ...
  ENDIF                                  ' End the if then section
       '..................End of Debugging Code.........................

LOOP                                     ' Go back and look at the 24 volt inputs again



Post Edited (thangngoc) : 1/21/2010 7:06:51 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-01-21 19:13
    What are you asking? The program you've posted looks ok.

    If you need a simpler version, then you can simplify what you've already posted. If you want us to rewrite the program for you, I don't think so.

    What you said you want to do is very simple. You need to go through the tutorials for learning about the Stamp and Parallax Basic. These are "What's a Microcontroller?" and the "BASIC Stamp Syntax and Reference Manual".

    www.parallax.com/tabid/477/Default.aspx

    Look under "BASIC Stamp Documentation" and under "Stamps in Class Downloads".
  • thangngocthangngoc Posts: 23
    edited 2010-01-21 20:00
    Thanks for the advice. I think this code is what I am trying to do in order to determine if the input of the device is logic 1 or 0
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    Main:
      INPUT 1                               ' Make P1 an input
      DEBUG "State of Pin 1: ",
            BIN1 IN1, CR
    
    END
    
    
  • Mike GreenMike Green Posts: 23,101
    edited 2010-01-21 20:12
    Yes, that will do it (once). You can even leave out the "INPUT 1" since the default state of all I/O pins is input.
  • Spiral_72Spiral_72 Posts: 791
    edited 2010-01-21 20:46
    ' Do it endless number of times... until you turn off the power or reset
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    INPUT 1 ' Make P1 an input
    Main:
    DEBUG "State of Pin 1: ",
    BIN1 IN1, CR
    goto main
    END








    ' Do it 1000 times
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    I VAR WORD

    Main:
    INPUT 1 ' Make P1 an input
    FOR I=1 to 1000
    DEBUG "State of Pin 1: ",
    BIN1 IN1, CR
    NEXT
    END
Sign In or Register to comment.