BY: www.emcu.eu Date: 08-12-2017 Ver. 1.0 Example for Servo Motor: MG996R This example was tested on NUCLEO-F401RE If you use a terminal emulator (9600,8,1) on your PC you also see the commands sends do RC motor.
Diff: main.cpp
- Revision:
- 0:b0c47a96f7cd
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Dec 08 11:15:39 2017 +0000 @@ -0,0 +1,124 @@ +/* + + BY: www.emcu.eu + Date: 08-12-2017 + Ver. 1.0 + Example for Servo Motor: MG996R + This example was tested on NUCLEO-F401RE + If you use a terminal emulator (9600,8,1) on your PC + you also see the commands sends do RC motor. + +--------------------------------------------------------------------------- + + Servo Motor: + MG996R - http://www.electronicoscaldas.com/datasheet/MG996R_Tower-Pro.pdf + + RED - + Vcc from 4,5 to 7,2V + BLACK - GND + ORANGE - PWM + + Duty - example: 1.9 (mS) + \ / + \/ + __ +__| |_____________ + ... 20mS...... + + For rotate to right use value 1 for Duty + For rotate to left use value 5 for Duty + + Vedere queste spiegazioni: + http://www.adrirobot.it/servotester/il_servomotore.htm + + + + NOTE: + + For rotate to Right (DESTRA) use this command: + Move(Right); + For rotate to Left (SINISTRA) use this command: + Move(Left); + + You also has the possibility to send a command like below: + Move(1.5): + +*/ + +#include "mbed.h" + +DigitalOut Drive(PA_10); + +#define PWMoff 20 // Waiting for end PWD +#define Right 1 // Move to Right -> DESTRA or DX +#define Left 5 // Move to LEFT <- SINISTRA or SX +#define DLY 1 + +void Move(double); + +double p=0; + + +int main() +{ +int n=0; + + printf("By: www.emcu.eu - Ver.1.0 \n\r"); + + printf("Rotate all to -> \n\r"); + // Sposta tutto a DX + for(n=0; n<20; n++) + Move(Right); + + wait(DLY); + + printf("Rotate all to <- \n\r"); + // Sposta tutto a SX + for(n=0; n<20; n++) + Move(Left); + + wait(DLY); + + printf("Move to 10 times to ->\n\r"); + for(n=0; n<10; n++) + Move(Right); + + wait(DLY); + + printf("END \n\r\n\r"); +} + + +void Move(double ON) +{ + +Drive=1; +wait_ms(ON); +Drive=0; +wait_ms(20); + +} + + + +/* + + // Sposta tutto a DX - Move all to RIGHT + for(n=0; n<200; n++) + Move(Right); + + wait(DLY); + + // Sposta tutto a SX - Move all to LEFT + for(n=0; n<200; n++) + Move(Left); + + wait(DLY); + +*/ + +/* + p=0.4; + myservo = p; + printf("P = %.2f \n\r", p); + wait(0.2); +*/