I love to controll a servo with a potentiometer, because I could make a working car. But now you will just learn to controll it and how the code works!
// eingebaute Bibliothek einbinden # include <Servo.h>// Bezeichnung des Motors ServoMotor;// speichert den analogen Wert des Drehpotentiometers intReglerWert;// Position des Motors intPosition;voidsetup(){// Motor an Pin 9 angeschlossen (attach)Motor.attach(9);}voidloop(){intReglerWert=analogRead(A0);/* umwandeln des gelesenen Wertes in die Drehung des Motors von 0 bis 1023 (analoger Sensorwert) auf 0 bis 180 (Drehung des Motors) */Position=map(ReglerWert,0,1023,0,180);// Motor zur Position bewegenMotor.write(Position);}
Comments