Components and supplies
Pushbutton Switch, Push-Pull
HC-05 Bluetooth Module
Alphanumeric LCD, 16 x 2
Arduino UNO
Apps and platforms
Arduino IDE
Project description
Code
the good code
arduino
1 2 3#include <SoftwareSerial.h> //Librería que permite establecer comunicación serie en otros pin 4#include <LiquidCrystal.h> 5 6 7 8 9// made by Gibran Hernandez 10//supergxp@gmail.com 11 12 13 14 15 16 17 18 19//Aquí conectamos los pins RXD,TDX del módulo Bluetooth. 20SoftwareSerial modulo(10,11); //10 RX, 11 TX. 21LiquidCrystal lcd (5, 3, 7, 9, 8, 12); 22 23int green=4; 24String hola = ""; 25int botonaso=2; 26int boton = HIGH; 27int red=6; 28char cadena[255]; //Creamos un array de caracteres de 256 cposiciones 29int i=0; //Tamaño actual del array 30int columna =0; 31int renglon = 0; 32int length = 0; 33int estado = 0; 34int adios = 0; 35int guante = 0; 36byte resets[8]={ 37 0b00000, 38 0b00000, 39 0b00000, 40 0b00000, 41 0b00000, 42 0b00000, 43 0b00000, 44 0b00000 45}; 46 47String prueba = ""; 48void setup() 49{ 50 modulo.begin(9600); 51 Serial.begin(9600); 52 pinMode(green,OUTPUT); 53 pinMode(boton,INPUT); 54 pinMode(red,OUTPUT); 55 lcd.begin(16, 2); 56 lcd.createChar(4, resets); 57 58} 59 60void loop(){ 61 boton = digitalRead(botonaso); 62 63 64 65 //Cuando haya datos disponibles 66 if(modulo.available()) 67 { 68 69 70 Serial.print("estado ="); 71 Serial.println(estado); 72 73 /* Codigo debug */ 74 /* if(estado == 0) 75 { 76 digitalWrite(green,HIGH); 77 Serial.println("ENCENDIDO"); 78 79 estado = 1; 80 81 } else { 82 digitalWrite(green,LOW); 83 Serial.println("apagado"); 84 estado = 0; 85 }*/ 86 /* Fin Codigo debug */ 87 88 char dato=modulo.read(); //Guarda los datos carácter a carácter en la variable "dato" 89 Serial.println(dato); 90 91 cadena[i++]=toUpperCase(dato); //Vamos colocando cada carácter recibido en el array "cadena" 92 93 94 /* Codigo debug */ 95 Serial.println("Se ha pulsado una tecla"); 96 97 Serial.println(cadena); 98 99 prueba = cadena; 100 101 if(prueba.length() <= 15){ 102 Serial.println("chica"); 103 borra(); 104 lcd.home(); 105 lcd.print(prueba); 106 107 } 108 109 else if (prueba.length() > 15 && prueba.length() < 32){ 110 borra(); 111 Serial.println("mediana"); 112 lcd.setCursor(0,0); 113 lcd.print(prueba.substring(0,16)); 114 115 lcd.setCursor(0,1 ); 116 lcd.print(prueba.substring(16,32)); 117 } 118 119 120 121 122else if (prueba.length() > 31 && prueba.length() < 48){ 123 borra(); 124 hola= ""; 125Serial.println("grande"); 126 127 lcd.setCursor(0,0); 128 lcd.print(prueba.substring(0,16)); 129 130 lcd.setCursor(0,1 ); 131 lcd.print(prueba.substring(16,32)); 132 133 Serial.println(prueba.length()); 134 135 hola = hola + "grande"; 136} 137 138else if (prueba.length() > 47 && prueba.length() < 64){ 139 borra(); 140 hola= ""; 141Serial.println("muy grande"); 142 143 lcd.setCursor(0,0); 144 lcd.print(prueba.substring(0,16)); 145 146 lcd.setCursor(0,1 ); 147 lcd.print(prueba.substring(16,32)); 148 149 Serial.println(prueba.length()); 150 151 hola = hola + "muy grande"; 152} 153 154 155 156/* 157 if(izeof(cadena) < 15){ 158 borradisplay(); 159 lcd.home(); 160 lcd.print(cadena); 161 } 162 /* if (sizeof(cadena) > 15){ 163 lcd.setCursor(0,0); 164 lcd.print(substring(0,15, cadena)); 165 166 lcd.setCursor(0,1 ); 167 lcd.print(substring(16,sizeof(cadena)-1, cadena)); 168 } 169 else{ 170 lcd.print(cadena); 171 } 172 173 174 if(strstr (cadena,"GREEN ON") != 0) 175 { 176 digitalWrite(green,HIGH); 177 Serial.println("prende"); 178 } 179 else{ 180 digitalWrite(green,LOW); 181 Serial.println("apaga"); 182 183 } 184*/ 185/* 186 if(strstr (cadena,"BLUE ON") != 0) 187 { 188 digitalWrite(yellow,HIGH); 189 Serial.println("prende"); 190 191 clean(); 192 193 } 194 else{ 195 digitalWrite(yellow,LOW); 196 Serial.println("apaga"); 197 198 } 199 200 if(strstr (cadena,"CLEAN") != 0) 201 { 202 borradisplay(); 203 Serial.println("clean"); 204 205 clean(); 206 207 } 208 209 210 clean(); 211*/ 212 213 214 215 216/* if((prueba.length() != prueba.length() <= 15) || (prueba.length() != (prueba.length() > 15 && prueba.length() < 30)) && hola ==0){ 217 218clean(); 219 220 221 }*/} 222 223 else if(boton == LOW && hola == "grande"){ 224 Serial.println("boton presionado"); 225 lcd.setCursor(0,0); 226 lcd.print(prueba.substring(16,32)); 227 228 lcd.setCursor(0,1 ); 229 lcd.print(prueba.substring(32,48)); 230 hola = ""; 231 } 232 233 else if(boton == LOW && hola == "muy grande"){ 234 Serial.println("boton presionado"); 235 lcd.setCursor(0,0); 236 lcd.print(prueba.substring(32,48)); 237 238 lcd.setCursor(0,1 ); 239 lcd.print(prueba.substring(48,64)); 240 hola = ""; 241 } 242 243 244 else if(boton == LOW && hola == "gigante"){ 245 Serial.println("boton presionado"); 246 lcd.setCursor(0,0); 247 lcd.print(prueba.substring(32,48)); 248 249 lcd.setCursor(0,1 ); 250 lcd.print(prueba.substring(48,64)); 251 hola = "gigante 1"; 252 } 253 254 else if(boton == LOW && hola == "gigante 1"){ 255 Serial.println("boton presionado"); 256 lcd.setCursor(0,0); 257 lcd.print(prueba.substring(64,80)); 258 259 lcd.setCursor(0,1 ); 260 lcd.print(prueba.substring(80,96)); 261 hola = ""; 262 } 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 else if (hola == "") { 290 clean(); 291} 292 else if (prueba.length() >= 81) { 293 clean(); 294} 295 296 297 // Serial.print("hola = "); 298 //Serial.println(hola); 299 } 300 301//Limpia el array 302void clean() 303{ 304 for (int cl=0; cl<=i; cl++) 305 { 306 cadena[cl]=0; 307 prueba[cl]=0; 308 adios=0; 309 hola=""; 310 } 311 i=0; 312} 313void borra() 314{ 315 for(columna = 0; columna <= 16; columna++){ 316 lcd.setCursor(columna, 0); 317 lcd.write(4); 318 319 lcd.setCursor(columna, 1); 320 lcd.write(4); 321 322 }//for 323 Serial.print("hola = "); 324 Serial.println(hola); 325} 326 327void clean2() 328{ 329 for (int cl=0; cl<=i; cl++) 330 { 331 332 prueba[cl]=0; 333 adios=0; 334 } 335 i=0; 336}
the good code
arduino
1 2 3#include <SoftwareSerial.h> //Librería que permite establecer comunicación serie en otros pin 4#include <LiquidCrystal.h> 5 6 7 8 9// made by Gibran Hernandez 10//supergxp@gmail.com 11 12 13 14 15 16 17 18 19//Aquí conectamos los pins RXD,TDX del módulo Bluetooth. 20SoftwareSerial modulo(10,11); //10 RX, 11 TX. 21LiquidCrystal lcd (5, 3, 7, 9, 8, 12); 22 23int green=4; 24String hola = ""; 25int botonaso=2; 26int boton = HIGH; 27int red=6; 28char cadena[255]; //Creamos un array de caracteres de 256 cposiciones 29int i=0; //Tamaño actual del array 30int columna =0; 31int renglon = 0; 32int length = 0; 33int estado = 0; 34int adios = 0; 35int guante = 0; 36byte resets[8]={ 37 0b00000, 38 0b00000, 39 0b00000, 40 0b00000, 41 0b00000, 42 0b00000, 43 0b00000, 44 0b00000 45}; 46 47String prueba = ""; 48void setup() 49{ 50 modulo.begin(9600); 51 Serial.begin(9600); 52 pinMode(green,OUTPUT); 53 pinMode(boton,INPUT); 54 pinMode(red,OUTPUT); 55 lcd.begin(16, 2); 56 lcd.createChar(4, resets); 57 58} 59 60void loop(){ 61 boton = digitalRead(botonaso); 62 63 64 65 //Cuando haya datos disponibles 66 if(modulo.available()) 67 { 68 69 70 Serial.print("estado ="); 71 Serial.println(estado); 72 73 /* Codigo debug */ 74 /* if(estado == 0) 75 { 76 digitalWrite(green,HIGH); 77 Serial.println("ENCENDIDO"); 78 79 estado = 1; 80 81 } else { 82 digitalWrite(green,LOW); 83 Serial.println("apagado"); 84 estado = 0; 85 }*/ 86 /* Fin Codigo debug */ 87 88 char dato=modulo.read(); //Guarda los datos carácter a carácter en la variable "dato" 89 Serial.println(dato); 90 91 cadena[i++]=toUpperCase(dato); //Vamos colocando cada carácter recibido en el array "cadena" 92 93 94 /* Codigo debug */ 95 Serial.println("Se ha pulsado una tecla"); 96 97 Serial.println(cadena); 98 99 prueba = cadena; 100 101 if(prueba.length() <= 15){ 102 Serial.println("chica"); 103 borra(); 104 lcd.home(); 105 lcd.print(prueba); 106 107 } 108 109 else if (prueba.length() > 15 && prueba.length() < 32){ 110 borra(); 111 Serial.println("mediana"); 112 lcd.setCursor(0,0); 113 lcd.print(prueba.substring(0,16)); 114 115 lcd.setCursor(0,1 ); 116 lcd.print(prueba.substring(16,32)); 117 } 118 119 120 121 122else if (prueba.length() > 31 && prueba.length() < 48){ 123 borra(); 124 hola= ""; 125Serial.println("grande"); 126 127 lcd.setCursor(0,0); 128 lcd.print(prueba.substring(0,16)); 129 130 lcd.setCursor(0,1 ); 131 lcd.print(prueba.substring(16,32)); 132 133 Serial.println(prueba.length()); 134 135 hola = hola + "grande"; 136} 137 138else if (prueba.length() > 47 && prueba.length() < 64){ 139 borra(); 140 hola= ""; 141Serial.println("muy grande"); 142 143 lcd.setCursor(0,0); 144 lcd.print(prueba.substring(0,16)); 145 146 lcd.setCursor(0,1 ); 147 lcd.print(prueba.substring(16,32)); 148 149 Serial.println(prueba.length()); 150 151 hola = hola + "muy grande"; 152} 153 154 155 156/* 157 if(izeof(cadena) < 15){ 158 borradisplay(); 159 lcd.home(); 160 lcd.print(cadena); 161 } 162 /* if (sizeof(cadena) > 15){ 163 lcd.setCursor(0,0); 164 lcd.print(substring(0,15, cadena)); 165 166 lcd.setCursor(0,1 ); 167 lcd.print(substring(16,sizeof(cadena)-1, cadena)); 168 } 169 else{ 170 lcd.print(cadena); 171 } 172 173 174 if(strstr (cadena,"GREEN ON") != 0) 175 { 176 digitalWrite(green,HIGH); 177 Serial.println("prende"); 178 } 179 else{ 180 digitalWrite(green,LOW); 181 Serial.println("apaga"); 182 183 } 184*/ 185/* 186 if(strstr (cadena,"BLUE ON") != 0) 187 { 188 digitalWrite(yellow,HIGH); 189 Serial.println("prende"); 190 191 clean(); 192 193 } 194 else{ 195 digitalWrite(yellow,LOW); 196 Serial.println("apaga"); 197 198 } 199 200 if(strstr (cadena,"CLEAN") != 0) 201 { 202 borradisplay(); 203 Serial.println("clean"); 204 205 clean(); 206 207 } 208 209 210 clean(); 211*/ 212 213 214 215 216/* if((prueba.length() != prueba.length() <= 15) || (prueba.length() != (prueba.length() > 15 && prueba.length() < 30)) && hola ==0){ 217 218clean(); 219 220 221 }*/} 222 223 else if(boton == LOW && hola == "grande"){ 224 Serial.println("boton presionado"); 225 lcd.setCursor(0,0); 226 lcd.print(prueba.substring(16,32)); 227 228 lcd.setCursor(0,1 ); 229 lcd.print(prueba.substring(32,48)); 230 hola = ""; 231 } 232 233 else if(boton == LOW && hola == "muy grande"){ 234 Serial.println("boton presionado"); 235 lcd.setCursor(0,0); 236 lcd.print(prueba.substring(32,48)); 237 238 lcd.setCursor(0,1 ); 239 lcd.print(prueba.substring(48,64)); 240 hola = ""; 241 } 242 243 244 else if(boton == LOW && hola == "gigante"){ 245 Serial.println("boton presionado"); 246 lcd.setCursor(0,0); 247 lcd.print(prueba.substring(32,48)); 248 249 lcd.setCursor(0,1 ); 250 lcd.print(prueba.substring(48,64)); 251 hola = "gigante 1"; 252 } 253 254 else if(boton == LOW && hola == "gigante 1"){ 255 Serial.println("boton presionado"); 256 lcd.setCursor(0,0); 257 lcd.print(prueba.substring(64,80)); 258 259 lcd.setCursor(0,1 ); 260 lcd.print(prueba.substring(80,96)); 261 hola = ""; 262 } 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 else if (hola == "") { 290 clean(); 291} 292 else if (prueba.length() >= 81) { 293 clean(); 294} 295 296 297 // Serial.print("hola = "); 298 //Serial.println(hola); 299 } 300 301//Limpia el array 302void clean() 303{ 304 for (int cl=0; cl<=i; cl++) 305 { 306 cadena[cl]=0; 307 prueba[cl]=0; 308 adios=0; 309 hola=""; 310 } 311 i=0; 312} 313void borra() 314{ 315 for(columna = 0; columna <= 16; columna++){ 316 lcd.setCursor(columna, 0); 317 lcd.write(4); 318 319 lcd.setCursor(columna, 1); 320 lcd.write(4); 321 322 }//for 323 Serial.print("hola = "); 324 Serial.println(hola); 325} 326 327void clean2() 328{ 329 for (int cl=0; cl<=i; cl++) 330 { 331 332 prueba[cl]=0; 333 adios=0; 334 } 335 i=0; 336}
Downloadable files
the good sketch
the good sketch
Comments
Only logged in users can leave comments
GiHOxp
0 Followers
•0 Projects
Table of contents
Intro
2
0