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.
Fork of HumanInterface by
HumanInterface.cpp
00001 #include "HumanInterface.h" 00002 00003 00004 HumanInterface::HumanInterface (PCA9555 *ioExt, 00005 unsigned int redLed1Pin, unsigned int greenLed1Pin, unsigned int blueLed1Pin, 00006 unsigned int redLed2Pin, unsigned int greenLed2Pin, unsigned int blueLed2Pin, 00007 PinName goalButtonPin, PinName startButtonPin, PinName ballSensePin): 00008 extIO(ioExt), 00009 rgbLed1(ioExt, redLed1Pin, greenLed1Pin, blueLed1Pin), 00010 rgbLed2(ioExt, redLed2Pin, greenLed2Pin, blueLed2Pin), 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 inputBall.rise(this, &HumanInterface::ballRise); 00026 inputBall.fall(this, &HumanInterface::ballFall); 00027 00028 buttonGoal.setSamplesTillAssert(20); 00029 buttonStart.setSamplesTillAssert(20); 00030 //inputBall.setSamplesTillAssert(2); 00031 00032 buttonGoal.setSampleFrequency(1000); 00033 buttonStart.setSampleFrequency(1000); 00034 //inputBall.setSampleFrequency(5000); 00035 00036 redBlinking = false; 00037 goalBlinking = false; 00038 00039 setGoal(UNSET); 00040 00041 ledTicker.attach(this, &HumanInterface::blinkLeds, 0.2); 00042 00043 } 00044 00045 void HumanInterface::setError(bool state) { 00046 if (state) { 00047 redBlinking = true; 00048 rgbLed2.setGreen(false); 00049 rgbLed2.setColor(RgbLed::RED); 00050 } else { 00051 redBlinking = false; 00052 rgbLed2.setRed(false); 00053 } 00054 } 00055 00056 void HumanInterface::setGo(bool state) { 00057 if (state) { 00058 rgbLed2.setColor(RgbLed::GREEN); 00059 redBlinking = false; 00060 } else { 00061 rgbLed2.setGreen(false); 00062 } 00063 } 00064 00065 void HumanInterface::setGoal(Goal goal) { 00066 if (goal == YELLOW) { 00067 rgbLed1.setColor(RgbLed::YELLOW); 00068 goalBlinking = false; 00069 } else if (goal == BLUE) { 00070 rgbLed1.setColor(RgbLed::BLUE); 00071 goalBlinking = false; 00072 } else if (goal == UNSET) { 00073 rgbLed1.setColor(RgbLed::YELLOW); 00074 goalBlinking = true; 00075 } 00076 } 00077 00078 void HumanInterface::blinkLeds(void) { 00079 if (redBlinking) 00080 rgbLed2.toggleRed(); 00081 if (goalBlinking) 00082 rgbLed1.toggle(); 00083 } 00084 00085 00086 00087 int HumanInterface::getBallState() { 00088 //int ret = ballState; 00089 //ballState = 0; 00090 return ballState; 00091 } 00092 00093 bool HumanInterface::isGoalChange() { 00094 bool ret = goalButtonPressed; 00095 goalButtonPressed = false; 00096 return ret; 00097 } 00098 00099 bool HumanInterface::isStart() { 00100 bool ret = startButtonReleased; 00101 startButtonReleased = false; 00102 return ret; 00103 } 00104 00105 void HumanInterface::goalFall() { 00106 goalButtonPressed = true; 00107 } 00108 00109 void HumanInterface::startRise() { 00110 startButtonReleased = true; 00111 } 00112 00113 void HumanInterface::ballRise() { 00114 ballState = 1; 00115 rgbLed2.setColor(RgbLed::MAGENTA); 00116 } 00117 00118 void HumanInterface::ballFall() { 00119 ballState = 0; 00120 rgbLed2.setColor(RgbLed::OFF); 00121 }
Generated on Thu Aug 11 2022 08:35:58 by
1.7.2
