Created
March 30, 2022 11:37
-
-
Save cmoz/0ea9d1b6d9456d32d8e397c92c8863d4 to your computer and use it in GitHub Desktop.
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 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