
irrigation system for the ST Nucleo boards
Diff: Keepad.cpp
- Revision:
- 4:9e223db481da
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Keepad.cpp Sat Apr 18 21:06:58 2015 +0000 @@ -0,0 +1,114 @@ +#include "mbed.h" +#include "Keepad.h" +#include "LCDs.h" + +DigitalIn bi1(PC_8); +DigitalIn bi2(PC_6); +DigitalIn bi3(PC_5); +DigitalIn bi4(PB_1); +DigitalOut bo1(PA_12); +DigitalOut bo2(PA_11); +DigitalOut bo3(PB_12); +DigitalOut bo4(PB_11); + +int g = 0; + +Keepad::Keepad(){} + +int Keepad::keypad() +{ + g=7; + LCDs t2; + //t2.lcdcmd(0x01); + wait_ms(10); + g=5; + int i=0; + + bo1 = 1; + bo2 = 0; + bo3 = 0; + bo4 = 0; + keypadIn(); + if(g!=5) + { + t2.putString("A"); + i=10+g; + wait_ms(500); + return(i); + } + + bo1 = 0; + bo2 = 1; + bo3 = 0; + bo4 = 0; + keypadIn(); + if(g!=5) + { + t2.putString("B"); + i=20+g; + wait_ms(500); + return(i); + } + + bo1 = 0; + bo2 = 0; + bo3 = 1; + bo4 = 0; + keypadIn(); + if(g!=5) + { + t2.putString("C"); + i=30+g; + wait_ms(500); + return(i); + } + + bo1 = 0; + bo2 = 0; + bo3 = 0; + bo4 = 1; + keypadIn(); + if(g!=5) + { + t2.putString("D"); + i=40+g; + wait_ms(500); + return(i); + } + return(0); +} + +void Keepad::keypadIn() +{ + LCDs t3; + for(int l=1;l<10;l++) + { + if(bi1 == 1) + { + t3.putString("1"); + g=1; + break; + } + else if(bi2 == 1) + { + t3.putString("2"); + g=2; + break; + } + else if(bi3 == 1) + { + t3.putString("3"); + g=3; + break; + } + else if(bi4 == 1) + { + t3.putString("4"); + g=4; + break; + } + else + {g=5;} + wait_ms(10); + } +} \ No newline at end of file