Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@cmoz
Created March 30, 2022 11:37
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 cmoz/0ea9d1b6d9456d32d8e397c92c8863d4 to your computer and use it in GitHub Desktop.
Save cmoz/0ea9d1b6d9456d32d8e397c92c8863d4 to your computer and use it in GitHub Desktop.
#include <Servo.h>
Servo servo1;
int flexpin = A0;
void setup()
{
Serial.begin(9600);
servo1.attach(A1);
}
void loop()
{
int flexposition;
int servoposition;
flexposition = analogRead(flexpin);
servoposition = map(flexposition, 600, 1000, 0, 180);
servoposition = constrain(servoposition, 0, 180);
servo1.write(servoposition);
Serial.print("sensor: ");
Serial.print(flexposition);
Serial.print(" servo: ");
Serial.println(servoposition);
delay(20);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment