Words in Typing mode

Dependencies:   SDFileSystem emic2 mbed-rtos mbed

Committer:
aismail1997
Date:
Mon Dec 04 19:40:28 2017 +0000
Revision:
42:aa46c2be7dbb
Parent:
41:560ee7866781
Words in typing mode;

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 41:560ee7866781 13
aismail1997 10:21268d8bf979 14 // FUNCTIONS
aismail1997 13:b80dde24e9bc 15
aismail1997 19:ceac47be2e64 16 int button::getPress()
aismail1997 19:ceac47be2e64 17 {
nnguyen45 33:3090ec93b4aa 18 //pc.printf("%d", press);
aismail1997 19:ceac47be2e64 19 return press;
aismail1997 19:ceac47be2e64 20 }
aismail1997 19:ceac47be2e64 21
aismail1997 10:21268d8bf979 22
aismail1997 13:b80dde24e9bc 23 // move servo into the slot
aismail1997 10:21268d8bf979 24 void button::moveServoIn()
aismail1997 10:21268d8bf979 25 {
aismail1997 10:21268d8bf979 26 //myled = 1;
aismail1997 10:21268d8bf979 27 // rotate 90 degrees one way
nnguyen45 33:3090ec93b4aa 28 for(int i=4; i<=7; i++) {
aismail1997 10:21268d8bf979 29 servo = i/100.0;
aismail1997 10:21268d8bf979 30 wait(0.01);
aismail1997 10:21268d8bf979 31 }
nnguyen45 33:3090ec93b4aa 32 //press = 1;
nnguyen45 32:e87bb6e83072 33 switch (id) {
nnguyen45 32:e87bb6e83072 34 case 1:
nnguyen45 32:e87bb6e83072 35 led2 = 0;
nnguyen45 32:e87bb6e83072 36 led3 = 0;
nnguyen45 32:e87bb6e83072 37 led4 = 1;
nnguyen45 32:e87bb6e83072 38 break;
nnguyen45 32:e87bb6e83072 39 case 2:
nnguyen45 32:e87bb6e83072 40 led2 = 0;
nnguyen45 32:e87bb6e83072 41 led3 = 1;
nnguyen45 32:e87bb6e83072 42 led4 = 0;
nnguyen45 32:e87bb6e83072 43 break;
nnguyen45 32:e87bb6e83072 44 case 3:
nnguyen45 32:e87bb6e83072 45 led2 = 0;
nnguyen45 32:e87bb6e83072 46 led3 = 1;
nnguyen45 32:e87bb6e83072 47 led4 = 1;
nnguyen45 32:e87bb6e83072 48 break;
nnguyen45 32:e87bb6e83072 49 case 4:
nnguyen45 32:e87bb6e83072 50 led2 = 1;
nnguyen45 32:e87bb6e83072 51 led3 = 0;
nnguyen45 32:e87bb6e83072 52 led4 = 0;
nnguyen45 32:e87bb6e83072 53 break;
nnguyen45 32:e87bb6e83072 54 case 5:
nnguyen45 32:e87bb6e83072 55 led2 = 1;
nnguyen45 32:e87bb6e83072 56 led3 = 0;
nnguyen45 32:e87bb6e83072 57 led4 = 1;
nnguyen45 32:e87bb6e83072 58 break;
nnguyen45 32:e87bb6e83072 59 case 6:
nnguyen45 32:e87bb6e83072 60 led2 = 1;
nnguyen45 32:e87bb6e83072 61 led3 = 1;
nnguyen45 32:e87bb6e83072 62 led4 = 0;
nnguyen45 32:e87bb6e83072 63 break;
nnguyen45 32:e87bb6e83072 64 }
aismail1997 10:21268d8bf979 65 }
aismail1997 10:21268d8bf979 66
aismail1997 13:b80dde24e9bc 67 // move servo out of the slot
aismail1997 10:21268d8bf979 68 void button::moveServoOut()
aismail1997 10:21268d8bf979 69 {
aismail1997 10:21268d8bf979 70 //myled = 0;
nnguyen45 33:3090ec93b4aa 71 for(int i=7; i>4; i--) {
aismail1997 10:21268d8bf979 72 servo = i/100.0;
aismail1997 10:21268d8bf979 73 wait(0.01);
aismail1997 10:21268d8bf979 74 }
nnguyen45 32:e87bb6e83072 75 led2 = 0;
nnguyen45 32:e87bb6e83072 76 led3 = 0;
nnguyen45 32:e87bb6e83072 77 led4 = 0;
aismail1997 10:21268d8bf979 78 }
aismail1997 19:ceac47be2e64 79
aismail1997 39:8cc80f0b4398 80 // get servo pin
aismail1997 39:8cc80f0b4398 81 void button::setMode(int mymode)
aismail1997 19:ceac47be2e64 82 {
aismail1997 39:8cc80f0b4398 83 type = mymode;
aismail1997 39:8cc80f0b4398 84 }
aismail1997 22:6931917c70cd 85
aismail1997 39:8cc80f0b4398 86 int button::updateState()
aismail1997 39:8cc80f0b4398 87 { if (type == 0) {
aismail1997 39:8cc80f0b4398 88 //myled = 0;
aismail1997 39:8cc80f0b4398 89 // state 0 - button is up, pb = 0
aismail1997 39:8cc80f0b4398 90 if (pb == 0 && state == 3) {
aismail1997 39:8cc80f0b4398 91 // nothing happens here, servo is still
aismail1997 39:8cc80f0b4398 92 state = 0;
aismail1997 39:8cc80f0b4398 93 }
aismail1997 39:8cc80f0b4398 94 // state 1 - button is moving down, pb = 1
aismail1997 39:8cc80f0b4398 95 if (pb == 1 && state == 0) {
aismail1997 39:8cc80f0b4398 96 moveServoIn();
aismail1997 39:8cc80f0b4398 97 state = 1;
aismail1997 39:8cc80f0b4398 98 press = 1;
aismail1997 39:8cc80f0b4398 99 }
aismail1997 39:8cc80f0b4398 100 // state 2 - button is down, pb = 0
aismail1997 39:8cc80f0b4398 101 if (pb == 0 && state == 1) {
aismail1997 39:8cc80f0b4398 102 // nothing happens here, servo is still
aismail1997 39:8cc80f0b4398 103 state = 2;
aismail1997 39:8cc80f0b4398 104 }
aismail1997 39:8cc80f0b4398 105 // state 3 - button is moving up, pb = 1
aismail1997 39:8cc80f0b4398 106 if (pb == 1 && state == 2) {
aismail1997 39:8cc80f0b4398 107 moveServoOut();
aismail1997 39:8cc80f0b4398 108 state = 3;
aismail1997 39:8cc80f0b4398 109 press = 0;
aismail1997 39:8cc80f0b4398 110 }
aismail1997 39:8cc80f0b4398 111 } else {
aismail1997 39:8cc80f0b4398 112 state = pb;
aismail1997 39:8cc80f0b4398 113 press = pb;
aismail1997 19:ceac47be2e64 114 }
aismail1997 19:ceac47be2e64 115 return state;
aismail1997 19:ceac47be2e64 116 }
aismail1997 19:ceac47be2e64 117
aismail1997 27:b2e53ce54b3e 118 void button::setup() {
nnguyen45 33:3090ec93b4aa 119 for(int i=0; i<=4; i++) {
aismail1997 27:b2e53ce54b3e 120 servo = i/100.0;
aismail1997 27:b2e53ce54b3e 121 wait(0.01);
aismail1997 27:b2e53ce54b3e 122 }
aismail1997 27:b2e53ce54b3e 123 }