// https://wokwi.com/projects/425456205563802625
// Demonstrating that Serov.read() reads the last servo.write()
// for https://forum.arduino.cc/t/help-with-making-if-statement-routine-more-efficient/1363808/4
// https://wokwi.com/projects/410112964087132161
// Code from https://github.com/arduino-libraries/Servo/blob/master/examples/Knob/Knob.ino
// Other simulations: https://forum.arduino.cc/t/wokwi-simulations-for-arduino-built-in-examples/1304754/6
/*
Controlling a servo position using a potentiometer (variable resistor)
by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
modified on 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Knob
*/
#include <Servo.h>
Servo myservo; // create Servo object to control a servo
void setup() {
Serial.begin(115200);
myservo.attach(9); // attaches the servo on pin 9 to the Servo object
}
void loop(){
int target = 0;
Serial.print(target);
myservo.write(target);
Serial.print(" ");
Serial.print(myservo.read());
Serial.print(" +2s...");
delay(2000);
Serial.print(myservo.read());
Serial.println(" ");
target = 180;
Serial.print(target);
Serial.print(" ");
myservo.write(target);
Serial.print(myservo.read());
Serial.print(" +2s...");
delay(2000);
Serial.print(myservo.read());
Serial.println(" ");
}