Created
November 16, 2018 00:01
-
-
Save natendaben/49e1da58e5809ae97cb08823a9ae989c to your computer and use it in GitHub Desktop.
Servo Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Servo.h> | |
//make instance of servo object | |
Servo mike; | |
void setup() { | |
// put your setup code here, to run once: | |
//attach servo motor | |
//works with any digital pin | |
mike.attach(9); | |
} | |
void loop() { | |
int sensor = analogRead(A0); | |
//servo.Write() takes values between 0-180 | |
int angle = map(sensor, 0, 1023, 0, 180); | |
// put your main code here, to run repeatedly: | |
mike.write(angle); | |
//to fix jitter, add a delay to write to servo less frequently | |
//delay(20); | |
//millis() counts milliseconds since program started | |
if(millis()%20<2) | |
{ | |
//functionally the same as delay(20) but doesn't delay the rest of your code | |
mike.write(angle); //takes value between 0-180 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment