Created
July 12, 2018 08:05
-
-
Save elktros/52fb6f3f8614173b4ddf3275bb26adbf to your computer and use it in GitHub Desktop.
Code for controlling a Servo motor with Flex Sensor and Arduino.
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> | |
Servo myServo; | |
const int flexPin = A0; | |
void setup() | |
{ | |
myServo.attach(11); | |
} | |
void loop() | |
{ | |
int flexValue; | |
int servoPosition; | |
flexValue = analogRead(flexPin); | |
servoPosition = map(flexValue, 800, 900, 0, 180); | |
servoPosition = constrain(servoPosition, 0, 180); | |
myServo.write(servoPosition); | |
delay(20); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment