Try this:
using System.Threading;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
/*
September 28, 2015:
I found this code at this URL: https://jamessdixon.wordpress.com/category/netduino/
All the servo examples (the ones I examined) on the Netduino forums & even on the GHI codeshare space are written for the pre NETMF 4.2/4.3 PWM implementation.
There's a guy named Chris Seto who wrote something & posted it to GHI & Netduino. It's OLD. He's not back with a revised version.
*/
namespace Tryout_Servo
{
public class Program
{
private const uint TILT_SERVO_STRAIGHT = 1500;
private const uint TILT_SERVO_MAX_UP = 2000;
private const uint TILT_SERVO_MAX_DOWN = 1000;
private const uint PAN_SERVO_STRAIGHT = 1500;
private const uint PAN_SERVO_MAX_LEFT = 750;
private const uint PAN_SERVO_MAX_RIGHT = 2250;
private static PWM _tiltServo;
private static PWM _panServo;
private static uint _tiltServoCurrentPosition = 0;
private static uint _panServoCurrentPosition = 0;
public static void Main()
{
SetupServos();
InputPort button = new InputPort(Pins.ONBOARD_BTN, false, Port.ResistorMode.Disabled);
while (true)
if (button.Read())
MoveServo();
}
private static void SetupServos()
{
uint period = 20000;
_tiltServoCurrentPosition = TILT_SERVO_STRAIGHT;
_panServoCurrentPosition = PAN_SERVO_STRAIGHT;
_panServo = new PWM(PWMChannels.PWM_PIN_D5, period, _panServoCurrentPosition, PWM.ScaleFactor.Microseconds, false);
_panServo.Start();
}
private static void MoveServo()
{
_panServo.Duration = PAN_SERVO_MAX_LEFT;
Thread.Sleep(2000);
_panServo.Duration = PAN_SERVO_MAX_RIGHT;
Thread.Sleep(2000);
_panServo.Duration = PAN_SERVO_STRAIGHT;
Thread.Sleep(2000);
}
}
}