#include <Arduino.h>
// Define PWM output pins (one side of the cable)
const int pwm_pins[8] = {5, 18, 19, 21, 22, 23, 25, 26};
// Define ADC input pins (other side of the cable)
const int adc_pins[8] = {34, 35, 32, 33, 36, 39, 27, 14};
// Define PWM channels
const int pwm_channels[8] = {0, 1, 2, 3, 4, 5, 6, 7};
// Define duty cycle percentages (10% to 80%)
const int duty_cycles[8] = {32, 64, 96, 128, 160, 192, 224, 255};
// Expected ADC voltage readings (approximate values based on 3.3V)
const float expected_voltages[8] = {0.33, 0.66, 0.99, 1.32, 1.65, 1.98, 2.31, 2.64};
void setup() {
Serial.begin(115200);
// Set up PWM output
for (int i = 0; i < 8; i++) {
ledcSetup(pwm_channels[i], 1000, 8); // 1 kHz, 8-bit resolution
ledcAttachPin(pwm_pins[i], pwm_channels[i]);
ledcWrite(pwm_channels[i], duty_cycles[i]); // Assign unique duty cycles
}
delay(500); // Allow signals to stabilize
}
void loop() {
Serial.println("Checking Wires:");
float measured_voltages[8];
// Read ADC values
for (int i = 0; i < 8; i++) {
int adc_value = analogRead(adc_pins[i]); // Read ADC
measured_voltages[i] = adc_value * (3.3 / 4095.0); // Convert to voltage
}
// Check wire conditions
for (int i = 0; i < 8; i++) {
Serial.print("Wire ");
Serial.print(i + 1);
Serial.print(": ");
Serial.print(measured_voltages[i]);
Serial.print(" V - ");
// Check if wire is cut (0V)
if (measured_voltages[i] < 0.1) {
Serial.println("⚠️ CUT!");
continue;
}
// Check if wire is swapped
bool swapped = true;
for (int j = 0; j < 8; j++) {
if (abs(measured_voltages[i] - expected_voltages[j]) < 0.2) {
swapped = (i != j); // If index doesn't match, it's swapped
break;
}
}
if (swapped) {
Serial.println("⚠️ SWAPPED!");
} else {
Serial.println("✅ OK");
}
}
Serial.println("-------------------");
delay(1000);
}