I am trying to build a 36-line cable tester, using the Digistump DigiX (99 i/o pins). Digital pins 0-35 are outputs, connected via the cable in question, to (in a perfect world) digital input pins 36-72. The plan is to have 36 neopixels (to conserve DigiX pins), one corresponding to each line in the cable. Currently they light up green for connection and red for no connection.
It's easy to check if output 0 goes to input 36, but there are more potential problems in a cable than no connection...
What if there is a short and output 0 goes to 36 and 42? It will still show up as correct when it tests 0 to 36... I somehow need to "ask" it what, if any, inputs (pins 36-72) are HIGH when only output 0 is HIGH.
I'm not sure how I'm going to display this extra data yet (Lcd maybe? Or maybe any pins shorted together all use a unique led color...), but I want to make sure the idea will work before I move on to that. Here is what I have working so far, just using a 3-line cable for now. And yes, I'm new to this. Any advice would be greatly appreciated!
#include <FastLED.h>
#define NUM_LEDS 3
#define LED_PIN 6
CRGB leds[NUM_LEDS];
#define brightness 25
int var = 0;
void setup() {
for (int sendPins=0; sendPins <= 2; sendPins++) {
pinMode(sendPins, OUTPUT); }
for (int recPins=3; recPins <= 5; recPins++) {
pinMode(recPins, INPUT); }
FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, NUM_LEDS);
FastLED.clear();
}
void loop() {
while (var < 3) { //so it only runs once for each line in the cable.
var++;
for (int sendPins=0; sendPins < 3; sendPins++) {
digitalWrite(sendPins, HIGH);
int recPins = map(sendPins, 0, 2, 3, 5); //made more sense to me than another for loop.
int recPin = digitalRead(recPins);
if (recPin == HIGH)
{
leds[sendPins].g = brightness;
leds[sendPins].r = 0;
FastLED.show();
}
else
{
leds[sendPins].r = brightness;
leds[sendPins].g = 0;
FastLED.show();
}
digitalWrite(sendPins, LOW);
delay(250); //just for testing so i know it's going through them all.
}
}
}