Arduino

Arduino

a.

#include <Servo.h>

Servo myServo;

int const potPin = A0;

int porVal;

int angle;

void setup () {

 myServo.attach(9);

 Serial.begin(9600);

}

void loop () {

 porVal = analogRead(potPin);

 Serial.print("potVal: ");

 Serial.print(potVal);

 angle = map(potVal, 0, 1023, 0, 179);

 Serial.print("; angle: ");

 Serial.println(angle);

 myServo.write(angle);

 delay(15);

}


Report Page