Fork of original senior design repo

Dependencies:   SDFileSystem mbed-rtos mbed wave_player emic2

Fork of BAT_senior_design by BAT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers button.cpp Source File

button.cpp

00001 #include "mbed.h"
00002 #include "button.h"
00003 #include "emic2.h"
00004 
00005 //emic2 myTTS(p28, p27); //serial RX,TX pins to emic
00006 //DigitalOut led4(LED4);
00007 
00008 // button constructor
00009 button::button(PwmOut servo, DigitalIn pb, int id)
00010     : servo(servo), pb(pb), state(0), press(0), id(id) {}
00011 /*button::button(PwmOut servo, DigitalIn pb, AnalogIn lp)
00012     : servo(servo), pb(pb), linpot(lp), press(0), state(0) {}
00013 */
00014 
00015 // FUNCTIONS
00016 
00017 // get servo pin
00018 PwmOut button::getServoPin()
00019 {
00020     return servo;
00021 }
00022 
00023 // get servo pin
00024 void button::setState(int mystate)
00025 {
00026     state = mystate;
00027 }
00028 
00029 void button::setPress(int mypress)
00030 {
00031     press = mypress;
00032 }
00033 
00034 // get servo pin
00035 /*void button::setMode(int mymode)
00036 {
00037     mode = mymode;
00038 }*/
00039 
00040 // get current state of the button
00041 int button::getState()
00042 {
00043     return state;
00044 }
00045 
00046 int button::getID()
00047 {
00048     return id;
00049 }
00050 
00051 
00052 int button::getPress()
00053 {
00054     return press;
00055 }
00056 
00057 // get current state of the button
00058 int button::getLp()
00059 {
00060     /*    if (linpot < 2)
00061             return 1;
00062         else*/
00063     return 0;
00064 }
00065 
00066 // move servo into the slot
00067 void button::moveServoIn()
00068 {
00069     //myled = 1;
00070     // rotate 90 degrees one way
00071     for(int i=3; i<=7; i++) {
00072         servo = i/100.0;
00073         wait(0.01);
00074     }
00075 }
00076 
00077 // move servo out of the slot
00078 void button::moveServoOut()
00079 {
00080     //myled = 0;
00081     for(int i=7; i>3; i--) {
00082         servo = i/100.0;
00083         wait(0.01);
00084     }
00085 }
00086 
00087 int button::updateState()
00088 {
00089     //myled = 0;
00090     // state 0 - button is up, pb = 0
00091     if (pb == 0 && state == 3) {
00092         // nothing happens here, servo is still
00093         state = 0;
00094     }
00095     // state 1 - button is moving down, pb = 1
00096     if (pb == 1 && state == 0) {
00097         moveServoIn();
00098         state = 1;
00099         press = 1;
00100 
00101         // Speaker says stuff
00102         /*myTTS.volume(18); //max volume
00103         myTTS.speakf("S");//Speak command starts with "S"
00104         myTTS.speakf("Hey, you pressed a pin!");  // Send the desired string to convert to speech
00105         myTTS.speakf("\r"); //marks end of speak command*/
00106     }
00107     // state 2 - button is down, pb = 0
00108     if (pb == 0 && state == 1) {
00109         // nothing happens here, servo is still
00110         state = 2;
00111     }
00112     // state 3 - button is moving up, pb = 1
00113     if (pb == 1 && state == 2) {
00114         moveServoOut();
00115         state = 3;
00116         press = 0;
00117     }
00118     // state 4 - handle debouncing while button is down
00119     /*if (pb1 = 1 && state == 2) {
00120         count++;
00121     }*/
00122     return state;
00123 }
00124 
00125 void button::setup() {
00126     for(int i=0; i<=3; i++) {
00127         servo = i/100.0;
00128         wait(0.01);
00129     }
00130 }