Skip to content

Instantly share code, notes, and snippets.

@giljr
Created June 27, 2018 02:04
Show Gist options
  • Save giljr/9912f9176dfbfe0cfacfcd8dc00b6ef3 to your computer and use it in GitHub Desktop.
Save giljr/9912f9176dfbfe0cfacfcd8dc00b6ef3 to your computer and use it in GitHub Desktop.
LED library implementation see https://www.apress.com/br/book/9781430238829
// LED.cpp - Example library to manipulate LEDs - public domain
#include "LED.h"
// the constructor
LED::LED(byte pin) {
_pin = pin; // save the pin number
pinMode(pin, OUTPUT); // configure pin as output
}
// the public methods
void LED::on() {
digitalWrite(_pin, HIGH); // turn on LED
_state = HIGH;
}
void LED::off() {
digitalWrite(_pin, LOW); // turn off LED
_state = LOW;
}
void LED::toggle() {
if(_state) {
off();
} else {
on();
}
}
byte LED::state() {
return _state;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment