Skip to content

Instantly share code, notes, and snippets.

@elktros
Created July 12, 2018 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elktros/52fb6f3f8614173b4ddf3275bb26adbf to your computer and use it in GitHub Desktop.
Save elktros/52fb6f3f8614173b4ddf3275bb26adbf to your computer and use it in GitHub Desktop.
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