' {$STAMP BS2sx} ' {$PBASIC 2.5} 'VAR Bit ' Value can be 0 or 1 'VAR Nib ' Value can be 0 to 15 'VAR Byte ' Value can be 0 to 255 'VAR Word ' Value can be 0 to 65535 LED_IRTrig PIN 0 'define the IRTrigger pin to light the IR LEDs via the transistor LEDIndicator PIN 15 'define the pin that drive the LED indicator light. SWButton PIN 5 'define the pin that the switch is on IRFlashFreq VAR Word ' set the frequency of the IR LEDs gWorkSpace VAR Byte Piezo PIN 11 IDXInd VAR Nib 'LCD Variables lcd_cmd CON $FE 'command prefix lcd_cmd2 CON $7C 'special command prefix clrLCD CON $01 'Clear entire LCD screen displayOff CON $08 'Display off displayOn CON $0C 'Display ON noCurs CON $0C 'Make cursor invisible ulCurs CON $0E 'Show underline cursor blkCurs CON $0D 'Show blinking block cursor curpos CON $80 'set cursor + position (row 1=0 TO 15, row 2 = 64 TO 79) scrollRight CON $1C scrollLeft CON $18 curRight CON $14 curLeft CON $10 LCDRX CON 4 'set the LCD RX connection pin Inverted CON $4000 'Value for inverted serial format 'baud parameters. Baud CON T9600 '+ Inverted 8,N,1 inverted T9600 CON 240 'define and set the baud paramenters IRFlashFreq = 1200 'set it to 1200 to start beginning: DO 'BUTTON Pin, DownState, Delay, Rate, Workspace, TargetState, Address 'BUTTON SWButton, 1, 255, 0, gWorkSpace ,1, SwitchIRFreq 'DEBUG ? SWButton 'Allow for the frequency to be switched. IF SWButton=1 THEN PAUSE 500 'wait just a bit longer to ensure that the button is still pressed IF SWButton=1 THEN 'yup, the button is still pressed. GOTO SwitchIRFreq ENDIF ENDIF 'pin#, duration in MS, frequency in Hz (pulses per second) FREQOUT LED_IRTrig, 1000, IRFlashFreq 'flash the beacon for 1 second at the frequency chosen 'ever so often, blink the status LED to show the system is working. Roughly every 10 seconds IF IDXInd = 10 THEN IDXInd = 0 'reset the counter FREQOUT LEDIndicator, 500, 1 'flash the indicator LED once to identify that the system is working. 'FREQOUT Piezo, 200, 1200 'FREQOUT, PIN, DURATION, FREQUENCY FREQOUT Piezo, 250, 1350 'beep FREQOUT Piezo, 150, 1150 'beep PAUSE 200 ELSE IDXInd = IDXInd + 1 'increment the counter ENDIF LOOP SwitchIRFreq: 'flip the IR beacon frequency. IF IRFlashFreq = 1200 THEN IRFlashFreq = 600 ELSE IRFlashFreq = 1200 ENDIF 'display results on the LCD SEROUT LCDRX,Baud,[lcd_cmd, displayOn] SEROUT LCDRX,Baud,[lcd_cmd, clrLCD] SEROUT LCDRX,Baud,[lcd_cmd2, $8C] '40% backlight PAUSE 1000 'allow the LCD to initialize (important or it wont work!) SEROUT LCDRX,Baud,[lcd_cmd, curpos + 0, "New Freq: ", DEC IRFlashFreq, "Hz"] SEROUT LCDRX,Baud,[lcd_cmd, curpos + 64,"Waiting 2 sec."] PAUSE 1000 SEROUT LCDRX,Baud,[lcd_cmd, curpos + 64,"Waiting 1 sec.."] PAUSE 1000 SEROUT LCDRX,Baud,[lcd_cmd, clrLCD] SEROUT LCDRX,Baud,[lcd_cmd, displayOff] GOTO beginning