From e5d41a4076d8b52c9341a49c26c7af48bce391c3 Mon Sep 17 00:00:00 2001 From: Emanuele Dajko Date: Sat, 25 Nov 2023 17:51:30 +0100 Subject: [PATCH] Add LedBlinkTask class impl. for controlling LED blinking --- smart_bridge/src/tasks/LedBlinkTask.cpp | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 smart_bridge/src/tasks/LedBlinkTask.cpp diff --git a/smart_bridge/src/tasks/LedBlinkTask.cpp b/smart_bridge/src/tasks/LedBlinkTask.cpp new file mode 100644 index 0000000..0c9f2bf --- /dev/null +++ b/smart_bridge/src/tasks/LedBlinkTask.cpp @@ -0,0 +1,41 @@ +#include "LedBlinkTask.h" + +/** + * @brief Construct a new LedBlinkTask object. + * + * @param ledPin The pin number where the LED is connected. + */ +LedBlinkTask::LedBlinkTask(int ledPin) +{ + this->ledPin = ledPin; +} + +/** + * @brief Initialize the LedBlinkTask. + * + * @param period The period of the task in milliseconds. + */ +void LedBlinkTask::init(int period) +{ + Task::init(period); + state = SWITCH_OFF; +} + +/** + * @brief Perform the LedBlinkTask. + * + * This method is called periodically based on the period of the task. + * It switches the state of the LED from on to off, or from off to on. + */ +void LedBlinkTask::tick() +{ + switch (state) + { + case State::SWITCH_OFF: + state = State::SWITCH_ON; + break; + case State::SWITCH_ON: + state = State::SWITCH_OFF; + break; + } +} \ No newline at end of file