Skip to content

Instantly share code, notes, and snippets.

@hemmer
Last active September 29, 2021 15:29
Show Gist options
  • Save hemmer/1325709841602d210884e9f20bc1b62e to your computer and use it in GitHub Desktop.
Save hemmer/1325709841602d210884e9f20bc1b62e to your computer and use it in GitHub Desktop.
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));
}
@hemmer
Copy link
Author

hemmer commented Sep 29, 2021

PXL_20210929_152700429

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment