topical media & game development
graphic-processing-algorithm-Ch11-p295-p295.pde / pde
void setup(){
pinMode(13,OUTPUT);
}
int degrees = 90;
int value2;
void loop(){
int value1 = analogRead(0);
int diff = value2 - value1;
degrees += diff;
degrees = constrain(degrees, 0, 180);
servoMove(13,degrees);
value2 = value1;
}
void servoMove(int pin, int angle){
int pulseWidth = (angle*11)+500;
digitalWrite(pin,HIGH);
delayMicroseconds(pulseWidth);
digitalWrite(pin,LOW);
delay(20);
}
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.