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.
Revision 1:220396a0cb8a, committed 2015-07-31
- Comitter:
- coisme
- Date:
- Fri Jul 31 23:36:45 2015 +0000
- Parent:
- 0:3c77443bfb5b
- Commit message:
- Formatted.
Changed in this revision
| LEDUtil.cpp | Show annotated file Show diff for this revision Revisions of this file |
| LEDUtil.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/LEDUtil.cpp Fri Jul 31 23:26:36 2015 +0000
+++ b/LEDUtil.cpp Fri Jul 31 23:36:45 2015 +0000
@@ -4,15 +4,17 @@
#define PIN_HIGH 1
#define PIN_LOW 0
-LEDUtil::LEDUtil(PinName targetPinName, LEDUtil::Polarity targetPinPolarity) {
+LEDUtil::LEDUtil(PinName targetPinName, LEDUtil::Polarity targetPinPolarity)
+{
this->pinName = targetPinName;
this->polarity = targetPinPolarity;
-}
+}
+
-
-void LEDUtil::setLedState(LedState state) {
+void LEDUtil::setLedState(LedState state)
+{
DigitalOut pin(pinName);
-
+
if (state == LEDUtil::LED_ON) {
// turns on the LED
pin.write((polarity == LEDUtil::HIGH_ON_LOW_OFF) ? PIN_HIGH : PIN_LOW);
@@ -22,15 +24,18 @@
}
}
-void LEDUtil::turnOn() {
+void LEDUtil::turnOn()
+{
LEDUtil::setLedState(LEDUtil::LED_ON);
}
-void LEDUtil::turnOff() {
+void LEDUtil::turnOff()
+{
LEDUtil::setLedState(LEDUtil::LED_OFF);
}
-bool LEDUtil::isOn() {
+bool LEDUtil::isOn()
+{
if (getLedState() == LEDUtil::LED_ON) {
return true;
} else {
@@ -38,20 +43,22 @@
}
}
-bool LEDUtil::isOff() {
+bool LEDUtil::isOff()
+{
return (!LEDUtil::isOn());
}
-LEDUtil::LedState LEDUtil::getLedState() {
+LEDUtil::LedState LEDUtil::getLedState()
+{
DigitalOut pin(pinName);
LedState state = LEDUtil::LED_OFF;
-
+
if (pin.read() == PIN_HIGH) {
state = ((polarity == LEDUtil::HIGH_ON_LOW_OFF) ? LEDUtil::LED_ON : LEDUtil::LED_OFF);
} else {
state = ((polarity == LEDUtil::LOW_ON_HIGH_OFF) ? LEDUtil::LED_OFF : LEDUtil::LED_ON);
}
-
+
return state;
}
--- a/LEDUtil.h Fri Jul 31 23:26:36 2015 +0000
+++ b/LEDUtil.h Fri Jul 31 23:36:45 2015 +0000
@@ -10,11 +10,11 @@
* #include "LEDUtil.h"
*
* // LED is connected to P0_19 on BLENano and it lights up when the pin state is high.
- * #define LED_PIN_NAME P0_19
+ * #define LED_PIN_NAME P0_19
*
* void main() {
* LEDUtil led1(P0_19, LEDUtil::HIGH_ON_LOW_OFF);
- *
+ *
* while(true) {
* led1.turnOn();
* wait(0.5);
@@ -24,18 +24,19 @@
* }
* @endcode
*/
-class LEDUtil {
+class LEDUtil
+{
- public:
-
+public:
+
/** Polarity of LED's configuration. */
typedef enum {
/** The target LED lights up when the pin level is high. */
HIGH_ON_LOW_OFF,
/** The target LED lights up when the pin level is low. */
- LOW_ON_HIGH_OFF
+ LOW_ON_HIGH_OFF
} Polarity;
-
+
/**
* Constructor.
*
@@ -48,24 +49,24 @@
* Turns on the LED.
*/
void turnOn();
-
+
/**
* Turns off the LED.
*/
void turnOff();
-
+
/**
* Returns if the LED is on.
* @return Returns true if the LED is on. Otherwise returns false.
*/
bool isOn();
-
+
/**
* Returns if the LED is off.
* @return Returns true if the LED is off. Otherwise returns false.
*/
- bool isOff();
-
+ bool isOff();
+
/**
* Get polarity setting.
* @return polarity setting of this LED configuration.
@@ -73,14 +74,14 @@
Polarity getPolarity();
- private:
-
+private:
+
/* Holds the target LED's pin name. */
PinName pinName;
-
+
/* Holds polarity of the target LED pin. */
Polarity polarity;
-
+
/* State of the LED, i.e. on or off. */
typedef enum {LED_ON, LED_OFF} LedState;
@@ -89,7 +90,7 @@
* @param state LED state to be set.
*/
void setLedState(LedState state);
-
+
/*
* Gets the LED state.
* @return Returns LED state.