Étape 4: Arduino Sketch
Cette esquisse seulement besoin d’une petite modification de la norme Servo > bouton sketch par Michal Rinott et Scott Fitzgerald , que j’ai alors appelé Bouton double ^_^
/* Controlling a servo position using a potentiometer (variable resistor) by Michal Rinott modified on 8 Nov 2013 by Scott Fitzgerald http://www.arduino.cc/en/Tutorial/Knob */#include <Servo.h> Servo myservoLR; // create servo object to control a servo Left-Right Servo myservoUD; // servo Up-Downint potpinLR = 0; // analog pin used to connect the potentiometer int potpinUD = 1; int valLR; // variable to read the value from the analog pin int valUD;void setup() { myservoLR.attach(9); // attaches the servo on pin 9 to the servo object myservoUD.attach(10); }void loop() { valLR = analogRead(potpinLR); // reads the value of the potentiometer (value between 0 and 1023) valUD = analogRead(potpinUD); valLR = map(valLR, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180) valUD = map(valUD, 0, 1023, 0, 180); myservoLR.write(valLR); // sets the servo position according to the scaled value myservoUD.write(valUD); delay(15); // waits for the servo to get there}