-
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.
[TEST TASK] Add a simple blinking task
- Loading branch information
Showing
2 changed files
with
48 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,28 @@ | ||
#include "BlinkTask.h" | ||
|
||
BlinkTask::BlinkTask(int pin) | ||
{ | ||
this->pin = pin; | ||
} | ||
|
||
void BlinkTask::init(int period) | ||
{ | ||
Task::init(period); | ||
led = new Led(pin); | ||
state = OFF; | ||
} | ||
|
||
void BlinkTask::tick() | ||
{ | ||
switch (state) | ||
{ | ||
case OFF: | ||
led->switchOn(); | ||
state = ON; | ||
break; | ||
case ON: | ||
led->switchOff(); | ||
state = OFF; | ||
break; | ||
} | ||
} |
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,20 @@ | ||
#ifndef __BLINK_TASK__ | ||
#define __BLINK_TASK__ | ||
|
||
#include "kernel/Task.h" | ||
#include "components/api/Led.h" | ||
|
||
class BlinkTask: public Task { | ||
|
||
int pin; | ||
Light* led; | ||
enum { ON, OFF} state; | ||
|
||
public: | ||
|
||
BlinkTask(int pin); | ||
void init(int period); | ||
void tick(); | ||
}; | ||
|
||
#endif |