Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class Program
- {
- // This method is run when the mainboard is powered up or reset.
- GT.Interfaces.PWMOutput servo;
- void ProgramStarted()
- {
- // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
- Debug.Print("Program Started");
- servo = this.extender.SetupPWMOutput(GT.Socket.Pin.Seven);//must be pin 7,8,9 on socket with a P
- moveServo(0.2); // set to a value between 0 and 1. Where 0 is the first position and 1 is the last.
- }
- void moveServo(double servoPosition)
- {
- double maxRange = 2000; // the max pulse width
- double minRange = 700; // the min pulse width
- double totalDegrees = 180; // the number of degrees that the servo can turn
- double servoDegrees = totalDegrees * servoPosition;
- double hightimeCalculation = ((((maxRange - minRange) / totalDegrees)) * servoDegrees) + minRange;
- uint hightime = (uint)System.Math.Round(hightimeCalculation);
- servo.SetPulse(20 * 1000 * 1000, hightime * 1000);
- System.Threading.Thread.Sleep(100);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement