Step 3Now that it works on your breadboard...
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' -----( I/O Definitions )-------------------------------------------------
PIR PIN 0 ' I/O Pin For PIR Sensor
LEDONE PIN 15 ' I/O Pin For Green LED
LEDTWO PIN 14 ' I/O Pin For Red LED
' -----( Variables )-------------------------------------------------------
counter VAR Byte ' Trip Counter
x VAR Word ' define a general purpose variable
sign VAR x.BIT15 ' sign bit of x
degC VAR Word ' define a variable to hold degrees Celsius
degF VAR Word ' to hold degrees Fahrenheit
' -----( Initialization )--------------------------------------------------
DEBUG CLS ' Clear DEBUG Screen
SEROUT 12,396,("!NB0W07:", "Warming Up",CLS) 'Tell the PINK whats up
FOR counter = 10 TO 0
HIGH LEDONE ' Flash the LEDS
LOW LEDTWO ' Wait 20 Seconds For PIR Warm-Up
DEBUG HOME, "Warming up:", DEC2 counter
SEROUT 12,396,("!NB0W07:Warming up:", CLS)
PAUSE 1000
LOW LEDONE
HIGH LEDTWO
PAUSE 1000 ' Display Counter Every Second
NEXT
LOW LEDONE
LOW LEDTWO
counter = 0 ' Clear Counter Variable
DEBUG HOME, "Waiting"
SEROUT 12,396,("!NB0W07:Waiting...", CLS)
HIGH LEDTWO
HIGH 5 ' select the DS1620
SHIFTOUT 7,6,LSBFIRST,(238) ' "start convertions" command
LOW 5 ' do the command
' -----( Program Code )----------------------------------------------------
Main:
DO
'Motion detector
IF PIR = 1 THEN ' Motion Detected?
counter = counter + 1 ' Update Trip Counter
HIGH LEDONE '
LOW LEDTWO ' Light Red LED
DEBUG HOME, "TRIPPED...", DEC3 counter
SEROUT 12,396,("!NB0W07:", "Tripped...",CLS)
DO : LOOP UNTIL PIR = 0 ' Wait For PIR To Clear
DEBUG HOME, "CLEARED...", DEC3 counter
SEROUT 12,396,("!NB0W07:", "Cleared...",CLS)
LOW LEDONE
HIGH LEDTWO ' Turn Off Red LED
ENDIF
'Temperature
HIGH 5 ' select the DS1620
SHIFTOUT 7,6,LSBFIRST,(170) ' send the "get data" command
SHIFTIN 7,6,LSBPRE,(x\9) ' get the data, including sign
LOW 5 ' end the command
x.BYTE1 = -x.BIT8 ' extend the sign to 16 bits
degC=x*5 ' convert to 'C*10 (resolution 0.5 'C)
degF= degC+2732*9/50-459 ' conver to F
DEBUG ? degF, CR, CR ' Show on debug
SEROUT 12,396,("!NB0W06:", DEC degF ,CLS)
'Garage Door detector.
IF IN1 = 0 THEN
SEROUT 12,396,("!NB0W08:", "Open" ,CLS)
ELSE
SEROUT 12,396,("!NB0W08:", "Closed" ,CLS)
ENDIF
PAUSE 1000
LOOP
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|
























![[Purple] living and dining room makeover](http://img.instructables.com/files/deriv/FDK/7JLC/GP7IRZZR/FDK7JLCGP7IRZZR.SQUARE.jpg)


















