Skip to content

Instantly share code, notes, and snippets.

@fearthecowboy
Created December 9, 2018 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fearthecowboy/157741f5b2993ba5db7be8f1a64baece to your computer and use it in GitHub Desktop.
Save fearthecowboy/157741f5b2993ba5db7be8f1a64baece to your computer and use it in GitHub Desktop.
Blinker Device
#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