// https://forum.arduino.cc/t/binary-counter-led-project-issue/1438696
//
int ledPin[4] = {10, 11, 12, 13};
const int loopDelay = 577;
int loopCounter = 0;
//bool writeValueLed[4];
int numArray[4][8] = {
{0, 2, 4, 6, 8, 10, 12, 14},
{0, 1, 4, 5, 8, 9, 12, 13},
{0, 1, 2, 3, 8, 9, 10, 11},
{0, 1, 2, 3, 4, 5, 6, 7}
};
// for use in digital read and write
const bool OFF = false;
const auto ON = true;
void setup() {
Serial.begin(115200);
Serial.println("\nwhat does it do?\n");
for (byte ii = 0; ii < 4; ii++)
pinMode(ledPin[ii], OUTPUT);
}
void loop() {
static unsigned long lastTime = millis() - loopDelay;
unsigned long now = millis();
if (now - lastTime < loopDelay) return; // not time for next step
lastTime += loopDelay;
Serial.print("loopCounter = ");
Serial.println(loopCounter);
for (byte theBit = 0; theBit < 4; theBit++) {
bool onOrOff = true; // unless proven otherwise
for (int i = 0; i < 8; i++) {
if (numArray[theBit][i] == loopCounter) {
onOrOff = false;
break;
}
}
digitalWrite(ledPin[theBit], onOrOff ? ON : OFF);
}
loopCounter++;
if (loopCounter >= 16) loopCounter = 0;
}
/*
for (byte ii = 0; ii < 16; ii++) {
}
*/