forked from esp8266/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of Functional and Scheduled option in Ticker lib (esp8…
…266#5030) * Implementation of Functional and Scheduled option in Ticker lib * Update example formatting * More example updates * More updates to example * More updates to example
- Loading branch information
Showing
3 changed files
with
115 additions
and
9 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
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
64 changes: 64 additions & 0 deletions
64
libraries/Ticker/examples/TickerFunctional/TickerFunctional.ino
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,64 @@ | ||
#include "Arduino.h" | ||
#include "Ticker.h" | ||
|
||
#define LED1 2 | ||
#define LED2 4 | ||
#define LED3 12 | ||
#define LED4 14 | ||
#define LED5 15 | ||
|
||
|
||
class ExampleClass { | ||
public: | ||
ExampleClass(int pin, int duration) : _pin(pin), _duration(duration) { | ||
pinMode(_pin, OUTPUT); | ||
_myTicker.attach_ms(_duration, std::bind(&ExampleClass::classBlink, this)); | ||
} | ||
~ExampleClass() {}; | ||
|
||
int _pin, _duration; | ||
Ticker _myTicker; | ||
|
||
void classBlink() { | ||
digitalWrite(_pin, !digitalRead(_pin)); | ||
} | ||
}; | ||
|
||
void staticBlink() { | ||
digitalWrite(LED2, !digitalRead(LED2)); | ||
} | ||
|
||
void scheduledBlink() { | ||
digitalWrite(LED3, !digitalRead(LED2)); | ||
} | ||
|
||
void parameterBlink(int p) { | ||
digitalWrite(p, !digitalRead(p)); | ||
} | ||
|
||
Ticker staticTicker; | ||
Ticker scheduledTicker; | ||
Ticker parameterTicker; | ||
Ticker lambdaTicker; | ||
|
||
ExampleClass example(LED1, 100); | ||
|
||
|
||
void setup() { | ||
pinMode(LED2, OUTPUT); | ||
staticTicker.attach_ms(100, staticBlink); | ||
|
||
pinMode(LED3, OUTPUT); | ||
scheduledTicker.attach_ms_scheduled(100, scheduledBlink); | ||
|
||
pinMode(LED4, OUTPUT); | ||
parameterTicker.attach_ms(100, std::bind(parameterBlink, LED4)); | ||
|
||
pinMode(LED5, OUTPUT); | ||
lambdaTicker.attach_ms(100, []() { | ||
digitalWrite(LED5, !digitalRead(LED5)); | ||
}); | ||
} | ||
|
||
void loop() { | ||
} |