Tuesday, November 15, 2011

A basic programme to read and write PWM signal


#include
int pin = 7;
int val  = 0;
Servo myservo;
unsigned long duration;

void setup()
{
  pinMode(pin, INPUT);
  //pinMode(9, OUTPUT);
  myservo.attach(9);
}

void loop()
{
  duration = pulseIn(pin, HIGH);
  duration = map(duration,1160,1780,0,179);
  myservo.write(duration);
}

There was an error in this gadget