Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
HumanInterface.cpp
00001 #include "HumanInterface.h" 00002 00003 00004 HumanInterface::HumanInterface (PCA9555 *ioExt, 00005 unsigned int yellowLedPin, unsigned int blueLedPin, unsigned int redLedPin, 00006 unsigned int greenLedPin, unsigned int orangeLedPin, 00007 PinName goalButtonPin, PinName startButtonPin, PinName ballSensePin): 00008 extIO(ioExt), redLed(ioExt, redLedPin), blueLed(ioExt, blueLedPin), yellowLed(ioExt, yellowLedPin), 00009 greenLed(ioExt, greenLedPin), orangeLed(ioExt, orangeLedPin), 00010 /*interruptGoal(goalButtonPin), interruptStart(startButtonPin), interruptBall(ballSensePin)*/ 00011 buttonGoal(goalButtonPin), buttonStart(startButtonPin), inputBall(ballSensePin) 00012 { 00013 goalButtonPressed = false; 00014 startButtonReleased = false; 00015 ballState = 0; 00016 00017 buttonGoal.mode(PullUp); 00018 buttonStart.mode(PullUp); 00019 00020 buttonGoal.attach_deasserted(this, &HumanInterface::goalFall); 00021 buttonStart.attach_asserted(this, &HumanInterface::startRise); 00022 inputBall.attach_asserted(this, &HumanInterface::ballRise); 00023 inputBall.attach_deasserted(this, &HumanInterface::ballFall); 00024 00025 buttonGoal.setSamplesTillAssert(20); 00026 buttonStart.setSamplesTillAssert(20); 00027 inputBall.setSamplesTillAssert(2); 00028 00029 buttonGoal.setSampleFrequency(1000); 00030 buttonStart.setSampleFrequency(1000); 00031 inputBall.setSampleFrequency(250); 00032 00033 00034 redBlinking = false; 00035 blueBlinking = false; 00036 yellowBlinking = false; 00037 greenBlinking = false; 00038 orangeBlinking = false; 00039 00040 setGoal(UNSET); 00041 00042 ledTicker.attach(this, &HumanInterface::blinkLeds, 0.2); 00043 00044 } 00045 00046 void HumanInterface::setError(bool state) { 00047 if (state) { 00048 redBlinking = true; 00049 } else { 00050 redBlinking = false; 00051 redLed.clear(); 00052 } 00053 } 00054 00055 void HumanInterface::setGo(bool state) { 00056 if (state) { 00057 greenLed.set(); 00058 } else { 00059 greenLed.clear(); 00060 } 00061 } 00062 00063 void HumanInterface::setGoal(Goal goal) { 00064 if (goal == YELLOW) { 00065 yellowLed.set(); 00066 blueLed.clear(); 00067 blueBlinking = false; 00068 yellowBlinking = false; 00069 } else if (goal == BLUE) { 00070 yellowLed.clear(); 00071 blueLed.set(); 00072 blueBlinking = false; 00073 yellowBlinking = false; 00074 } else if (goal == UNSET) { 00075 yellowLed.clear(); 00076 blueLed.clear(); 00077 blueBlinking = true; 00078 yellowBlinking = true; 00079 } 00080 } 00081 00082 void HumanInterface::blinkLeds(void) { 00083 if (redBlinking) 00084 redLed.toggle(); 00085 if (blueBlinking) 00086 blueLed.toggle(); 00087 if (yellowBlinking) 00088 yellowLed.toggle(); 00089 if (greenBlinking) 00090 greenLed.toggle(); 00091 if (orangeBlinking) 00092 orangeLed.toggle(); 00093 } 00094 00095 00096 00097 int HumanInterface::getBallState() { 00098 int ret = ballState; 00099 ballState = 0; 00100 return ret; 00101 } 00102 00103 bool HumanInterface::isGoalChange() { 00104 bool ret = goalButtonPressed; 00105 goalButtonPressed = false; 00106 return ret; 00107 } 00108 bool HumanInterface::isStart() { 00109 bool ret = startButtonReleased; 00110 startButtonReleased = false; 00111 return ret; 00112 } 00113 00114 00115 void HumanInterface::goalFall() { 00116 goalButtonPressed = true; 00117 } 00118 00119 void HumanInterface::startRise() { 00120 startButtonReleased = true; 00121 } 00122 00123 void HumanInterface::ballRise() { 00124 ballState = 1; 00125 } 00126 00127 void HumanInterface::ballFall() { 00128 ballState = -1; 00129 }
Generated on Wed Jul 13 2022 09:29:00 by
1.7.2
