Created
June 27, 2018 02:04
-
-
Save giljr/9912f9176dfbfe0cfacfcd8dc00b6ef3 to your computer and use it in GitHub Desktop.
LED library implementation see https://www.apress.com/br/book/9781430238829
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
// 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