Hi,
I did some research in the forum, am still getting confused. Is there a simplest way for dummies like me? Thanks
I have pin13 available on my button switch:
{
if(digitalRead(13))
{
Hi,
I did some research in the forum, am still getting confused. Is there a simplest way for dummies like me? Thanks
I have pin13 available on my button switch:
{
if(digitalRead(13))
{
There's no way this is going to compile. Can you post the whole thing? What are you trying to do, and what's the issue with your current attempt?
I thought so, i did some research. Basically, i have a continuity test sketch that runs 4 pin cable, i want to add same script for 8 pin. I like to toggle in between 4 and 8. As of now i am using 2x arduino 2x display for both. Wish i can do that just 1 with toggle switch.
You mean you have two independent (arduino+display)s, one for each line? And you want to merge that into a single arduino+display unit?
Yes
Alright. It's better if you start by posting what you have coded so far (within code tags), together with a rough schematic of your contraption (a photo of a drawing is OK; a photo of your actual thing, less so).
please see above: #define PIN 4, that's the only thing I change to make a difference codes for 8 pin, 12, e.g.
Thanks
#define PIN 4
int endA[PIN] = {22,24,26,28,}; //pins end A
int endB[PIN] = {23,25,27,29}; //pins endB
int pSwitch = A0;
int pEncA = A1;
int pEncB = A2;
//results
int result[PIN];
int test[PIN];
int counter[PIN];
bool fail;
void setup() {
Serial.begin(9600); //serial used for debugging only
lcd.begin(20, 4);
//setup pins
for (int i = 0; i < PIN; i++) {
pinMode(endA[i], OUTPUT);//set output pins (end A)
pinMode(endB[i], INPUT_PULLUP);//set input pins (end B)
}
pinMode(pSwitch, INPUT_PULLUP);
//lcd.clear();
//lcd.setCursor(0, 1);
//lcd.print("Cable Tester");
//lcd.print("Press Enc p/ Start");
}
void loop() {
//run the test
runTest_4x1();
delay(2000);
}
void runTest_4x1() {
// add space for null terminator
char s[PIN+1] = "0000";
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("USB-ODU Testing...");
lcd.setCursor(0, 1);
// re-initialize reqired variables
fail = false;
for (int i = 0; i < PIN; i++){
result[i] = -1;
test[i] = -1;
counter[i] = -1;
}
for (int i = 0; i < PIN; i++) {
counter[i] = 0;
for (int j = 0; j < 4; j++) {
digitalWrite(endA[i], LOW); //set all outputs to LOW
}
for (int j = 0; j < PIN; j++) { //check for crossed / open circuits vs closed, good, circuits
digitalWrite(endA[j], HIGH); //scan across the inputs in turn
test[i] = digitalRead(endB[i]); //read the output
if (test[i] == 1 && j != i) { //crossed or open circuit
counter[i]++;
result[i] = 8 + j;
}
else if (test[i] == 1 && j == i && result[i] < 8 ) { //Good, closed circuit
result[i] = 0;
}
digitalWrite(endA[j], LOW);
//debugging
/*
Serial.print("test input core ");
Serial.print(i);
Serial.print(" with output core ");
Serial.print(j);
Serial.print(" test =");
Serial.print(test[i]);
Serial.print(" counter =");
Serial.println(counter[i]);
*/
}
Serial.print("Core ");
Serial.print(i);
Serial.print(" result = ");
if (result[i] == 0) {
Serial.println(" 1");
s[i] = '1';
}
else if (counter[i] == 3) { //Total +1 (of conductor/wire)
Serial.println(" O");
s[i] = '0';
fail = true;
}
else {
Serial.println(" X");
s[i] = 'X';
fail = true;
}
}
lcd.print(s);
lcd.setCursor(0, 2);
if (fail) {
Serial.println("BAD CABLE");
lcd.print("BAD CABLE");
}
else {
Serial.println("GOOD CABLE");
lcd.print("GOOD CABLE");
}
Serial.println();
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.