' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------
'
' Uses FREQOUT to modulate an IR LED for object detection. When object
' is detected, a tone is generated from the pieze element.
' -------------------------------------------------------------------------
' Device Settings
' -------------------------------------------------------------------------
DEVICE SX28, OSCXT2, TURBO, STACKX, OPTIONX
FREQ 4_000_000
ID "FREQOUT"
' -------------------------------------------------------------------------
' IO Pins
' -------------------------------------------------------------------------
IrLED VAR RB.0 ' output to IR LED
Detect VAR RB.1 ' input from IR detector
Spkr VAR RB.2 ' output to piezo
' -------------------------------------------------------------------------
' Constants
' -------------------------------------------------------------------------
IrMod CON 38000 ' modulation freq = 38 kHz
Yes CON 0 ' for active-low output
No CON 1
' =========================================================================
PROGRAM Start
' =========================================================================
' -------------------------------------------------------------------------
' Program Code
' -------------------------------------------------------------------------
Start:
DO
FREQOUT IrLED, 1, IrMod ' modulate IR diode
IF Detect = Yes THEN ' check detector
SOUND Spkr, 100, 2 ' buzz if object detected
ENDIF
LOOP