Trying to debug

Dependencies:   mbed TextLCD keypad

Committer:
baet6458
Date:
Thu Jan 31 00:48:02 2019 +0000
Revision:
6:d2f4c1f6877c
Parent:
5:7aff70602b66
Child:
7:022c8579e8c7
Added in lcd display code.; ; Please test!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
reyno1jk 0:9b646298bdc9 1 #include "TextLCD.h"
reyno1jk 0:9b646298bdc9 2 #include "mbed.h"
reyno1jk 0:9b646298bdc9 3 #include "Keypad.h"
reyno1jk 0:9b646298bdc9 4 #include <string>
baet6458 5:7aff70602b66 5 //define lcd pins deafault 16x2
baet6458 5:7aff70602b66 6 TextLCD lcd(D8,D9, D4, D5, D6, D7); // rs, e, d4, d5, d6, d7
reyno1jk 0:9b646298bdc9 7 // Define your own keypad values
reyno1jk 0:9b646298bdc9 8 char Keytable[] = { '1', '2', '3', 'U', // r0 U = up
reyno1jk 0:9b646298bdc9 9 '4', '5', '6', 'D', // r1 D = down
reyno1jk 0:9b646298bdc9 10 '7', '8', '9', 'S', // r2 S = 2nd
reyno1jk 0:9b646298bdc9 11 'C', '0', ',', 'E' // r3 C = clear, E = enter
reyno1jk 0:9b646298bdc9 12 };
reyno1jk 0:9b646298bdc9 13 // c0 c1 c2 c3
baet6458 1:c57c18e1ca87 14
baet6458 1:c57c18e1ca87 15 //displayed menu items
baet6458 1:c57c18e1ca87 16 const char* menu[]={"Select harness:","1. Harness A","2. Harness B","3. Harness C","4. Harness D","5. Harness E","6. Harness F","7. Harness G","8. Harness H","9. Harness I","Test in progress"};
baet6458 5:7aff70602b66 17
baet6458 5:7aff70602b66 18 //array to display and tracker
baet6458 5:7aff70602b66 19 char LCDdisplay[16];
baet6458 5:7aff70602b66 20 int displayTracker=0;
baet6458 1:c57c18e1ca87 21
baet6458 3:59fc3838d34d 22 //key presesed holder
baet6458 1:c57c18e1ca87 23 int keyTracker=0;
reyno1jk 0:9b646298bdc9 24
baet6458 5:7aff70602b66 25 bool special =false;
baet6458 5:7aff70602b66 26
baet6458 1:c57c18e1ca87 27 //enter function
baet6458 1:c57c18e1ca87 28 void enterFunc(){
baet6458 1:c57c18e1ca87 29 //do something eventually
baet6458 1:c57c18e1ca87 30 }
baet6458 5:7aff70602b66 31
baet6458 5:7aff70602b66 32 void updateDisplayArray(int pos, bool comma=false){
baet6458 5:7aff70602b66 33 if (comma == false)
baet6458 5:7aff70602b66 34 LCDdisplay[displayTracker]=Keytable[pos];
baet6458 5:7aff70602b66 35 else
baet6458 5:7aff70602b66 36 LCDdisplay[displayTracker]='-';
baet6458 5:7aff70602b66 37
baet6458 5:7aff70602b66 38 special=false;
baet6458 5:7aff70602b66 39 }
reyno1jk 0:9b646298bdc9 40
baet6458 1:c57c18e1ca87 41
baet6458 1:c57c18e1ca87 42 uint32_t LCDUpdate(uint32_t index) {
baet6458 3:59fc3838d34d 43 //see which key is pressed
baet6458 3:59fc3838d34d 44 switch (index){
baet6458 3:59fc3838d34d 45 //if up button is presseed
baet6458 3:59fc3838d34d 46 case 3:
baet6458 3:59fc3838d34d 47 //do something
baet6458 3:59fc3838d34d 48 break;
baet6458 3:59fc3838d34d 49
baet6458 3:59fc3838d34d 50 //if down button is pressed
baet6458 3:59fc3838d34d 51 case 7:
baet6458 3:59fc3838d34d 52 //do something
baet6458 3:59fc3838d34d 53 break;
baet6458 3:59fc3838d34d 54
baet6458 3:59fc3838d34d 55 //if 2nd button is pressed
baet6458 3:59fc3838d34d 56 case 11:
baet6458 5:7aff70602b66 57 //say if 2nd is pressed
baet6458 5:7aff70602b66 58 special=!special;
baet6458 3:59fc3838d34d 59 break;
baet6458 3:59fc3838d34d 60 //if clear is pressed
baet6458 3:59fc3838d34d 61 case 12:
baet6458 3:59fc3838d34d 62 //reset key Tracker
baet6458 3:59fc3838d34d 63 keyTracker=0;
baet6458 5:7aff70602b66 64 //put blanks back in array
baet6458 5:7aff70602b66 65 for(int i=0;i<16;i++){
baet6458 6:d2f4c1f6877c 66 LCDdisplay[i]=' ';
baet6458 5:7aff70602b66 67 }
baet6458 3:59fc3838d34d 68 break;
baet6458 3:59fc3838d34d 69 //if comma is pressed
baet6458 3:59fc3838d34d 70 case 14:
baet6458 5:7aff70602b66 71 //if 2nd is pressed put in dash
baet6458 5:7aff70602b66 72 if (special==true)
baet6458 5:7aff70602b66 73 updateDisplayArray(index,special);
baet6458 5:7aff70602b66 74 else
baet6458 5:7aff70602b66 75 //otherwise it is a comma
baet6458 5:7aff70602b66 76 updateDisplayArray(index);
baet6458 3:59fc3838d34d 77 break;
baet6458 3:59fc3838d34d 78 //if enter is pressed
baet6458 3:59fc3838d34d 79 case 15:
baet6458 1:c57c18e1ca87 80 //call enter function
baet6458 3:59fc3838d34d 81 enterFunc();
baet6458 3:59fc3838d34d 82 break;
baet6458 3:59fc3838d34d 83
baet6458 3:59fc3838d34d 84 default://update the keypressed
baet6458 5:7aff70602b66 85
baet6458 5:7aff70602b66 86 //may remove this later
baet6458 3:59fc3838d34d 87 keyTracker=keyTracker*10+int(Keytable[index]);
baet6458 5:7aff70602b66 88
baet6458 5:7aff70602b66 89 updateDisplayArray(index);
baet6458 5:7aff70602b66 90
baet6458 1:c57c18e1ca87 91 }
baet6458 1:c57c18e1ca87 92
baet6458 5:7aff70602b66 93 displayTracker++;
baet6458 5:7aff70602b66 94 if(displayTracker>16)
baet6458 5:7aff70602b66 95 displayTracker=0;
baet6458 1:c57c18e1ca87 96 return 0;
reyno1jk 0:9b646298bdc9 97 }
reyno1jk 0:9b646298bdc9 98
baet6458 1:c57c18e1ca87 99
reyno1jk 0:9b646298bdc9 100 int main() {
reyno1jk 0:9b646298bdc9 101 // r0 r1 r2 r3 c0 c1 c2 c3
reyno1jk 0:9b646298bdc9 102 Keypad keypad(D0, D1, D2, D3, D10, D11, D12, D13);
baet6458 1:c57c18e1ca87 103 keypad.attach(&LCDUpdate);
baet6458 2:c25102764602 104 keypad.start();
reyno1jk 0:9b646298bdc9 105 while (1) {
baet6458 6:d2f4c1f6877c 106 lcd.cls();
baet6458 6:d2f4c1f6877c 107 lcd.printf("Please Enter wires:");
baet6458 6:d2f4c1f6877c 108 lcd.locate(0,1);
baet6458 6:d2f4c1f6877c 109 for(int j=0;j<16;j++){
baet6458 6:d2f4c1f6877c 110 lcd.putc(LCDdisplay[j]);
baet6458 6:d2f4c1f6877c 111 }
reyno1jk 0:9b646298bdc9 112 }
baet6458 2:c25102764602 113
reyno1jk 0:9b646298bdc9 114 }