| |
'*************************************************************************'
'Description: The Sharp GP2D12 Infrared Object Detector and '
'DS-LCDD 2 x 16 character Serial LCD Module controlled by the '
'OOPic II Microcontroller, demonstrating distance measurement, '
'displayed on the LCD. '
' '
'N.B. Due to the A2D conversion, readings are only accurate over '
'small ranges of distance. '
' '
'Created: 21/08/02 Revision 1.00 '
'Written By: Total Robots (Jamie Finnan) '
'TR-004 '
'*************************************************************************'
Dim LCD As New oLCDSE 'Serial LCD Object
Dim IR As New oIRRange 'IRRange Object
Dim Store As New oByte 'Store for IR ReadingSub Main()
IR.IOLine = 1 'Pin 7, IR data line
IR.Operate = 1 'IR on
LCD.IOLine = 8 'LCD Data Line
LCD.Clear 'Clear LCD Screen
LCD.String = "Sharp GP2D12 IR" 'First Line of text
LCD.Value = 254 'Command value
LCD.Value = 192 'Second line command
LCD.String = "Detector System" 'Second line of text
OOPic.delay = 200 '2 second delay
Call IR_Read
End Sub
'*************************************************************************'
Sub IR_Read()
Do
Store = IR 'Move IR value into Store
If Store >=20 then 'If store is greater or equals to
Call Check '20 then check for what distance is
else
Call Waiting
End If
Loop
End Sub
'*************************************************************************'
Sub Check()
If store <= 27 then 'Looks for value between 20-27
call Dis10
elseIf Store <=37 then 'Looks for value between 30-37
Call Dis15
elseIf Store <=47 then 'Looks for value between 38-47
Call Dis20
elseIf Store <=58 then 'Looks for value between 48-58
Call Dis25
elseIf Store <=74 then 'Looks for value between 58-74
Call Dis30
else
call Waiting 'Otherwise output waiting screen
end if
end Sub
Sub Dis10() 'Distance of 09-12cm output
LCD.Clear
LCD.String = "Distance is "
LCD.Value = 254
LCD.value = 192
LCD.String = "approx 09-12 cm."
OOpic.delay = 150
End Sub
Sub Dis15() 'Distance of 12-16cm output
LCD.Clear
LCD.String = "Distance is "
LCD.Value = 254
LCD.value = 192
LCD.String = "approx 12-16 cm."
OOPic.delay = 150
End Sub
Sub Dis20() 'Distance of 16-22cm output
LCD.Clear
LCD.String = "Distance is "
LCD.Value = 254
LCD.value = 192
LCD.String = "approx 16-22 cm."
OOPic.delay = 150
End Sub
Sub Dis25() 'Distance of 22-26cm output
LCD.Clear
LCD.String = "Distance is "
LCD.Value = 254
LCD.value = 192
LCD.String = "approx 22-26 cm."
OOPic.delay = 150
End Sub
Sub Dis30() 'Distance of 26-32cm output
LCD.Clear
LCD.String = "Distance is "
LCD.Value = 254
LCD.value = 192
LCD.String = "approx 26-32 cm."
OOPic.delay = 150
End Sub
Sub Waiting() 'Measurement waiting screen
LCD.Clear
LCD.String = "Waiting for new"
LCD.Value = 254
LCD.Value = 192
LCD.String = " Measurement "
OOPic.Delay = 25
End Sub
'*************************************************************************'
|