Andrea Coronado
/
Movimiento
Sensor de movimiento con bluetooth
Revision 0:0a405c6f350d, committed 2014-11-29
- Comitter:
- AndreaC
- Date:
- Sat Nov 29 20:17:52 2014 +0000
- Child:
- 1:b0059057fd23
- Commit message:
- Sensor de movimiento con bluetooth
Changed in this revision
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
movimiento.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Nov 29 20:17:52 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/movimiento.cpp Sat Nov 29 20:17:52 2014 +0000 @@ -0,0 +1,68 @@ +#include "mbed.h" +Serial pc(USBTX, USBRX); + +DigitalOut led = (PTC9); // LED que comprueba movimiento +DigitalIn pinLectura = (PTB0); // Pin de lectura del sensor INPUTPIN +Timer timer; +int begin, end; + +Serial bt(PTE0, PTE1); + +void f_SensorMovimiento() +{ + timer.start(); + while(timer <= 3) + { + led = 1; + } + timer.stop(); + timer.reset(); + + int val2 = pinLectura.read(); + + if(val2 == 0){ + f_SensorMovimiento(); + } + + else{ + led = 0; + return; + } +} + +int main() +{ + bt.baud(9600); + while(1) + { + if(bt.readable()) //establesco la conexion del bluethooth + { + char c = bt.getc(); //resive un caracter via bluethoth y lo asigna a una variable + //bt.printf("%c\n\r", c); + + if (c == 'm') + { + bt.printf("Iluminacion Automatica Activada\r"); + while(c != 'v'){ + + int val = pinLectura.read(); + + if (val == 0) + { + f_SensorMovimiento(); + } + if(bt.readable()) + { // reestablese la conexcion del bluethooth para solisitar o checar si se vumple la opcion para salir del while(c!=='v') + c = bt.getc(); //resive un caracter via bluethoth y lo asigna a una variable + led = 0; //apaga el led si se sale de este pedaso + } + } + bt.printf("Iluminacion Automatica Desactivada"); + } + if(c == 'p') + { + bt.printf("Prueba"); + } + } + } +} \ No newline at end of file