[Solved]
Hi,
To make your sketch easy to read, can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Not a fritzy diagram, please note pin name/numbers and power supply details.
Tom....
Would you please specify what the following sequence
if (test[n] == 1) {
if(j != n) {
counter[n]++;
result[n] = 8 + j;
}
}
// rephrased from
if (test[n] == 1 && j != n) {
counter[n]++;
result[n] = 8 + j;
} else if (test[n] == 1 && j == n && result[n] < 8 ) { // result[n] always 0 or >= 8
result[n] = 0;
}
is trying to compute?
Did you try something like
byte badCon = bitCount(test[n] & ~seq[n]);
byte noCon = ((test[n] & seq[n]) ? 0 : 1);
byte bitCount(byte bVal) {
byte nBits = 0;
for (byte i = 0; i<8; i++) {
if (bVal & 1) {
nBits++;
}
bVal >>= 1;
}
return nBits;
}
My suggestion tries to compute
- number of shorts in badCon (0 to 7)
by counting all 1-bits that dont belong to the pattern - number of open connections in noCon (can only be 1 or 0 because you check one bit)
by anding sent pattern to received pattern
You code counts/checks something only when the pattern 1 is read back.
Basically you will have to replace the if-construct and its enclosing loop by code that
- computes the testresults (see my example)
- stores the results in your array(s) in the correct format and at the correct place
Probably the description was longer then the code will be.
You still need a loop for the seq[] pattern, the looping for the bit counting is done in bitCount().
-
init results[]
-
for all patterns
-
apply pattern
-
read connections
-
compute result
-
store result- process results[]