Ok.... I found this code and I set it up as they said. Now this happens ALL the time. I past it, and it has a load of errors. It beats me how it can work for some ells and not for me.
As you said Heroduino, writing it in code is a lot easier to understand. So please if can please fix the code for me.
Here are the errors and the code.
Error 1 Overload resolution failed because no accessible 'New' accepts this number of arguments. Servo_AP.vb 41 25 Servo test 12
Warning 2 Using DirectCast operator to cast a value-type to the same type is obsolete. Servo_AP.vb 41 44 Servo test 12
Error 3 The targeted platform does not support latebinding. Servo test 12Servo_AP.vb 43 13 Servo test 12
Error 4 'SetDutyCycle' is not a member of 'Microsoft.SPOT.Hardware.PWM'. Servo test 12Servo_AP.vb 66 13 Servo test 12
Error 5 'SetPulse' is not a member of 'Microsoft.SPOT.Hardware.PWM'. Servo_AP.vb 87 17 Servo test 12
Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware
Imports SecretLabs.NETMF.Hardware.Netduino
Module Module1
Sub Main()
Dim servo As New Servo_API.Servo(Pins.GPIO_PIN_D9)
Dim i As Integer = 0
Do While True
Do While i < 100
'Loop to fade from off to full on'
servo.Degree = i
'wait for 15 milliseconds'
Thread.Sleep(10)
i = i + 1
Loop
i = 100
Do While i > 0
'Loop to fade from full on to off'
servo.Degree = i
'wait for 15 milliseconds'
Thread.Sleep(10)
i = i - 1
Loop
Loop
End Sub
End Module
--------------------------------------------------------------------------------------------------------------------------
'
' * Servo NETMF Driver '
' * Coded by Chris Seto August 2010 '
' * <chris@chrisseto.com> '
' * '
' * Use this code for whatveer you want. Modify it, redistribute it, I don't care.
' * I do ask that you please keep this header intact, however. '
' * If you modfy the driver, please include your contribution below: '
' * '
' * Chris Seto: Inital release (1.0) '
' * Chris Seto: Netduino port (1.0 -> Netduino branch) '
' * Chris Seto: bool pin state fix (1.1 -> Netduino branch) '
' * Fileark: 2012-05-08 Converted to VB (
' * '
' * '
Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware
Namespace Servo_API
Public Class Servo
Implements IDisposable
' PWM handle'
Private servo As PWM
' Timings range'
Private range As Long() = New Long(1) {}
' Set servo inversion'
Public inverted As Boolean = False
' Create the PWM pin, set it low and configure timings'
Public Sub New(ByVal pin As Cpu.Pin)
' Init the PWM pin'
Dim servo = New PWM(DirectCast(pin, Cpu.Pin))
servo.SetDutyCycle(0)
' Typical settings'
range(0) = 800
range(1) = 3200
End Sub
Public Sub Dispose() Implements IDisposable.Dispose
disengage()
servo.Dispose()
End Sub
' Allow the user to set cutom timings'
Public Sub setRange(ByVal fullLeft As Long, ByVal fullRight As Long)
range(1) = fullLeft
range(0) = fullRight
End Sub
' Disengage the servo. '
' The servo motor will stop trying to maintain an angle'
Public Sub disengage()
servo.SetDutyCycle(0)
End Sub
' Set the servo degree'
Public WriteOnly Property Degree() As Double
Set(ByVal value As Double)
' Range checks'
If value > 180 Then
value = 180
End If
If value < 0 Then
value = 0
End If
' Are we inverted?'
If inverted Then
value = 180 - value
End If
' Set the pulse'
servo.SetPulse(20000, CUInt(map(CLng(Math.Truncate(value)), 0, 180, range(0), range(1))))
End Set
End Property
' Used internally to map a value of one scale to another'
Private Function map(ByVal x As Long, ByVal in_min As Long, ByVal in_max As Long, ByVal out_min As Long, ByVal out_max As Long) As Long
Return (x - in_min) * (out_max - out_min) (in_max - in_min) + out_min
End Function
End Class
End Namespace