I have modified my servo so that it can turn left and right continuously. But now I want it to halt inbetween. I use the mbed Servo function. What do I need to put in my program to get a '0', so no pulses, at pin p21?
Below my code. Where it states 'myServo=0.5;' it should turn of the PWM on p21 to enable the motor to stop rotating. I tried various possibilities for myServo here, but the motor doesn't stop because I removed the stop and the feedback to enable full swing rotation.
#include "mbed.h"
#include "Servo.h"
Servo myServo (p21);
/* myServo defines the setting of the Servo
myServo>0.55 the motor turns left fast
myServo<0.50 the motor turns right fast
at myServo=0.52 the motor turns left slow...
at myServo=0.515 the motor turns right slow...
*/
/* start with a turn with a fixed wait time of 3s
then continue endlessly with a random wait time between turns*/
int main() {
int i,j,k;
j=1;
k=1;
for (i=0 ; i<100 ; i++){
myServo = i/100.0;
wait (0.01);
}
myServo=0.5; /*here it should wait, not turn. How to shut of the pwm?*/
wait (3); /*wait 3s*/
for (i=100 ; i>0 ; i--){
myServo = i/100.0;
wait (0.01);
}
myServo=0.5; /*here it should wait, not turn. How to shut of the pwm?*/
wait (3); /*wait 3s*/
while (1) {
for (i=0 ; i<100 ; i++){
myServo = i/100.0;
wait (0.01);
}
myServo=0.5; /*here it should wait, not turn. How to shut of the pwm?*/
j=(rand()%10)+1; /*rand()%10 means any number between 0 and 10!*/
wait (j); /*random wait between 0 and 10s*/
for (i=100 ; i>0 ; i--){
myServo = i/100.0;
wait (0.01);
}
myServo=0.5; /*here it should wait, not turn. How to shut of the pwm?*/
k=(rand()%10)+1;
wait (k); /*random wait between 0 and 10s*/
}
}
I have modified my servo so that it can turn left and right continuously. But now I want it to halt inbetween. I use the mbed Servo function. What do I need to put in my program to get a '0', so no pulses, at pin p21?
Below my code. Where it states 'myServo=0.5;' it should turn of the PWM on p21 to enable the motor to stop rotating. I tried various possibilities for myServo here, but the motor doesn't stop because I removed the stop and the feedback to enable full swing rotation.
#include "mbed.h"
#include "Servo.h"
Servo myServo (p21);
/* myServo defines the setting of the Servo
myServo>0.55 the motor turns left fast
myServo<0.50 the motor turns right fast
at myServo=0.52 the motor turns left slow...
at myServo=0.515 the motor turns right slow...
*/
/* start with a turn with a fixed wait time of 3s
then continue endlessly with a random wait time between turns*/
int main() {
int i,j,k;
j=1;
k=1;
for (i=0 ; i<100 ; i++){
myServo = i/100.0;
wait (0.01);
}
myServo=0.5; /*here it should wait, not turn. How to shut of the pwm?*/
wait (3); /*wait 3s*/
for (i=100 ; i>0 ; i--){
myServo = i/100.0;
wait (0.01);
}
myServo=0.5; /*here it should wait, not turn. How to shut of the pwm?*/
wait (3); /*wait 3s*/
while (1) {
for (i=0 ; i<100 ; i++){
myServo = i/100.0;
wait (0.01);
}
myServo=0.5; /*here it should wait, not turn. How to shut of the pwm?*/
j=(rand()%10)+1; /*rand()%10 means any number between 0 and 10!*/
wait (j); /*random wait between 0 and 10s*/
for (i=100 ; i>0 ; i--){
myServo = i/100.0;
wait (0.01);
}
myServo=0.5; /*here it should wait, not turn. How to shut of the pwm?*/
k=(rand()%10)+1;
wait (k); /*random wait between 0 and 10s*/
}
}