Core Base Classes for the Light Endpoints
Dependents: mbed_mqtt_endpoint_ublox_ethernet mbed_mqtt_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_ethernet ... more
Diff: CopCarLEDFlasher.cpp
- Revision:
- 146:8c05a119d9d4
- Parent:
- 144:e4d24c2c8f18
- Child:
- 188:56fccf5f919b
--- a/CopCarLEDFlasher.cpp Wed Apr 02 01:08:48 2014 +0000 +++ b/CopCarLEDFlasher.cpp Wed Apr 02 01:50:02 2014 +0000 @@ -21,22 +21,36 @@ // default constructor CopCarLEDFlasher::CopCarLEDFlasher(PwmOut *led1,PwmOut *led2,ErrorHandler *error_handler) : ExternalLEDLight(led1,error_handler) { this->m_led2 = led2; + this->m_toggle = false; } // destructor CopCarLEDFlasher::~CopCarLEDFlasher() { if (this->m_led2 != NULL) delete this->m_led2; } + + // turn the light on + void CopCarLEDFlasher::on() { this->m_state = 1; this->update(); } + + // turn the light off + void CopCarLEDFlasher::off() { this->m_state = 0; this->update(); } // set the light state void CopCarLEDFlasher::update() { - ExternalLEDLight::update(); - // turn the light on or off if (this->m_state == 0) { *(this->m_led2) = 0; + *(this->m_led) = 0; } - else { - *(this->m_led2) = 1; + if (this->m_state == 1) { + if (this->m_toggle) { + *(this->m_led2) = 1; + *(this->m_led) = 0; + } + else { + *(this->m_led2) = 0; + *(this->m_led) = 1; + } + this->m_toggle = !this->m_toggle; } } \ No newline at end of file