PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

29 lines
939B

  1. /*
  2. Controlling a servo position using a potentiometer (variable resistor)
  3. by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
  4. modified on 8 Nov 2013
  5. by Scott Fitzgerald
  6. http://arduino.cc/en/Tutorial/Knob
  7. */
  8. #include <Servo.h>
  9. Servo myservo; // create servo object to control a servo
  10. int potpin = 0; // analog pin used to connect the potentiometer
  11. int val; // variable to read the value from the analog pin
  12. void setup()
  13. {
  14. myservo.attach(9); // attaches the servo on pin 9 to the servo object
  15. }
  16. void loop()
  17. {
  18. val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
  19. val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
  20. myservo.write(val); // sets the servo position according to the scaled value
  21. delay(15); // waits for the servo to get there
  22. }