-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add LedBlinkTask class impl. for controlling LED
blinking
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |