#include <Arduino.h>
const uint8_t NODES[8] = {2, 3, 4, 5, 6, 7, 8, 9}; // D2–D9 = P0–P7
struct Pair { uint8_t hi, lo; };
// === Build 44 LED pairs (hi ≠ lo), in order ===
const int NUM_LEDS = 44;
Pair LEDS[NUM_LEDS];
void buildCharlieplexMap() {
int index = 0;
for (int i = 0; i < 8 && index < NUM_LEDS; i++) {
for (int j = 0; j < 8 && index < NUM_LEDS; j++) {
if (i != j) {
LEDS[index++] = {NODES[i], NODES[j]};
}
}
}
}
void setHighZ() {
for (uint8_t i = 0; i < 8; i++) {
pinMode(NODES[i], INPUT);
}
}
void lightLED(Pair p) {
setHighZ();
pinMode(p.hi, OUTPUT);
pinMode(p.lo, OUTPUT);
digitalWrite(p.hi, HIGH);
digitalWrite(p.lo, LOW);
}
void setup() {
buildCharlieplexMap();
}
void loop() {
for (int i = 0; i < NUM_LEDS; i++) {
lightLED(LEDS[i]);
delayMicroseconds(300); // Fast scanning = all appear ON
}
}
P0 (D2)
P1 (D3)
P2 (D4)
P3 (D5)
P4 (D6)
P5 (D7)
P6 (D8)