Advertisement
shapingstuff

Servo Method - Gadgeteer

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