>
>
> > I tried using oA2D Last night but it just read 0 all the time for
all
> > the sensors. I'll give it a go tonight when I get home using
oIRRange
> > to see if I get any readings from it.
> >
> > Thanks,
> >
> > Jason
> >
>
> Post your code! This should be an easy program. It is helpful to
> have a DVM measuring the pin at the same time the program is
running.
>
> You will find that the readings bobble. Make certain you put a 33
ufd
> electrolytic cap immediately adjacent to the sensor - across VCC and
> GND. You can try putting a 0.1 ufd ceramic capacitor between the
A/D
> input pin and GND.
>
> Richard
>
Thanks for that I've managed to fix the non signal problem. I've
managed to adjust a bit of the values and now the sensors are working
as expected. I'll post the code anyway so other peeps can make use of
it:
' Declare servo objects
Dim leftServo As New oServoSP
Dim rightServo As New oServoSP
' Declare range sensor objects
Dim leftRangeSensor As New oA2D
Dim centreRangeSensor As New oA2D
Dim rightRangeSensor As New oA2D
' Setup range sensor values
Const rangeAtRange = 30
Const rangeClose = 80
' Setup sensor direction values
Const left = 1
Const centre = 2
Const right = 3
' Declare LED objects
Dim redLED As New oLED
Dim yellowLED As New oLED
Dim greenLED As New oLED
' Setup LED brightness levels
Const noObstacle = 0
Const atRange = 1
Const close = 14
' Setup LED Colour constants
Const red = 1
Const yellow = 2
Const green = 3
Sub Main()
' Initialise routines
SetupDevices()
' Main loop
Do
UpdateLED()
Loop
End Sub
Sub SetupDevices()
SetupLED()
SetupSensor()
SetupServo()
End Sub
Sub SetupLED()
' Setup the Red onboard LED
' This will be representing the Right Sensor
redLED.IOLine = 7
SetLED(red, noObstacle)
redLED.Operate = cvTrue
' Setup the Yellow LED
' This will be representing the center Sensor
yellowLED.IOLine = 6
SetLED(yellow, noObstacle)
yellowLED.Operate = cvTrue
' Setup the Green LED
' This LED will represent the left sensor
greenLED.IOLine = 5
SetLED(green, noObstacle)
greenLED.Operate = cvTrue
End Sub
Sub SetLED(LEDColour As Byte, brightness As Byte)
If LEDColour = red Then
redLED.Brightness = brightness
End If
If LEDColour = yellow Then
yellowLED.Brightness = brightness
End If
If LEDColour = green Then
greenLED.Brightness = brightness
End If
End Sub
Sub SetupServo()
leftServo.IOLine = 29
rightServo.IOLine = 30
End Sub
Sub SetupSensor()
leftRangeSensor.IOLine = 2
leftRangeSensor.Operate = cvTrue
centreRangeSensor.IOLine = 3
centreRangeSensor.Operate = cvTrue
rightRangeSensor.IOLine = 4
rightRangeSensor.Operate = cvTrue
End Sub
' Routine to update the LED's based on the
' results from the Sensors
Sub UpdateLED()
redLED.Brightness = GetSensor(left)
yellowLED.Brightness = GetSensor(centre)
greenLED.Brightness = GetSensor(right)
End Sub
' Retuen the sensor range
Function GetSensor(position As Byte) As Byte
Dim value As oByte
If position = left Then
value = leftRangeSensor.Result
End If
If position = centre Then
value = centreRangeSensor.Result
End If
If position = right Then
value = rightRangeSensor.Result
End If
GetSensor = noObstacle
If value >= rangeAtRange Then
GetSensor = atRange
End If
If value >= rangeClose Then
GetSensor = close
End If
End Function
Jas
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/oopic/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/oopic/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:oopic-digest@yahoogroups.com
mailto:oopic-fullfeatured@yahoogroups.com
<*> To unsubscribe from this group, send an email to:
oopic-unsubscribe@yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
No comments:
Post a Comment