8. Final Code¶
Servo- Flex code … for my final project
#include <Servo.h>
Servo myServo;
int flexValue;
int servoPosition;
const int flexPin = A0;
void setup()
{
myServo.attach(6);
Serial.begin(9600);
}
void loop()
{
flexValue = analogRead(flexPin);
servoPosition = map(flexValue, 450 , 1023 , 0, 125);
servoPosition = constrain(servoPosition, 0, 125);
Serial.println(flexValue);
// Serial.println(servoPosition);
myServo.write(servoPosition);
delay(100);
}