Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 1:b473a0ad2b83
- Parent:
- 0:a9181441db9b
- Child:
- 2:fda902bed8c6
--- a/main.cpp Fri Feb 22 12:53:42 2019 +0000
+++ b/main.cpp Fri Feb 22 13:10:24 2019 +0000
@@ -18,35 +18,55 @@
-// definicion de las variables globales
+// definición de las variables globales
uint8_t nm; // almacena el número de motor
uint8_t ng; // almacena los grados que se mueve el motor
void setup_uart();
-void setup_motor();
-void mover_servo();
-
+void setup_servo();
+void mover_servo(uint8_t motor, uint8_t gradss);
+void leer_datos();
int main() {
-
+
+ setup_uart();
+ setup_servo();
+ while(1){
+ leer_datos();
+ mover_servo(nm, ng);
+}
+}
+
+
+
+void setup_uart(){
+ command.baud(115200);
+}
+
+void setup_servo(){
myservo1.period_ms(20);
- int cw=1;
- int dpulse=1000;
- myservo1.pulsewidth_us(dpulse);
+ myservo1.pulsewidth_us(1000);
+}
+
+void leer_datos(){
+ while(command.getc()!= 0xff);
+ nm=command.getc();
+ ng=command.getc();
- while(1) {
+}
+
+
+
+void mover_servo(uint8_t motor, uint8_t grados){
+
+/*
+complementar el códogo necesarios
+tip: deben pasar grados a microsegundo
+
+*/
+ uint32_t dpulse=0;
myservo1.pulsewidth_us(dpulse);
- wait(0.5);
- if (cw){
- dpulse+=100;
- if (dpulse==2500)
- cw=0;
- }else{
- dpulse-=100;
- if (dpulse==100)
- cw=1;
- }
+
}
-}