Continuity Test

Hi everyone!

I'm currently trying use the Arduino Uno to do a continuity test between multiple ports (pin3,4,5) to one common port(pin2).

On a 4x4 keypad, by pressing 'A', it will perform the continuity for all ports, by pressing '1', it will perform continuity for the first port, so on and so forth. The results will be displayed on a 16x2 LCD.

The continuity test is performed by setting the input to HIGH and reading back on the output.

The test for 'All' ports has been successful to get the results of either 'pass' or 'fail'. However, for the testing of individual ports, the outcome will be displayed as a 'pass' for the first time but subsequently, it will all show 'fail'

I've tried modifying it for quite awhile now to get the intended outcome but am unable to find the error in the code

I would like to seek your help and advice for this issue.

The code is as follows;

#include "Keypad.h"

#include <LiquidCrystal.h>

LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);

const byte Rows= 4; //number of rows on the keypad i.e. 4

const byte Cols= 4; //number of columns on the keypad i,e, 4


char keymap[Rows][Cols]=

{

{'1', '2', '3', 'A'},

{'4', '5', '6', 'B'},

{'7', '8', '9', 'C'},

{'*', '0', '#', 'D'}

};


byte rPins[Rows]= {13,12,11,10}; 

byte cPins[Cols]= {9,8,7,6}; 


Keypad kpd= Keypad(makeKeymap(keymap), rPins, cPins, Rows, Cols);


enum {PASS, FAIL_NOTCONNECTED };

const byte pinsCableBegin[]= { 3, 4 };

const byte pinsCableEnd[]  = { 2, 2 };

const byte NUMCABLES=sizeof(pinsCableBegin);


void setup()

{

     Serial.begin(9600);  

     lcd.begin(16, 2);

}

//to set all input to HIGH

void allPinsInputHigh() 

{ // Button, set all pins to INPUT_PULLUP in a for-loop

  for (byte i=0;i<NUMCABLES;i++)

  {

    pinMode(pinsCableBegin[i],INPUT_PULLUP);

    pinMode(pinsCableEnd[i],INPUT_PULLUP);

  }

}

//to set only port2 input to HIGH
void Port1InputHigh(){ 

    pinMode(pinsCableBegin[0],INPUT_PULLUP);

    pinMode(pinsCableEnd[0],INPUT_PULLUP);

}

//to set only port2 input to HIGH
void Port2InputHigh(){ 

    pinMode(pinsCableBegin[1],INPUT_PULLUP);

    pinMode(pinsCableEnd[1],INPUT_PULLUP);

}



//to test all ports
void DoOneTest()

{

  byte result;

  Serial.println();

  Serial.println("### TEST ###");

  for (byte i=0;i<NUMCABLES;i++) // test each pin

   

  {

    result= PASS; // initially there is no error found, assume PASS

    allPinsInputHigh();

    

    // first test is for continuity and OUTPUT/HIGH

    pinMode(pinsCableBegin[i], OUTPUT);

    if (digitalRead(pinsCableEnd[i])!=HIGH)

    {

        bitSet(result,FAIL_NOTCONNECTED);

    }

    // then check for continuity and OUTPUT/LOW

    digitalWrite(pinsCableBegin[i], LOW);

    if (digitalRead(pinsCableEnd[i])!=LOW)

    {

        bitSet(result,FAIL_NOTCONNECTED);

    }


    Serial.print("Port Q");

    Serial.print(i);

    if (result== PASS){

    Serial.print(" PASS");

    lcd.setCursor (3,i); 

    lcd.print("PASS");

    }

    else {

    Serial.print(" FAIL");

    lcd.setCursor (3,i); 

    lcd.print("FAIL BREAK");

    } 

    

    if (bitRead(result,FAIL_NOTCONNECTED)) Serial.print(" BREAK");

    Serial.println();

  }

  Serial.println();

  Serial.println("Relay Test Completed");

  Serial.println();

}



//to test port 1 only
void TestPort1()

{  byte result;

  Serial.println("### TEST Port1 ###");

 

{

    result= PASS; // initially there is no error found, assume PASS

    Port1InputHigh();

    

    // first test is for continuity and OUTPUT/HIGH

    pinMode(pinsCableBegin[0], OUTPUT);

    if (digitalRead(pinsCableEnd[0])!=HIGH)

    {

        bitSet(result,FAIL_NOTCONNECTED);

    }

    // then check for continuity and OUTPUT/LOW

    digitalWrite(pinsCableBegin[0], LOW);

    if (digitalRead(pinsCableEnd[0])!=LOW)

    {

        bitSet(result,FAIL_NOTCONNECTED);

    }


    Serial.print("Port Q");

    Serial.print(0);

    if (result== PASS){

    Serial.print(" PASS");

    lcd.setCursor (0,0); 

    lcd.print("Q0 PASS");

    }

    

    else {

    Serial.print(" FAIL");

    lcd.setCursor (0,0); 

    lcd.print("Q0 FAIL");

 

    

    if (bitRead(result,FAIL_NOTCONNECTED)) Serial.print(" BREAK");

    Serial.println();

  }

}

  Serial.println();

  Serial.println("Relay Test Completed");

  Serial.println();

}


//to test port 2 only
void TestPort2()

{  byte result;

  Serial.println("### TEST Port2 ###");


    result= PASS; // initially there is no error found, assume PASS

    Port2InputHigh();

    

    // first test is for continuity and OUTPUT/HIGH

    pinMode(pinsCableBegin[1], OUTPUT);

    if (digitalRead(pinsCableEnd[1])!=HIGH)

    {

        bitSet(result,FAIL_NOTCONNECTED);

    }

    // then check for continuity and OUTPUT/LOW

    digitalWrite(pinsCableBegin[1], LOW);

    if (digitalRead(pinsCableEnd[1])!=LOW)

    {

        bitSet(result,FAIL_NOTCONNECTED);

    }


    Serial.print("Port Q");

    Serial.print(1);

    if (result== PASS){

      Serial.print(" PASS");

      lcd.setCursor (0,0); 

     lcd.print("Q1 PASS");

    }

    else {

      Serial.print(" FAIL");

      lcd.setCursor (0,0); 

      lcd.print("Q1 FAIL");

    }

    if (bitRead(result,FAIL_NOTCONNECTED)) {Serial.print(" BREAK");

    Serial.println();

  }

  Serial.println();

  Serial.println("Relay Test Completed");

  Serial.println();

  

}



void loop() {

    char keypressed = kpd.getKey();

  if (keypressed != NO_KEY){

     Serial.println(keypressed);

    if (keypressed == 'A' ){

    lcd.display();

    lcd.clear();

    DoOneTest();

    delay(20);

    

    while (Serial.available()) Serial.read(); // clear Serial input buffer

   

    for (int j = 0; j <= 1; j++)

      {

      lcd.setCursor(0,j);

      lcd.print("Q");

      lcd.setCursor(1,j);

      lcd.print(j);


     delay(500);

    }

  }

  if (keypressed == '1' ){

    lcd.display();

    lcd.clear();

    TestPort1();

    delay(20);

    //while (Serial.available()) Serial.read(); // clear Serial input buffer

  }

 if (keypressed == '2' ){

    lcd.clear();

    TestPort2();

    delay(20);

    //while (Serial.available()) Serial.read(); // clear Serial input buffer

 

  }  

  

  }

}