Help needed with programming ping sensor using basic stamp 2.0
I used the below code to detect distance with the ping sensor but now I want to convert that distance into a message i.e. If distance between 12-24 inches "maintenance immediately", If distance between 24-36 inches 'maintenance needed within two weeks". How do I include that in the below
code??????????'
code??????????'
' {$STAMP BS2} ' {$PBASIC 2.5} Ping_Pin CON 0 InConstant CON 890 inDistance VAR Word time VAR Word DO PULSOUT Ping_Pin, 5 ' Send short pulse to Ping PULSIN Ping_Pin, 1, time ' Wait for echo inDistance = inConstant ** time ' Convert to inches DEBUG CR, DEC inDistance ' Display result PAUSE 200 ' Short delay until next read LOOP
Comments
You'll need to use one of the comparison operations in PBasic such as IF/THEN, or SELECT/CASE.
Take a look at those commands in the help file or syntax manual for an explanation of how they work. Also, those sections have code samples.
BTW - I added some key words to your code that make it more readable - check 'em out.
IF inDistance > 12 AND inDistance < 24 THEN DEBUG "maintenance now",CR
PS, I see you don't have to wait around long here to get concurring opinions!