Skip to content

Instantly share code, notes, and snippets.

@elktros
Created July 12, 2018 08:05
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Code for controlling a Servo motor with Flex Sensor and Arduino.
#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