Controlador de drecciones de leds mediante el modulo Bluetooth HC-05
Dependencies: mbed
main.cpp@0:fc595d9f5765, 2019-05-31 (annotated)
- Committer:
- Narcia
- Date:
- Fri May 31 02:25:29 2019 +0000
- Revision:
- 0:fc595d9f5765
Controlador de direcciones de leds mediante la implementacion del modulo Bluetooth HC-05
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Narcia | 0:fc595d9f5765 | 1 | /* ########################################################################### |
Narcia | 0:fc595d9f5765 | 2 | ** Archivo : main.c |
Narcia | 0:fc595d9f5765 | 3 | ** Proyecto : FRDM-KL46Z_Proyecto_Implementacion_Bluetooth |
Narcia | 0:fc595d9f5765 | 4 | ** Procesador : MKL46Z256VLL4 |
Narcia | 0:fc595d9f5765 | 5 | ** Herramienta : Mbed |
Narcia | 0:fc595d9f5765 | 6 | ** Version : Driver 01.01 |
Narcia | 0:fc595d9f5765 | 7 | ** Compilador : GNU C Compiler |
Narcia | 0:fc595d9f5765 | 8 | ** Fecha/Hora : 22-05-2019, 23:57, # CodeGen: 0 |
Narcia | 0:fc595d9f5765 | 9 | ** Descripción : |
Narcia | 0:fc595d9f5765 | 10 | ** Este proyecto, mediante la implementacion del modulo Bluetooth |
Narcia | 0:fc595d9f5765 | 11 | ** HC-05 tiene la finalidad de, desde una aplicacion serial Bluetooth |
Narcia | 0:fc595d9f5765 | 12 | ** en cualquier smartphone, poder controlar las secuencias en que |
Narcia | 0:fc595d9f5765 | 13 | ** se desplaza una tira de leds implementada con leds individuales, |
Narcia | 0:fc595d9f5765 | 14 | ** ademas de la funcion on/off, a futuro se piensa desarrollar este |
Narcia | 0:fc595d9f5765 | 15 | ** proyecto con la imlementacion de leds inteligentes y sensores de |
Narcia | 0:fc595d9f5765 | 16 | ** proximidad cuyo proposito sea representar a grandes razgos la tecnología |
Narcia | 0:fc595d9f5765 | 17 | ** self-drive o self-lightning de los automoviles de mayor gama alta en |
Narcia | 0:fc595d9f5765 | 18 | ** la actualidad. |
Narcia | 0:fc595d9f5765 | 19 | ** Componentes : GPIO, Bluetooth HC-05, Serial, BusOut, Smartphone. |
Narcia | 0:fc595d9f5765 | 20 | ** Configuraciones : Includes, Serial y Drivers externos |
Narcia | 0:fc595d9f5765 | 21 | ** Autores : Mendoza Narcia Erick Daniel |
Narcia | 0:fc595d9f5765 | 22 | ** ATEAM Development Group: |
Narcia | 0:fc595d9f5765 | 23 | ** - Antulio Morgado Valle |
Narcia | 0:fc595d9f5765 | 24 | ** |
Narcia | 0:fc595d9f5765 | 25 | ** Versión : Beta |
Narcia | 0:fc595d9f5765 | 26 | ** Revisión : A |
Narcia | 0:fc595d9f5765 | 27 | ** Release : 0 |
Narcia | 0:fc595d9f5765 | 28 | ** Bugs & Fixes : |
Narcia | 0:fc595d9f5765 | 29 | ** Date : 01/08/2019 (aproximacion) |
Narcia | 0:fc595d9f5765 | 30 | ** Implementacion de leds inteligentes y sensores de proximidad |
Narcia | 0:fc595d9f5765 | 31 | ** |
Narcia | 0:fc595d9f5765 | 32 | * ###########################################################################/ |
Narcia | 0:fc595d9f5765 | 33 | /* |
Narcia | 0:fc595d9f5765 | 34 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
Narcia | 0:fc595d9f5765 | 35 | : Includes |
Narcia | 0:fc595d9f5765 | 36 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
Narcia | 0:fc595d9f5765 | 37 | */ |
Narcia | 0:fc595d9f5765 | 38 | #include "mbed.h" |
Narcia | 0:fc595d9f5765 | 39 | #include "Serial.h" |
Narcia | 0:fc595d9f5765 | 40 | /* |
Narcia | 0:fc595d9f5765 | 41 | :............................................................................... |
Narcia | 0:fc595d9f5765 | 42 | : Definiciones |
Narcia | 0:fc595d9f5765 | 43 | :............................................................................... |
Narcia | 0:fc595d9f5765 | 44 | */ |
Narcia | 0:fc595d9f5765 | 45 | /* |
Narcia | 0:fc595d9f5765 | 46 | +------------------------------------------------------------------------------- |
Narcia | 0:fc595d9f5765 | 47 | | Configuración de Puertos |
Narcia | 0:fc595d9f5765 | 48 | +------------------------------------------------------------------------------- |
Narcia | 0:fc595d9f5765 | 49 | */ |
Narcia | 0:fc595d9f5765 | 50 | DigitalOut gpo(D0); |
Narcia | 0:fc595d9f5765 | 51 | DigitalOut led(LED_RED); |
Narcia | 0:fc595d9f5765 | 52 | Serial Bluetooth(PTE0, PTE1); //establecemos los pines para la comunicacion serial |
Narcia | 0:fc595d9f5765 | 53 | //de la tarjeta con el bluetooth, PTE0 como RX y PTE1 como TX |
Narcia | 0:fc595d9f5765 | 54 | BusOut SECUENCIAS(PTE23, PTE22, PTE21, PTE20, PTE19, PTE18, PTE17, PTE16);//de estos |
Narcia | 0:fc595d9f5765 | 55 | //pines se conectaran los leds cuyas direcciones de iluminacion |
Narcia | 0:fc595d9f5765 | 56 | //podran ser controlados por la aplicacion de smartphone |
Narcia | 0:fc595d9f5765 | 57 | /* |
Narcia | 0:fc595d9f5765 | 58 | +------------------------------------------------------------------------------- |
Narcia | 0:fc595d9f5765 | 59 | | Variables Globales de Usuario |
Narcia | 0:fc595d9f5765 | 60 | +------------------------------------------------------------------------------- |
Narcia | 0:fc595d9f5765 | 61 | */ |
Narcia | 0:fc595d9f5765 | 62 | char DATO; //variable para almacenar caracter recibido desde el smartphone |
Narcia | 0:fc595d9f5765 | 63 | int16_t i=0; //variable auxiliar contador |
Narcia | 0:fc595d9f5765 | 64 | int32_t NSec=33; //variable auxiliar para el numero de secuencias de los vectores |
Narcia | 0:fc595d9f5765 | 65 | int32_t NSec2=160; //variable auxiliar para el numero de secuencias de los vectores |
Narcia | 0:fc595d9f5765 | 66 | /* |
Narcia | 0:fc595d9f5765 | 67 | |
Narcia | 0:fc595d9f5765 | 68 | /* |
Narcia | 0:fc595d9f5765 | 69 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Narcia | 0:fc595d9f5765 | 70 | | Definición de Funciones Prototipo y Rutinas de los Vectores |
Narcia | 0:fc595d9f5765 | 71 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Narcia | 0:fc595d9f5765 | 72 | */ |
Narcia | 0:fc595d9f5765 | 73 | uint8_t SHOW6[]={0xFF}; |
Narcia | 0:fc595d9f5765 | 74 | uint8_t SHOW5[]={0x55,0x55,0x55,0x55,0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,0xAA,0xAA,0xAA,0xAA, |
Narcia | 0:fc595d9f5765 | 75 | 0x55,0x55,0x55,0x55,0xAA,0xAA,0xAA,0xAA,0x55,0x55,0x55,0x55,0xAA,0xAA,0xAA,0xAA}; |
Narcia | 0:fc595d9f5765 | 76 | uint8_t SHOW4[]={0x81,0x81,0x42,0x42,0x24,0x24,0x18,0x18,0x81,0x81,0x42,0x42,0x24,0x24,0x18,0x18, |
Narcia | 0:fc595d9f5765 | 77 | 0x81,0x81,0x42,0x42,0x24,0x24,0x18,0x18,0x81,0x81,0x42,0x42,0x24,0x24,0x18,0x18}; |
Narcia | 0:fc595d9f5765 | 78 | uint8_t SHOW3[]={0x18,0x18,0x24,0x24,0x42,0x42,0x81,0x81,0x18,0x18,0x24,0x24,0x42,0x42,0x81,0x81, |
Narcia | 0:fc595d9f5765 | 79 | 0x18,0x18,0x24,0x24,0x42,0x42,0x81,0x81,0x18,0x18,0x24,0x24,0x42,0x42,0x81,0x81}; |
Narcia | 0:fc595d9f5765 | 80 | uint8_t SHOW2[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80, |
Narcia | 0:fc595d9f5765 | 81 | 0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; |
Narcia | 0:fc595d9f5765 | 82 | uint8_t SHOW1[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01, |
Narcia | 0:fc595d9f5765 | 83 | 0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; |
Narcia | 0:fc595d9f5765 | 84 | uint8_t SHOW0[]={0x00}; |
Narcia | 0:fc595d9f5765 | 85 | |
Narcia | 0:fc595d9f5765 | 86 | /* |
Narcia | 0:fc595d9f5765 | 87 | #=============================================================================== |
Narcia | 0:fc595d9f5765 | 88 | | |
Narcia | 0:fc595d9f5765 | 89 | | P R O G R A M A P R I N C I P A L |
Narcia | 0:fc595d9f5765 | 90 | | |
Narcia | 0:fc595d9f5765 | 91 | #=============================================================================== |
Narcia | 0:fc595d9f5765 | 92 | */ |
Narcia | 0:fc595d9f5765 | 93 | |
Narcia | 0:fc595d9f5765 | 94 | int main (){ |
Narcia | 0:fc595d9f5765 | 95 | Bluetooth.baud(9600); //velocidad de baudios a la cual la tarjeta se conectara al modulo |
Narcia | 0:fc595d9f5765 | 96 | //Bluetooth HC-05 |
Narcia | 0:fc595d9f5765 | 97 | while(1){ //loop |
Narcia | 0:fc595d9f5765 | 98 | if(Bluetooth.readable()) // Si el modulo bluetooth esta disponible y hay informacion |
Narcia | 0:fc595d9f5765 | 99 | //disponible para que este reciba |
Narcia | 0:fc595d9f5765 | 100 | { |
Narcia | 0:fc595d9f5765 | 101 | DATO=Bluetooth.getc(); //almacenara en esta variable el caracter que se recibio |
Narcia | 0:fc595d9f5765 | 102 | //desde el modulo |
Narcia | 0:fc595d9f5765 | 103 | i=0; |
Narcia | 0:fc595d9f5765 | 104 | if(DATO=='1') //Si el dato recibido es 1, ejecuta un vector que representa una |
Narcia | 0:fc595d9f5765 | 105 | //forma de mostrar la iluminacion de la tira de leds, lo mismo |
Narcia | 0:fc595d9f5765 | 106 | //en los demas casos con diferentes formas y secuencias de encendido |
Narcia | 0:fc595d9f5765 | 107 | //a menos que se indique la accion |
Narcia | 0:fc595d9f5765 | 108 | { |
Narcia | 0:fc595d9f5765 | 109 | for(i=0;i<NSec;i++) |
Narcia | 0:fc595d9f5765 | 110 | { |
Narcia | 0:fc595d9f5765 | 111 | SECUENCIAS=SHOW1[i]; |
Narcia | 0:fc595d9f5765 | 112 | wait_ms(70); |
Narcia | 0:fc595d9f5765 | 113 | } |
Narcia | 0:fc595d9f5765 | 114 | } |
Narcia | 0:fc595d9f5765 | 115 | if(DATO=='2') |
Narcia | 0:fc595d9f5765 | 116 | { |
Narcia | 0:fc595d9f5765 | 117 | for(i=0;i<NSec;i++) |
Narcia | 0:fc595d9f5765 | 118 | { |
Narcia | 0:fc595d9f5765 | 119 | SECUENCIAS=SHOW2[i]; |
Narcia | 0:fc595d9f5765 | 120 | wait_ms(70); |
Narcia | 0:fc595d9f5765 | 121 | } |
Narcia | 0:fc595d9f5765 | 122 | } |
Narcia | 0:fc595d9f5765 | 123 | if(DATO=='3') |
Narcia | 0:fc595d9f5765 | 124 | { |
Narcia | 0:fc595d9f5765 | 125 | for(i=0;i<NSec;i++) |
Narcia | 0:fc595d9f5765 | 126 | { |
Narcia | 0:fc595d9f5765 | 127 | SECUENCIAS=SHOW3[i]; |
Narcia | 0:fc595d9f5765 | 128 | wait_ms(70); |
Narcia | 0:fc595d9f5765 | 129 | } |
Narcia | 0:fc595d9f5765 | 130 | } |
Narcia | 0:fc595d9f5765 | 131 | if(DATO=='4') |
Narcia | 0:fc595d9f5765 | 132 | { |
Narcia | 0:fc595d9f5765 | 133 | for(i=0;i<NSec;i++) |
Narcia | 0:fc595d9f5765 | 134 | { |
Narcia | 0:fc595d9f5765 | 135 | SECUENCIAS=SHOW4[i]; |
Narcia | 0:fc595d9f5765 | 136 | wait_ms(70); |
Narcia | 0:fc595d9f5765 | 137 | } |
Narcia | 0:fc595d9f5765 | 138 | } |
Narcia | 0:fc595d9f5765 | 139 | if(DATO=='5') |
Narcia | 0:fc595d9f5765 | 140 | { |
Narcia | 0:fc595d9f5765 | 141 | for(i=0;i<NSec;i++) |
Narcia | 0:fc595d9f5765 | 142 | { |
Narcia | 0:fc595d9f5765 | 143 | SECUENCIAS=SHOW5[i]; |
Narcia | 0:fc595d9f5765 | 144 | wait_ms(70); |
Narcia | 0:fc595d9f5765 | 145 | } |
Narcia | 0:fc595d9f5765 | 146 | } |
Narcia | 0:fc595d9f5765 | 147 | if(DATO=='6') |
Narcia | 0:fc595d9f5765 | 148 | SECUENCIAS=SHOW6[i];//leds On |
Narcia | 0:fc595d9f5765 | 149 | if(DATO=='7') |
Narcia | 0:fc595d9f5765 | 150 | { |
Narcia | 0:fc595d9f5765 | 151 | for(i=0;i<NSec2;i++) |
Narcia | 0:fc595d9f5765 | 152 | { |
Narcia | 0:fc595d9f5765 | 153 | SECUENCIAS=SHOW5[i]; |
Narcia | 0:fc595d9f5765 | 154 | wait_ms(70); |
Narcia | 0:fc595d9f5765 | 155 | } |
Narcia | 0:fc595d9f5765 | 156 | } |
Narcia | 0:fc595d9f5765 | 157 | if(DATO=='0') |
Narcia | 0:fc595d9f5765 | 158 | SECUENCIAS=SHOW0[i]; //leds Off |
Narcia | 0:fc595d9f5765 | 159 | } |
Narcia | 0:fc595d9f5765 | 160 | } |
Narcia | 0:fc595d9f5765 | 161 | } |
Narcia | 0:fc595d9f5765 | 162 | /* END main */ |
Narcia | 0:fc595d9f5765 | 163 | |
Narcia | 0:fc595d9f5765 | 164 | /* |
Narcia | 0:fc595d9f5765 | 165 | |
Narcia | 0:fc595d9f5765 | 166 | /* END Program */ |
Narcia | 0:fc595d9f5765 | 167 | |
Narcia | 0:fc595d9f5765 | 168 | /* END Mbed */ |