// Номера пинов подключенных устройств
// АЦП проводов
const uint8_t WIRES_NUMBER = 6;
const uint8_t WIRES_PINS[WIRES_NUMBER] = {A0, A1, A2, A3, A6, A7};
// RGB СИДы
const uint8_t RGB_LED_G = 12;
const uint8_t RGB_LED_R = 13;
// Константы
const int16_t ADC_COLOR_TOLERANCE = 40;
const uint8_t WIRES_COLORS_NUMBER = 10;
const int16_t WIRES_COLORS_ADC[WIRES_COLORS_NUMBER] = {0, 93, 185, 327, 414, 512, 704, 844, 931, 1023};
const char* WIRES_COLORS[WIRES_COLORS_NUMBER] = {
"shorted",
"red & blue",
"red & white",
"blue & white",
"white",
"blue",
"yellow",
"red",
"black",
"not connected",
};
void setup() {
// Конфигурируем порты на выход
pinMode(RGB_LED_G, OUTPUT);
pinMode(RGB_LED_R, OUTPUT);
Serial.begin(115200);
}
void loop() {
for (uint8_t i = 0; i < WIRES_NUMBER; i++) {
Serial.print("Wire#");
Serial.print(i + 1);
Serial.print(" is ");
// Определяем цвет провода
uint16_t adcValue = analogRead(WIRES_PINS[i]);
for (uint8_t j = 0; j < WIRES_COLORS_NUMBER; j++) {
if (adcValue < WIRES_COLORS_ADC[j] + ADC_COLOR_TOLERANCE && adcValue >= WIRES_COLORS_ADC[j] - ADC_COLOR_TOLERANCE) {
Serial.println(WIRES_COLORS[j]);
}
}
}
Serial.println("-----------------");
while(true);
}
Сей девайс эмулирует сигнал --->
с резистивного делителя провода