Stap 3: De programma-Code
Copy/Paste deze schets in de Arduino IDE en uploaden naar je Arduino:
#include <Servo.h> Servo myservo; // create servo object int pot = 0; // analog pin used for pot (A0) int val; // value from analog pin int lastVal; // prevoius value long LastChange; void setup() { myservo.attach(9); // attaches the servo on pin 9 } void loop() { val = analogRead(pot); // reads pot 0 - 1023 val = map(val, 0, 1023, 1, 179); // scale it to servo 0 - 180 if (val < (lastVal-5) || val > (lastVal+5)) { myservo.write(val); // sets servo position delay(15); // waits for servo to get there LastChange = millis(); lastVal = val; } else if (millis() - LastChange > 500); { myservo.write(val); } }