ferney alberto beltran molina
/
00_LAB_COMMAND_BUZZER
lab de buzzer
main.cpp
- Committer:
- fabeltranm
- Date:
- 2019-02-27
- Revision:
- 4:8b31bf0ddab3
- Parent:
- 3:6aff6d7785e5
File content as of revision 4:8b31bf0ddab3:
#include "mbed.h" /***************************************************************************** generar un programa que controle por el puerto serial los tonos y el tiempo de buzzer . por medio de la comunicacion serial el comando es | | | | | INITCMD | tono | tiempo | | 0xff | 0x01- 0x05 | 0x00 - 0xb4 | para enviar los comandos usar el programa Coolterm http://freeware.the-meiers.org/ qFABELTRANM Ferney alberto beltran molina *****************************************************************************/ Serial command(USBTX, USBRX); PwmOut mybuzzer(PB_4); /*INGRESE LA CONFIGURACION DE LOS MOTORES*/ #define INITCMD 0xFF // d #define DO 130 #define RE 150 #define MI 160 #define FA 180 #define SO 200 uint8_t tono; // variable almacena la frecuencia del buzzer uint8_t tiempo; // varable almacena los tiempos del buzzer leer_datos() // definición de las funciones void setup_uart(); void buzzer_on(uint8_t tono, uint8_t tiempo); void leer_datos(); int main() { setup_uart(); //command.printf("inicio de programa"); while(1){ leer_datos(); buzzer_on(tono, tiempo); } } void setup_uart(){ command.baud(115200); } void leer_datos(){ while(command.getc()!= INITCMD); tono=command.getc(); tiempo=command.getc(); } void buzzer_on(uint8_t tono, uint8_t tm){ /* complementar el código necesario */ mybuzzer.write(0); switch(tono){ case 1: mybuzzer.period_us(DO);break; case 2: mybuzzer.period_us(RE);break; case 3: mybuzzer.period_us(MI);break; case 4: mybuzzer.period_us(FA);break; default:mybuzzer.period_us(SO); break; } mybuzzer.write(0.5); wait(tm); mybuzzer.write(0); }