'{$STAMP BS2} '------------------------------------------ 'greet.bs2 ' 'This program waits for someone to walk by, then 'greets them with a doorbell-like sound and an LED. motiond var bit 'Motion variable waitt var byte 'Wait time start: pause 10000 'Wait for warm-up. greet1: high 10 'Red LED off gosub getmd 'Get sensor reading. if motiond = 1 then greet2 high 10 'Red LED off goto greet1 'Loop forever greet2: low 10 'Red LED on 'Doorbell sound freqout 9,600,800 'Alarm sound freqout 9,600,650 'Alarm sound 'Wait for motion to stop for 10 seconds. greet3: waitt = 0 'Wait time low 10 'Red LED on greet4: gosub getmd 'Get sensor reading. if motiond = 1 then greet3 high 10 'Red LED off pause 500 'wait .5 seconds waitt = waitt + 1 'Update counter if waitt = 20 then greet1 goto greet4 'Loop until finished. '------------------------------------------ 'getmd 'Reads the PIR motion detector and sets 'variable motiond. getmd: motiond = in5 'Get detector state return 'Done