Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public Serial1 As Serial
Public servo1 As Servo
Public pinservo As Pin
Public Timer1 As Timer
Public potentiometer As Pin
Public driver As Adafruit_PWMServoDriver
Public const MIN_PULSE_WIDTH As Long = 80
Public const MAX_PULSE_WIDTH As Long = 620
Public const FREQUENCY As Long = 50
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
potentiometer.Initialize(potentiometer.A0,potentiometer.AnalogRead)
driver.Initialize(0x40)
driver.SetPWMFreq(FREQUENCY)
AddLooper("IntPot")
End Sub
Sub IntPot
Dim ServoPos As Int
ServoPos = MapRange(potentiometer.AnalogRead,0,1023,0,179)
driver.SetPWM(0,0,convert2angle(ServoPos)) ' KY66 working
driver.SetPWM(1,0,convert2angle(ServoPos)) 'KY66 working'
driver.SetPWM(2,0,convert2angle(ServoPos)) 'MG966R NOT working
Log("pot:",potentiometer.AnalogRead)
Log("ServoCmd:",ServoPos)
End Sub
Sub convert2angle (myang As Int) As Int
Dim pulse As Int
pulse =MapRange(myang,0,180,MIN_PULSE_WIDTH,MAX_PULSE_WIDTH)
Return pulse
End Sub