Letters in typing mode

Dependencies:   SDFileSystem emic2 mbed-rtos mbed

Fork of BAT_senior_design_Test_Type by BAT

Committer:
aismail1997
Date:
Sat Dec 02 23:53:06 2017 +0000
Revision:
39:8cc80f0b4398
Parent:
33:3090ec93b4aa
Child:
41:560ee7866781
gets stuck at recheck, works correctly otherwise;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aismail1997 10:21268d8bf979 1 #include "mbed.h"
aismail1997 10:21268d8bf979 2 #include "button.h"
aismail1997 22:6931917c70cd 3 #include "emic2.h"
aismail1997 22:6931917c70cd 4
aismail1997 23:23970cf718ee 5 //emic2 myTTS(p28, p27); //serial RX,TX pins to emic
nnguyen45 32:e87bb6e83072 6 DigitalOut led4(LED4);
nnguyen45 32:e87bb6e83072 7 DigitalOut led3(LED3);
nnguyen45 32:e87bb6e83072 8 DigitalOut led2(LED2);
aismail1997 10:21268d8bf979 9
aismail1997 13:b80dde24e9bc 10 // button constructor
aismail1997 21:c5df903f068a 11 button::button(PwmOut servo, DigitalIn pb, int id)
aismail1997 39:8cc80f0b4398 12 : servo(servo), pb(pb), state(0), press(0), id(id), type(0) {}
aismail1997 21:c5df903f068a 13 /*button::button(PwmOut servo, DigitalIn pb, AnalogIn lp)
aismail1997 21:c5df903f068a 14 : servo(servo), pb(pb), linpot(lp), press(0), state(0) {}
aismail1997 21:c5df903f068a 15 */
nnguyen45 33:3090ec93b4aa 16 //Serial pc(USBTX, USBRX);
aismail1997 10:21268d8bf979 17
aismail1997 10:21268d8bf979 18 // FUNCTIONS
aismail1997 13:b80dde24e9bc 19
aismail1997 13:b80dde24e9bc 20 // get servo pin
aismail1997 10:21268d8bf979 21 PwmOut button::getServoPin()
aismail1997 10:21268d8bf979 22 {
aismail1997 10:21268d8bf979 23 return servo;
aismail1997 10:21268d8bf979 24 }
aismail1997 10:21268d8bf979 25
aismail1997 14:581a3b02f4c3 26 // get servo pin
aismail1997 19:ceac47be2e64 27 void button::setState(int mystate)
aismail1997 14:581a3b02f4c3 28 {
aismail1997 14:581a3b02f4c3 29 state = mystate;
aismail1997 14:581a3b02f4c3 30 }
aismail1997 14:581a3b02f4c3 31
aismail1997 21:c5df903f068a 32 void button::setPress(int mypress)
aismail1997 21:c5df903f068a 33 {
aismail1997 21:c5df903f068a 34 press = mypress;
aismail1997 21:c5df903f068a 35 }
aismail1997 21:c5df903f068a 36
aismail1997 14:581a3b02f4c3 37 // get servo pin
aismail1997 19:ceac47be2e64 38 /*void button::setMode(int mymode)
aismail1997 14:581a3b02f4c3 39 {
aismail1997 14:581a3b02f4c3 40 mode = mymode;
aismail1997 14:581a3b02f4c3 41 }*/
aismail1997 14:581a3b02f4c3 42
aismail1997 13:b80dde24e9bc 43 // get current state of the button
aismail1997 19:ceac47be2e64 44 int button::getState()
aismail1997 10:21268d8bf979 45 {
aismail1997 10:21268d8bf979 46 return state;
aismail1997 19:ceac47be2e64 47 }
aismail1997 19:ceac47be2e64 48
aismail1997 21:c5df903f068a 49 int button::getID()
aismail1997 21:c5df903f068a 50 {
aismail1997 21:c5df903f068a 51 return id;
aismail1997 21:c5df903f068a 52 }
aismail1997 21:c5df903f068a 53
aismail1997 21:c5df903f068a 54
aismail1997 19:ceac47be2e64 55 int button::getPress()
aismail1997 19:ceac47be2e64 56 {
nnguyen45 33:3090ec93b4aa 57 //pc.printf("%d", press);
aismail1997 19:ceac47be2e64 58 return press;
aismail1997 19:ceac47be2e64 59 }
aismail1997 19:ceac47be2e64 60
aismail1997 21:c5df903f068a 61 // get current state of the button
aismail1997 21:c5df903f068a 62 int button::getLp()
aismail1997 21:c5df903f068a 63 {
aismail1997 22:6931917c70cd 64 /* if (linpot < 2)
aismail1997 22:6931917c70cd 65 return 1;
aismail1997 22:6931917c70cd 66 else*/
aismail1997 22:6931917c70cd 67 return 0;
aismail1997 21:c5df903f068a 68 }
aismail1997 10:21268d8bf979 69
aismail1997 13:b80dde24e9bc 70 // move servo into the slot
aismail1997 10:21268d8bf979 71 void button::moveServoIn()
aismail1997 10:21268d8bf979 72 {
aismail1997 10:21268d8bf979 73 //myled = 1;
aismail1997 10:21268d8bf979 74 // rotate 90 degrees one way
nnguyen45 33:3090ec93b4aa 75 for(int i=4; i<=7; i++) {
aismail1997 10:21268d8bf979 76 servo = i/100.0;
aismail1997 10:21268d8bf979 77 wait(0.01);
aismail1997 10:21268d8bf979 78 }
nnguyen45 33:3090ec93b4aa 79 //press = 1;
nnguyen45 32:e87bb6e83072 80 switch (id) {
nnguyen45 32:e87bb6e83072 81 case 1:
nnguyen45 32:e87bb6e83072 82 led2 = 0;
nnguyen45 32:e87bb6e83072 83 led3 = 0;
nnguyen45 32:e87bb6e83072 84 led4 = 1;
nnguyen45 32:e87bb6e83072 85 break;
nnguyen45 32:e87bb6e83072 86 case 2:
nnguyen45 32:e87bb6e83072 87 led2 = 0;
nnguyen45 32:e87bb6e83072 88 led3 = 1;
nnguyen45 32:e87bb6e83072 89 led4 = 0;
nnguyen45 32:e87bb6e83072 90 break;
nnguyen45 32:e87bb6e83072 91 case 3:
nnguyen45 32:e87bb6e83072 92 led2 = 0;
nnguyen45 32:e87bb6e83072 93 led3 = 1;
nnguyen45 32:e87bb6e83072 94 led4 = 1;
nnguyen45 32:e87bb6e83072 95 break;
nnguyen45 32:e87bb6e83072 96 case 4:
nnguyen45 32:e87bb6e83072 97 led2 = 1;
nnguyen45 32:e87bb6e83072 98 led3 = 0;
nnguyen45 32:e87bb6e83072 99 led4 = 0;
nnguyen45 32:e87bb6e83072 100 break;
nnguyen45 32:e87bb6e83072 101 case 5:
nnguyen45 32:e87bb6e83072 102 led2 = 1;
nnguyen45 32:e87bb6e83072 103 led3 = 0;
nnguyen45 32:e87bb6e83072 104 led4 = 1;
nnguyen45 32:e87bb6e83072 105 break;
nnguyen45 32:e87bb6e83072 106 case 6:
nnguyen45 32:e87bb6e83072 107 led2 = 1;
nnguyen45 32:e87bb6e83072 108 led3 = 1;
nnguyen45 32:e87bb6e83072 109 led4 = 0;
nnguyen45 32:e87bb6e83072 110 break;
nnguyen45 32:e87bb6e83072 111 }
aismail1997 10:21268d8bf979 112 }
aismail1997 10:21268d8bf979 113
aismail1997 13:b80dde24e9bc 114 // move servo out of the slot
aismail1997 10:21268d8bf979 115 void button::moveServoOut()
aismail1997 10:21268d8bf979 116 {
aismail1997 10:21268d8bf979 117 //myled = 0;
nnguyen45 33:3090ec93b4aa 118 for(int i=7; i>4; i--) {
aismail1997 10:21268d8bf979 119 servo = i/100.0;
aismail1997 10:21268d8bf979 120 wait(0.01);
aismail1997 10:21268d8bf979 121 }
nnguyen45 32:e87bb6e83072 122 led2 = 0;
nnguyen45 32:e87bb6e83072 123 led3 = 0;
nnguyen45 32:e87bb6e83072 124 led4 = 0;
aismail1997 10:21268d8bf979 125 }
aismail1997 19:ceac47be2e64 126
aismail1997 39:8cc80f0b4398 127 // get servo pin
aismail1997 39:8cc80f0b4398 128 void button::setMode(int mymode)
aismail1997 19:ceac47be2e64 129 {
aismail1997 39:8cc80f0b4398 130 type = mymode;
aismail1997 39:8cc80f0b4398 131 }
aismail1997 22:6931917c70cd 132
aismail1997 39:8cc80f0b4398 133 int button::updateState()
aismail1997 39:8cc80f0b4398 134 { if (type == 0) {
aismail1997 39:8cc80f0b4398 135 //myled = 0;
aismail1997 39:8cc80f0b4398 136 // state 0 - button is up, pb = 0
aismail1997 39:8cc80f0b4398 137 if (pb == 0 && state == 3) {
aismail1997 39:8cc80f0b4398 138 // nothing happens here, servo is still
aismail1997 39:8cc80f0b4398 139 state = 0;
aismail1997 39:8cc80f0b4398 140 }
aismail1997 39:8cc80f0b4398 141 // state 1 - button is moving down, pb = 1
aismail1997 39:8cc80f0b4398 142 if (pb == 1 && state == 0) {
aismail1997 39:8cc80f0b4398 143 moveServoIn();
aismail1997 39:8cc80f0b4398 144 state = 1;
aismail1997 39:8cc80f0b4398 145 press = 1;
aismail1997 39:8cc80f0b4398 146 }
aismail1997 39:8cc80f0b4398 147 // state 2 - button is down, pb = 0
aismail1997 39:8cc80f0b4398 148 if (pb == 0 && state == 1) {
aismail1997 39:8cc80f0b4398 149 // nothing happens here, servo is still
aismail1997 39:8cc80f0b4398 150 state = 2;
aismail1997 39:8cc80f0b4398 151 }
aismail1997 39:8cc80f0b4398 152 // state 3 - button is moving up, pb = 1
aismail1997 39:8cc80f0b4398 153 if (pb == 1 && state == 2) {
aismail1997 39:8cc80f0b4398 154 moveServoOut();
aismail1997 39:8cc80f0b4398 155 state = 3;
aismail1997 39:8cc80f0b4398 156 press = 0;
aismail1997 39:8cc80f0b4398 157 }
aismail1997 39:8cc80f0b4398 158 } else {
aismail1997 39:8cc80f0b4398 159 state = pb;
aismail1997 39:8cc80f0b4398 160 press = pb;
aismail1997 19:ceac47be2e64 161 }
aismail1997 19:ceac47be2e64 162 return state;
aismail1997 19:ceac47be2e64 163 }
aismail1997 19:ceac47be2e64 164
aismail1997 27:b2e53ce54b3e 165 void button::setup() {
nnguyen45 33:3090ec93b4aa 166 for(int i=0; i<=4; i++) {
aismail1997 27:b2e53ce54b3e 167 servo = i/100.0;
aismail1997 27:b2e53ce54b3e 168 wait(0.01);
aismail1997 27:b2e53ce54b3e 169 }
aismail1997 27:b2e53ce54b3e 170 }