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.
main.cpp
- Committer:
- fabeltranm
- Date:
- 2019-02-22
- Revision:
- 1:b473a0ad2b83
- Parent:
- 0:a9181441db9b
- Child:
- 2:fda902bed8c6
File content as of revision 1:b473a0ad2b83:
#include "mbed.h"
/*****************************************************************************
generar un programa que controle por el puerto serial el grado de 4 servo motores
por medio de la comunicacion serial donde el comando sea
| | | |
| init_commd | N_motor | N_grados |
| 0xff | 0x01- 0x04 | 0x00 - 0xb4 |
para enviar los comandos usar el programa Coolterm
*****************************************************************************/
Serial command(USBTX, USBRX);
PwmOut myservo1(PB_4);
/*INGRESE L A CONFIGURACION DE LOS MOTORES*/
// 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_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);
myservo1.pulsewidth_us(1000);
}
void leer_datos(){
while(command.getc()!= 0xff);
nm=command.getc();
ng=command.getc();
}
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);
}