CERRADURA POR CÓDIGO QR

Dependencies:   mbed

Fork of serialrecibe1 by Gustavo Ramirez

ESTE ES EL CODIGO QR Y EL APLICATIVO ES UN PROGRAMA EN APP INVENTOR ADEMAS BAJE LOS CODIGOS EN APP INVENTOR PARA ANDROID /media/uploads/tony63/scanner1.aia

/media/uploads/tony63/scanner1.apk

/media/uploads/tony63/qrcode.png

/media/uploads/tony63/app1.png

Committer:
tony63
Date:
Fri Apr 15 06:44:37 2016 +0000
Revision:
1:b0f1a3022c5b
Parent:
0:9894ad6153eb
CERRADURA POR C?DIGO QR

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tony63 1:b0f1a3022c5b 1 //PROGRAMA PARA CERRADURA ELECTRICA POR CODIGO QR CADENA ENCRIPTADA POR BLUETHOO EN EL SERIAL Y ACTIVA CANTONERA
tony63 1:b0f1a3022c5b 2 //UTIL EN LECTURA DE CADENAS PARA APP INVENTOR (SCANNER1.APK)
tony63 0:9894ad6153eb 3 #include "mbed.h"
tony63 0:9894ad6153eb 4 #include "stdio.h"
tony63 0:9894ad6153eb 5 #include "string.h"
tony63 0:9894ad6153eb 6 DigitalOut LedVerde(LED2);
tony63 0:9894ad6153eb 7 DigitalOut LedRojo(LED1);
tony63 0:9894ad6153eb 8 DigitalOut LedAzul(LED3);
tony63 0:9894ad6153eb 9 Serial GSM(PTE0,PTE1); //puertos del FRDM para el modem
tony63 0:9894ad6153eb 10 Serial pc(USBTX,USBRX); //puertos del PC
tony63 1:b0f1a3022c5b 11 char buffer[10];// TAMAÑO DEL BUFER
tony63 0:9894ad6153eb 12 Timer t; //VALOR DEL TIEMPO
tony63 0:9894ad6153eb 13 int count;
tony63 0:9894ad6153eb 14 int i = 0;
tony63 0:9894ad6153eb 15 int c=0;
tony63 0:9894ad6153eb 16 char r[]="";
tony63 1:b0f1a3022c5b 17 char Qr[]="qmAIzQGtSK";
tony63 1:b0f1a3022c5b 18 int ret;
tony63 0:9894ad6153eb 19
tony63 0:9894ad6153eb 20 int readBuffer(char *buffer,int count) //esta funcion lee un bufer de datos
tony63 0:9894ad6153eb 21 {
tony63 0:9894ad6153eb 22 int i=0;
tony63 0:9894ad6153eb 23 t.start(); //CUENTA EL TIEMPO DE CONEXION E INICIA
tony63 0:9894ad6153eb 24 while(1) {
tony63 0:9894ad6153eb 25 while (GSM.readable()) {
tony63 0:9894ad6153eb 26 char c = GSM.getc();
tony63 1:b0f1a3022c5b 27 //if (c == '\r' || c == '\n') c = '$';//si se envia fin de linea o de caracxter inserta $
tony63 0:9894ad6153eb 28 buffer[i++] = c;//mete al bufer el caracter leido
tony63 0:9894ad6153eb 29 if(i > count)break;//sale del loop si ya detecto terminacion
tony63 0:9894ad6153eb 30 }
tony63 0:9894ad6153eb 31 if(i > count)break;
tony63 0:9894ad6153eb 32 if(t.read() > 1) { //MAS DE UN SEGUNDO DE ESPERA SE SALE Y REINICA EL RELOJ Y SE SALE
tony63 0:9894ad6153eb 33 t.stop();
tony63 0:9894ad6153eb 34 t.reset();
tony63 0:9894ad6153eb 35 break;
tony63 0:9894ad6153eb 36 }
tony63 0:9894ad6153eb 37 }
tony63 0:9894ad6153eb 38 return 0;
tony63 0:9894ad6153eb 39 }
tony63 0:9894ad6153eb 40
tony63 0:9894ad6153eb 41 void cleanBuffer(char *buffer, int count) //esta funcion limpia el bufer
tony63 0:9894ad6153eb 42 {
tony63 0:9894ad6153eb 43 for(int i=0; i < count; i++) {
tony63 0:9894ad6153eb 44 buffer[i] = '\0';
tony63 0:9894ad6153eb 45 }
tony63 0:9894ad6153eb 46 }
tony63 0:9894ad6153eb 47
tony63 0:9894ad6153eb 48
tony63 0:9894ad6153eb 49 int main(void)
tony63 0:9894ad6153eb 50 {
tony63 0:9894ad6153eb 51 LedVerde=1;
tony63 1:b0f1a3022c5b 52 LedRojo=0;
tony63 0:9894ad6153eb 53 LedAzul=1;
tony63 0:9894ad6153eb 54 LedVerde=1;
tony63 1:b0f1a3022c5b 55 //wait(2); //PRENDE EL LED VERDE POR 2 SEGUNDOS
tony63 1:b0f1a3022c5b 56 //LedRojo=1;
tony63 0:9894ad6153eb 57 GSM.baud(9600);
tony63 0:9894ad6153eb 58 GSM.format(8,Serial::None,1);
tony63 1:b0f1a3022c5b 59
tony63 0:9894ad6153eb 60 while(1){
tony63 0:9894ad6153eb 61 if (GSM.readable()) {
tony63 1:b0f1a3022c5b 62 readBuffer(buffer,10);
tony63 0:9894ad6153eb 63 pc.printf("buffer= %s\n\r ",buffer); //imprime el bufer
tony63 0:9894ad6153eb 64 pc.printf("buffer= %c %c\n\r ",buffer[0],buffer[1]);//imprime el cero y el uno
tony63 0:9894ad6153eb 65 if(buffer[0]=='O' && buffer[1]=='N'){LedAzul=0;} //PRENDE EL LED AZUL
tony63 0:9894ad6153eb 66 if(buffer[0]=='O' && buffer[1]=='F'){LedAzul=1;} //APAGA EL LED AZUL
tony63 0:9894ad6153eb 67 }
tony63 1:b0f1a3022c5b 68 ret=(strncmp(buffer, Qr, 10));
tony63 1:b0f1a3022c5b 69 if(ret==0){
tony63 1:b0f1a3022c5b 70 LedRojo=1;
tony63 1:b0f1a3022c5b 71 LedVerde=0;
tony63 1:b0f1a3022c5b 72 wait(5); //PRENDE EL LED VERDE POR 2 SEGUNDOS que es la cerradura electrica
tony63 1:b0f1a3022c5b 73 LedRojo=0;
tony63 1:b0f1a3022c5b 74 LedVerde=1;
tony63 1:b0f1a3022c5b 75 }
tony63 1:b0f1a3022c5b 76 cleanBuffer(buffer,10);
tony63 0:9894ad6153eb 77 }
tony63 0:9894ad6153eb 78 }