// Charlieplexing LED Tester for a 4-pin, 12-LED Circuit const int ledPins[] = {0, 1, 2, 4}; // pin mapping on the XIAO RP2040: D6=0, D7=1, D8=2, D9=4 const int numPins = 4; // how many pins const int cycleDelay = 250; // how long each led is on for (ms) void setup() { // No setup needed, pin modes set dynamically in the loop } void loop() { // loop iterates through every possible pair of pins: outer loop 'i' sets pin to HIGH, inner loop 'j' sets pin to LOW for (int i = 0; i < numPins; i++) { for (int j = 0; j < numPins; j++) { if (i == j) { // skip when pin is paired with itself continue; } lightUpLED(i, j); // turn on corresponding LED pins delay(cycleDelay); // turn LED on for some time } } } void lightUpLED(int highIndex, int lowIndex) { // highIndex: ledPins array to set HIGH, lowIndex: ledPins array to set LOW for (int i = 0; i < numPins; i++) { // loops through all pins to set their mode (HIGH / LOW) if (i == highIndex) { // anode pin (+) pinMode(ledPins[i], OUTPUT); digitalWrite(ledPins[i], HIGH); } else if (i == lowIndex) { // cathode pin (-) pinMode(ledPins[i], OUTPUT); digitalWrite(ledPins[i], LOW); } else { // all other pins set to INPUT to disconnect them from circuit pinMode(ledPins[i], INPUT); } } }