Created
January 24, 2026 12:55
-
-
Save wilyJ80/3828707a77dfd86941df05dd9f28df83 to your computer and use it in GitHub Desktop.
leds
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
| class Led { | |
| public: | |
| Led(byte pinNo) : _pinNo(pinNo), _prev(0) { | |
| pinMode(_pinNo, OUTPUT); | |
| } | |
| void update(unsigned const long interval); | |
| private: | |
| byte _pinNo; | |
| unsigned long _prev; | |
| }; | |
| void Led::update(unsigned const long interval) { | |
| unsigned long cur = millis(); | |
| if (cur - _prev > interval) { | |
| digitalWrite(Led::_pinNo, !digitalRead(Led::_pinNo)); | |
| _prev = cur; | |
| } | |
| } | |
| void setup() { | |
| } | |
| void loop() { | |
| static Led red(4); | |
| red.update(50); | |
| static Led yellow(16); | |
| yellow.update(500); | |
| static Led green(17); | |
| green.update(5000); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment