Vous êtes sur la page 1sur 2

PROGRAM

#include <Servo.h>
Servo servo1;
const int flexpin = 1;

Servo myservo;

// create servo object to control a servo

int potpin = 0;

// analog pin used to connect the potentiometer

int val;

// variable to read the value from the analog pin

void setup()
{
Serial.begin(9600);
servo1.attach(9);
myservo.attach(10);
}
void loop()
{
int flexposition;
int servoposition;
flexposition = analogRead(flexpin);

servoposition = map(flexposition, 600, 900, 0, 180);


servoposition = constrain(servoposition, 0, 60);
servo1.write(servoposition);
Serial.print("sensor: ");
Serial.print(flexposition);
Serial.print(" servo: ");
Serial.println(servoposition);
delay(20);
val = analogRead(potpin);

// wait 20ms between servo updates


// reads the value of the potentiometer (value between 0

and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)

myservo.write(val);

// sets the servo position according to the scaled value

delay(15);

// waits for the servo to get there

Vous aimerez peut-être aussi