That's weird, it seems like normal binary backwards? If you can swap the table to normal
like 0001 = 1 not 1000 = 1 then it would line up perfectly no conversion needed
another idea is to compare to the normal value of that like 1000 = 8
so if d1 = 8 (do value 1)
I have an array (generated by a micrometer), that I've pulled out 13 variables, d1 - d13, than can have a value of 0, 1, 2, 4, 6, 8, 9, 10, 12, 14, or 15, that should match up to 0, 8, 4, 2, 6, 1, 9, 5, 3, 7, or 0 respectively. I'm seeing now that the binary intermediate will not be necessary, so this thread should be renamed.
const byte LUT [] = {
0, // 0
8, // 1
4, // 2
0, // 3 not used
2, // 4
0, // 5 not used
6, // 6
0, // 7 not used
1, // 8
9, // 9
5, // 10
0, // 11 not used
3, // 12
0, // 13 not used
7, // 14
0 // 15
};
void setup ()
{
Serial.begin (115200);
for (byte test = 0; test <= 15; test++)
{
Serial.print ("Input of ");
Serial.print (test, DEC);
Serial.print (" gives ");
Serial.println (LUT [test], DEC);
}
}
void loop () {}
Output:
Input of 0 gives 0
Input of 1 gives 8
Input of 2 gives 4
Input of 3 gives 0
Input of 4 gives 2
Input of 5 gives 0
Input of 6 gives 6
Input of 7 gives 0
Input of 8 gives 1
Input of 9 gives 9
Input of 10 gives 5
Input of 11 gives 0
Input of 12 gives 3
Input of 13 gives 0
Input of 14 gives 7
Input of 15 gives 0
So, assuming we have the 13 variables, labeled d1 - d13, how would one submit them (in a loop of some sort?) to the lookup table, and insert the results into another set of variables.
Ok, assuming we have the 13 variables, labeled d0 - d12, how would one submit them (in a loop of some sort?) to the lookup table, and insert the results into another set of variables.
int req = 5; //mic REQ line goes to pin 5 through q1 (arduino high pulls request line low)
int dat = 2; //mic Data line goes to pin 2
int clk = 3; //mic Clock line goes to pin 3
int i = 0; int j = 0; int k = 0;
byte mydata[14];
void setup()
{
Serial.begin(19200);
pinMode(req, OUTPUT);
pinMode(clk, INPUT);
pinMode(dat, INPUT);
digitalWrite(clk, HIGH); // enable internal pull ups
digitalWrite(dat, HIGH); // enable internal pull ups
digitalWrite(req,LOW); // set request at high
}
void loop()
{ // while( digitalRead(clk) == LOW) { } // hold until clock is high
digitalWrite(req, HIGH); // generate set request
// while( digitalRead(clk) == HIGH) { } // hold until clock is low
for( i = 0; i < 13; i++ ) {
k = 0;
for (j = 0; j < 4; j++) {
while( digitalRead(clk) == LOW) { } // hold until clock is high
while( digitalRead(clk) == HIGH) { } // hold until clock is low
//k = (k << 1) | (digitalRead(dat) && 0x1);
k = k | (digitalRead(dat) && 0x1) << ( 3 - j);
}
mydata[i] = k;
Serial.print(k);
}
Serial.println(",");
digitalWrite(req,LOW);
delay(2000); // do a reading every 2 seconds
}