#include <Servo.h>
Servo myservo;
int potpin = A0;
int serpin = 9;
int val;
void setup() {
myservo.attach(serpin);
}
void loop() {
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 180);
myservo.write(val);
delay(15);
}
/*
const int analogInPin = A0;
const int analogOutPin = 9; // Sheet says 5
int sensorValue = 0;
int outputValue = 0;
int pos = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(analogOutPin, OUTPUT);
// attaches servo on pin 9 to servo object
myservo.attach(9);
}
void loop() {
// put your main code here, to run repeatedly:
sensorValue = analogRead(analogInPin);
outputValue = map(sensorValue, 0, 1023, 0, 180);
//TODO: add user input here
//outputValue = Serial.read();
analogWrite(analogOutPin, outputValue);
Serial.print("sensor = ");
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);
// move the servo motor
// speed is inversely proportional to light coming in
if (outputValue < 200) {
myservo.write(0);
delay(random(outputValue * 5, outputValue * 20));
myservo.write(180);
delay(random(outputValue * 5, outputValue * 20));
}
delay(2);
}
*/