elbear_arduino_bsp/libraries/Servo/examples/Resist/Resist.ino

26 lines
874 B
C++

/*
"Resist"
This example demonstrates the servo drive movement
depending on the value on the potentiometer
*/
#include <Servo.h>
Servo servo; // create an Servo class instance to control the servo
// analog pin used to connect a potentiometer
int potpin = A0; // P1_5 for Start/Elsomik
int val; // variable for reading the analog output value
int pin = 8; // P1_9 for Start/Elsomik
void setup() {
servo.attach(pin); // connecting the servo drive to specified digital pin
}
void loop() {
val = analogRead(potpin); // reading the potentiometer value (value from 0 to 4096)
val = map(val, 0, 4096, 0, 180); // change scale for use with servo (value from 0 to 180)
servo.write(val); // setting the servo position according to the value
delay(15); // waiting for the servo to get there
}