Created
April 12, 2018 04:23
-
-
Save kmicheli/e3862a860ce5f24083246f1166971b9c to your computer and use it in GitHub Desktop.
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> | |
//creates an instance of the servo object to control a servo | |
Servo myServo; | |
void setup() { | |
//initialize serial communications | |
Serial.begin(9600); | |
//attaches the servo on pin 2 to the servo object | |
myServo.attach(3); | |
} | |
void loop() | |
{ | |
//read the analog input | |
int sensorVal = analogRead(A0); | |
//print it | |
Serial.println(sensorVal); | |
//new int called angle | |
//sensor range is 0 to 1023 since it is a potentiometer | |
int angle = map(sensorVal, 0, 1023, 0, 180); | |
//move the servo using the angle from the sensor: | |
myServo.write(angle); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment