Last active
September 29, 2021 15:29
-
-
Save hemmer/1325709841602d210884e9f20bc1b62e to your computer and use it in GitHub Desktop.
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
const int numLEDS = 4; | |
const int LEDs[numLEDS] = {5, 6, 3, 9}; | |
int binaryVariable = 0; | |
void setup() { | |
// put your setup code here, to run once: | |
for (int k = 0; k < numLEDS; k++) { | |
pinMode(LEDs[k], OUTPUT); | |
analogWrite(LEDs[k], 0); | |
} | |
} | |
void loop() { | |
int sequenceSpeed = 100; | |
int brightness = min(255, binaryVariable * 10); | |
for (int k = 0; k < numLEDS; k++) { | |
int mask = 1 << k; | |
int maskedbinaryVariable = binaryVariable & mask; | |
bool isBitActive = maskedbinaryVariable >> k; | |
analogWrite(LEDs[k], isBitActive ? brightness : 0 ); | |
} | |
delay(sequenceSpeed); | |
binaryVariable = (binaryVariable + 1) % int(pow(2, numLEDS)); | |
} |
Author
hemmer
commented
Sep 29, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment