Регулировка скорости вращения сервомотора slide

Регулировка скорости вращения сервомотора

Описание Регулировка скорости вращения сервомотора




Код программы:


// Sweep with speed control

#include Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 

int pos = 0;    // variable to store the servo position 
int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin 
 
void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
} 
 
void loop() 
{ 
     // scale it to use it with the servo (value between 0 and 180) 
 
  for(pos = 0; pos < 90; pos += val)  // goes from 0 degrees to 180 degrees 
  {    
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023) 
  val = map(val, 0, 1023, 1, 30);    // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(400);                       // waits 15ms for the servo to reach the position 
  } 
 
    for(pos = 60; pos < 180; pos += val)  // goes from 0 degrees to 180 degrees 
  {  
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023) 
  val = map(val, 0, 1023, 1, 30);    // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(700);                       // waits 15ms for the servo to reach the position 
  } 
 
  for(pos = 180; pos>=1; pos-= val)     // goes from 180 degrees to 0 degrees 
  {    
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023) 
  val = map(val, 0, 1023, 1, 30);    
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(400);                       // waits 15ms for the servo to reach the position 
  } 
 
  delay(2000);
} 


серво ардуино

Другие проекты