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
00001 #include "mbed.h" 00002 #include "TextLCD.h" 00003 00004 Serial slave1(PA_11, PA_12); 00005 Serial slave2(PA_15, PB_7); 00006 Serial bluetooth(PA_2, PA_3); 00007 00008 AnalogIn boton_LCD(A0); 00009 DigitalIn mov(D2); 00010 00011 Ticker lcdTimer, movTimer, sendTimer,alarmDatos; 00012 00013 TextLCD lcd = TextLCD(D8, D9, D4, D5, D6, D7, TextLCD::LCD16x2); 00014 00015 float key_value[6] = {0.05, 0.25, 0.45, 0.70, 0.85, 0.95}; 00016 int NUM_KEYS = 6; 00017 float key_in; 00018 int key = -1; 00019 int x = 0; 00020 char caracterActual = 'Z'; 00021 char password[8] = "AAAA"; 00022 char enterPassword [8]; 00023 int alarm = 0; 00024 00025 00026 int get_boton(float input); 00027 void lcd_control(); 00028 int get_movimiento(); 00029 void sendData(); //Ver como se hace y el readData 00030 00031 00032 void sendData(){ 00033 char bufferSlave1[64]; 00034 char bufferSlave2[64]; 00035 char bufferTotal[128]; 00036 00037 if(slave1.readable()){ 00038 slave1.gets(bufferSlave1,64); 00039 } 00040 if(slave2.readable()){ 00041 slave2.gets(bufferSlave2,64); 00042 } 00043 strncpy(bufferTotal, bufferSlave1, sizeof(bufferSlave1)); 00044 strncat(bufferTotal, bufferSlave2,sizeof(bufferSlave2)); 00045 00046 wait(0.2f); 00047 if(bluetooth.writeable()){ 00048 bluetooth.printf("%s",bufferTotal); 00049 } 00050 } 00051 00052 void sendAlarm(){ 00053 if(slave1.writeable()){ 00054 if(alarm == 1){ 00055 slave1.putc('A'); 00056 wait(0.2); 00057 if(mov.read() == 1){ 00058 slave1.putc('3'); 00059 } 00060 }else if(alarm == 0){ 00061 slave1.putc('N'); 00062 } 00063 } 00064 } 00065 00066 int get_boton(float input){ //Metodo para obtener el boton pulsado en función del valor 00067 00068 int k; 00069 if (input > key_value[5]) k = -1; //Error en la lectura 00070 00071 else { 00072 for (k=0; k<NUM_KEYS; k++){ 00073 if(input < key_value[k]) return k; 00074 } 00075 } 00076 return k; 00077 } 00078 00079 void lcd_control(){ 00080 int i; 00081 wait(0.2); 00082 key_in = boton_LCD.read(); 00083 key = get_boton(key_in); 00084 00085 lcd.locate(x,1); 00086 00087 if( key == 0){ //Tecla rigth 00088 enterPassword[x] = caracterActual; 00089 x++; 00090 if(x > 15) x=15; 00091 lcd.locate(x,1); 00092 caracterActual = 'A'; 00093 lcd.printf("%c",caracterActual); 00094 00095 } 00096 if ( key == 1){ //Tecla up 00097 caracterActual++; 00098 if(caracterActual > 'Z') caracterActual = 'A'; 00099 //pc.printf(caracterActual); 00100 lcd.printf("%c",caracterActual); 00101 } 00102 if(key == 2) { //Tecla down 00103 caracterActual--; 00104 if(caracterActual < 'A') caracterActual = 'Z'; 00105 //pc.printf(caracterActual); 00106 lcd.printf("%c",caracterActual); 00107 } 00108 if(key == 3) { //Tecla left 00109 x--; 00110 if (x<0) x = 0; 00111 caracterActual = 'Z'; 00112 } 00113 if(key == 5){ //Tecla select 00114 enterPassword[x] = caracterActual; 00115 x = 0; 00116 00117 if(alarm == 0){ 00118 if(strcmp(password,enterPassword) == 0){ 00119 alarm = 1; 00120 lcd.cls(); 00121 lcd.locate(0,0); 00122 lcd.printf("Alarma Activada"); 00123 lcd.locate(0,1); 00124 }else{ 00125 lcd.cls(); 00126 lcd.locate(0,0); 00127 lcd.printf("Pass incorrect"); 00128 lcd.locate(0,1); 00129 } 00130 }else{ 00131 if(strcmp(password,enterPassword) == 0){ 00132 alarm = 0; 00133 lcd.cls(); 00134 lcd.locate(0,0); 00135 lcd.printf("Alarma Desact"); 00136 lcd.locate(0,1); 00137 }else{ 00138 lcd.cls(); 00139 lcd.locate(0,0); 00140 lcd.printf("Pass incorrect"); 00141 lcd.locate(0,1); 00142 } 00143 } 00144 for(i=0; i<8; i++){ 00145 enterPassword[i] = (char)0; 00146 } 00147 } 00148 } 00149 00150 int main(){ 00151 lcd.locate(0,0); 00152 lcd.printf("Enter password"); 00153 float movimiento; 00154 while(1){ 00155 lcdTimer.attach(&lcd_control,0.5f); 00156 sendTimer.attach(&sendData, 1.0f); 00157 alarmDatos.attach(&sendAlarm, 0.5f); 00158 wait(1.0f); 00159 } 00160 }
Generated on Tue Aug 22 2023 12:20:07 by
1.7.2