Diego Rivera
/
CerraduraBluetooth
Cerradura controlada por bluetooth
main.cpp@2:f9a8ccac21e4, 2016-02-25 (annotated)
- Committer:
- DiegoRivera
- Date:
- Thu Feb 25 18:13:38 2016 +0000
- Revision:
- 2:f9a8ccac21e4
- Parent:
- 1:1c8a6c4ddc4f
Final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DiegoRivera | 0:bc7b5ae725ef | 1 | #include "mbed.h" |
DiegoRivera | 0:bc7b5ae725ef | 2 | #include "Cerradura.h" |
DiegoRivera | 0:bc7b5ae725ef | 3 | |
DiegoRivera | 0:bc7b5ae725ef | 4 | //DigitalOut cerradura (D2); |
DiegoRivera | 2:f9a8ccac21e4 | 5 | //DigitalOut gnd(D2); |
DiegoRivera | 2:f9a8ccac21e4 | 6 | //DigitalOut vcc(D3); |
DiegoRivera | 2:f9a8ccac21e4 | 7 | //DigitalOut en(D4); |
DiegoRivera | 0:bc7b5ae725ef | 8 | |
DiegoRivera | 2:f9a8ccac21e4 | 9 | Serial bluetooth(PTE0, PTE1); |
DiegoRivera | 2:f9a8ccac21e4 | 10 | Cerradura cerradura(D2); //clase para abrir y crrar cerradura |
DiegoRivera | 2:f9a8ccac21e4 | 11 | Cerradura rojo(LED1); |
DiegoRivera | 2:f9a8ccac21e4 | 12 | Cerradura verde(LED2); |
DiegoRivera | 0:bc7b5ae725ef | 13 | |
DiegoRivera | 1:1c8a6c4ddc4f | 14 | void leer() //interrupcion rx serial |
DiegoRivera | 0:bc7b5ae725ef | 15 | { |
DiegoRivera | 1:1c8a6c4ddc4f | 16 | int in; |
DiegoRivera | 1:1c8a6c4ddc4f | 17 | bluetooth.scanf("%d", &in); |
DiegoRivera | 0:bc7b5ae725ef | 18 | if(in==1) |
DiegoRivera | 2:f9a8ccac21e4 | 19 | { |
DiegoRivera | 0:bc7b5ae725ef | 20 | cerradura.abrir(); |
DiegoRivera | 2:f9a8ccac21e4 | 21 | rojo.abrir(); |
DiegoRivera | 2:f9a8ccac21e4 | 22 | verde.cerrar(); |
DiegoRivera | 2:f9a8ccac21e4 | 23 | bluetooth.printf("1"); |
DiegoRivera | 2:f9a8ccac21e4 | 24 | } |
DiegoRivera | 0:bc7b5ae725ef | 25 | if(in==0) |
DiegoRivera | 2:f9a8ccac21e4 | 26 | { |
DiegoRivera | 0:bc7b5ae725ef | 27 | cerradura.cerrar(); |
DiegoRivera | 2:f9a8ccac21e4 | 28 | rojo.cerrar(); |
DiegoRivera | 2:f9a8ccac21e4 | 29 | verde.abrir(); |
DiegoRivera | 2:f9a8ccac21e4 | 30 | bluetooth.printf("0"); |
DiegoRivera | 2:f9a8ccac21e4 | 31 | } |
DiegoRivera | 0:bc7b5ae725ef | 32 | } |
DiegoRivera | 0:bc7b5ae725ef | 33 | |
DiegoRivera | 0:bc7b5ae725ef | 34 | int main() |
DiegoRivera | 0:bc7b5ae725ef | 35 | { |
DiegoRivera | 2:f9a8ccac21e4 | 36 | // gnd=0; |
DiegoRivera | 2:f9a8ccac21e4 | 37 | // vcc=1; |
DiegoRivera | 2:f9a8ccac21e4 | 38 | // en=1; |
DiegoRivera | 0:bc7b5ae725ef | 39 | bluetooth.baud(9600); |
DiegoRivera | 0:bc7b5ae725ef | 40 | bluetooth.format(8, SerialBase::None, 1); |
DiegoRivera | 0:bc7b5ae725ef | 41 | bluetooth.attach(&leer, Serial::RxIrq); |
DiegoRivera | 0:bc7b5ae725ef | 42 | while(1) |
DiegoRivera | 0:bc7b5ae725ef | 43 | { |
DiegoRivera | 0:bc7b5ae725ef | 44 | } |
DiegoRivera | 0:bc7b5ae725ef | 45 | } |