26 lines
375 B
Arduino
26 lines
375 B
Arduino
|
#include <Servo.h>
|
||
|
Servo myServo;
|
||
|
int const potPin = A0;
|
||
|
int potVal;
|
||
|
int angle;
|
||
|
|
||
|
void setup() {
|
||
|
myServo.attach(8);
|
||
|
|
||
|
Serial.begin(9600);
|
||
|
}
|
||
|
|
||
|
void loop() {
|
||
|
potVal = analogRead(potPin);
|
||
|
angle = map(potVal, 0, 1023, 0, 179);
|
||
|
|
||
|
Serial.print("Potval: ");
|
||
|
Serial.print(potVal);
|
||
|
Serial.print(" Angle: ");
|
||
|
Serial.print(angle);
|
||
|
|
||
|
myServo.write(angle);
|
||
|
|
||
|
delay(15);
|
||
|
}
|