/* ServoPWM * --------------- * * Comments * This is a standalone version for 1 servo (out 9) and one poti (analog in 0) * */ int val = 0; void setup(void) { pinMode(9,OUTPUT); // Servo Pin Serial.begin(9600); TCCR1A = 0x00; // sets timer control bits to PWM Phase and Frequency Correct mode TCCR1B = 0x12; // sets timer control bits to Prescaler N = 8 //ICR1 = 0x0FA0;; // Upper Timer Limit = 4000 (in hex) equals 4ms => 1/5 of servo frequency ICR1 = 0x4E20; // My own frequency of the PWM: Upper Timer Limit = 20000 (in hex) equals 20ms => 1/1 of servo frequency } void loop(void) { val = analogRead(0); // read potentiometer Serial.print ("Poti-value: " ); Serial.println( val); // poti servo value: must be from 0-1024 (=10 bit) val = (val * 1.38) + 600; // convert potentiometer reading to value in microseconds (my servo responds to signals in the 600us - 2400us range > use 1.6 as factor) // the conrad servor responds to 600-2020us range > so i used 1.38 analogWrite(9,val); // pulse servo Serial.print ("Servo-value: " ); Serial.println( val); // output servo value }