![](/media/cache/group/X1_XNu7A_400x400.png.50x50_q85.png)
Gestione tastierino robotval
main.cpp@0:051324d87f93, 2018-05-05 (annotated)
- Committer:
- fdalforno
- Date:
- Sat May 05 14:42:39 2018 +0000
- Revision:
- 0:051324d87f93
diagnostico per tastierino robotval
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fdalforno | 0:051324d87f93 | 1 | #include "mbed.h" |
fdalforno | 0:051324d87f93 | 2 | #include "TextLCD.h" |
fdalforno | 0:051324d87f93 | 3 | |
fdalforno | 0:051324d87f93 | 4 | DigitalOut myled(LED1); |
fdalforno | 0:051324d87f93 | 5 | |
fdalforno | 0:051324d87f93 | 6 | |
fdalforno | 0:051324d87f93 | 7 | PinName rowPins[4] = { PB_0 , PA_4 , PA_1 , PA_0 }; |
fdalforno | 0:051324d87f93 | 8 | PinName colPins[4] = { PA_13 , PA_14 , PC_14 , PC_15 }; |
fdalforno | 0:051324d87f93 | 9 | |
fdalforno | 0:051324d87f93 | 10 | DigitalOut* _rows[4]; |
fdalforno | 0:051324d87f93 | 11 | DigitalIn* _cols[4]; |
fdalforno | 0:051324d87f93 | 12 | |
fdalforno | 0:051324d87f93 | 13 | TextLCD lcd(D2,D3,D4,D5,D6,D7); |
fdalforno | 0:051324d87f93 | 14 | |
fdalforno | 0:051324d87f93 | 15 | void printKeyBoard(){ |
fdalforno | 0:051324d87f93 | 16 | //lcd.cls(); |
fdalforno | 0:051324d87f93 | 17 | |
fdalforno | 0:051324d87f93 | 18 | |
fdalforno | 0:051324d87f93 | 19 | lcd.locate(0,0); |
fdalforno | 0:051324d87f93 | 20 | lcd.printf("KeyBoard: "); |
fdalforno | 0:051324d87f93 | 21 | |
fdalforno | 0:051324d87f93 | 22 | lcd.locate(0,1); |
fdalforno | 0:051324d87f93 | 23 | for(int i = 0;i < 4 ;i++){ |
fdalforno | 0:051324d87f93 | 24 | DigitalOut *row = _rows[i]; |
fdalforno | 0:051324d87f93 | 25 | |
fdalforno | 0:051324d87f93 | 26 | char level = 'L'; |
fdalforno | 0:051324d87f93 | 27 | if(row->read() == 1){ |
fdalforno | 0:051324d87f93 | 28 | level = 'H'; |
fdalforno | 0:051324d87f93 | 29 | } |
fdalforno | 0:051324d87f93 | 30 | lcd.printf( "%c" , level); |
fdalforno | 0:051324d87f93 | 31 | } |
fdalforno | 0:051324d87f93 | 32 | |
fdalforno | 0:051324d87f93 | 33 | lcd.printf( "%c" , " "); |
fdalforno | 0:051324d87f93 | 34 | |
fdalforno | 0:051324d87f93 | 35 | |
fdalforno | 0:051324d87f93 | 36 | for(int i = 0;i < 4;i++){ |
fdalforno | 0:051324d87f93 | 37 | DigitalIn *col = _cols[i]; |
fdalforno | 0:051324d87f93 | 38 | |
fdalforno | 0:051324d87f93 | 39 | char level = 'L'; |
fdalforno | 0:051324d87f93 | 40 | if(col->read() == 1){ |
fdalforno | 0:051324d87f93 | 41 | level = 'H'; |
fdalforno | 0:051324d87f93 | 42 | } |
fdalforno | 0:051324d87f93 | 43 | lcd.printf( "%c" , level); |
fdalforno | 0:051324d87f93 | 44 | } |
fdalforno | 0:051324d87f93 | 45 | |
fdalforno | 0:051324d87f93 | 46 | } |
fdalforno | 0:051324d87f93 | 47 | |
fdalforno | 0:051324d87f93 | 48 | int main() { |
fdalforno | 0:051324d87f93 | 49 | |
fdalforno | 0:051324d87f93 | 50 | lcd.locate(0,0); |
fdalforno | 0:051324d87f93 | 51 | lcd.printf("Clean"); |
fdalforno | 0:051324d87f93 | 52 | |
fdalforno | 0:051324d87f93 | 53 | |
fdalforno | 0:051324d87f93 | 54 | for(int i = 0;i < 4; i++){ |
fdalforno | 0:051324d87f93 | 55 | _rows[i] = new DigitalOut(rowPins[i]); |
fdalforno | 0:051324d87f93 | 56 | _rows[i]->write(0); |
fdalforno | 0:051324d87f93 | 57 | } |
fdalforno | 0:051324d87f93 | 58 | for(int i = 0;i < 4; i++){ |
fdalforno | 0:051324d87f93 | 59 | _cols[i] = new DigitalIn(colPins[i],PullDown); |
fdalforno | 0:051324d87f93 | 60 | } |
fdalforno | 0:051324d87f93 | 61 | |
fdalforno | 0:051324d87f93 | 62 | |
fdalforno | 0:051324d87f93 | 63 | while(1) { |
fdalforno | 0:051324d87f93 | 64 | for (int i = 0; i < 4; i++) { |
fdalforno | 0:051324d87f93 | 65 | _rows[i]->write(1); |
fdalforno | 0:051324d87f93 | 66 | printKeyBoard(); |
fdalforno | 0:051324d87f93 | 67 | wait(0.5); |
fdalforno | 0:051324d87f93 | 68 | _rows[i]->write(0); |
fdalforno | 0:051324d87f93 | 69 | } |
fdalforno | 0:051324d87f93 | 70 | } |
fdalforno | 0:051324d87f93 | 71 | } |