Page 1 of 1

Servo-Test

Posted: Sat Dec 10, 2016 11:23 am
by André
#include <Servo.h>
Servo motorL;
Servo motorR;

void setup() {
motorL.attach(9);
motorR.attach(8);
}
void loop() {
drive(0, 170, 2000 );
stop();
delay(1000);
drive(1, 170, 2000 );
stop();
delay(1000);
}
/**
* direction: 0 oder 1
* speed: 0 - 180 eingeben
* time: angabe der zeit in millisec
*/
void drive(int direction, int speed, int time){

if(direction == 0 ){
motorL.write(180-speed);
motorR.write(speed);
}
if(direction == 1 ){
motorL.write(speed);
motorR.write(180-speed);
}
delay(time);

}
/**
* stop
*/
void stop(){
motorL.write(90);
motorR.write(90);
}