Created
December 9, 2018 05:52
-
-
Save fearthecowboy/157741f5b2993ba5db7be8f1a64baece to your computer and use it in GitHub Desktop.
Blinker Device
This file contains hidden or 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
#pragma once | |
#include "device.h" | |
// our Blinker class, just blinks a light on and off on continually. | |
class Blinker : public Device { | |
private: | |
bool state = false; | |
public: | |
// constructor -- pass in the interval for flipping the light. | |
Blinker(unsigned long msec) { | |
// standard arduino built-in LED | |
pinMode(LED_BUILTIN, OUTPUT); | |
// tell the scheduler how often we'd like to run. | |
repeat(msec); | |
} | |
protected: | |
// each device gets a 'loop' function that will get called | |
// at the scheduled time. Device writers don't have to do | |
// anything tricky to make this work. | |
void loop() { | |
// in this case, flip the state of the light. | |
digitalWrite(LED_BUILTIN, state = !state); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment