Created
October 3, 2018 14:25
-
-
Save FrankBuss/05b0a41491575d5e849dd9df924cf2a4 to your computer and use it in GitHub Desktop.
general class to simplify the syntax to write to a pin
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
class PinOut { | |
public: | |
PinOut(uint8_t pin): m_pin(pin) { | |
pinMode(pin, OUTPUT); | |
} | |
PinOut& operator= (uint8_t state) { | |
digitalWrite(m_pin, state ? HIGH : LOW); | |
return *this; | |
} | |
private: | |
uint8_t m_pin; | |
}; | |
// example usage: create a "led" object, which uses the pin number LED_BUILTIN | |
PinOut led(LED_BUILTIN); | |
void setup() {} | |
// much easier to read "blinking" example | |
void loop() { | |
led = 1; | |
delay(1000); | |
led = 0; | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment