i was looking through the tutorial on interfacing arduino with a QT401 sensor. there are some commands and syntaxes that i totally don't understand and can't seem to find in the reference guide. is anyone able to explain to me what they mean?
the complete segment of code that i'm quoting from is included below if you want to see the context...
ok, first up:
byte qt401_transfer(byte data_out)
what does the bit in brackets refer to? i thought variable declaration just took the format type variableToDefine = value; - the example above looks to me like some kind of nested declaration or a function call...
second question:
while(0 < i) {
mask = 0x01 << --i
hmmmm... i'm really stumped on this one. what do "<<" and "--" mean?
third question:
if(data_out & mask){
i couldn't find any reference to "&" as a logical operator in the reference guide... how does it work?
number four:
data_in |= mask
is this just an error and meant to be "!=" (ie, not equal to)...?
lastly, number five:
return data_in;
i can't find any reference to "return" as a command....
well, sorry these are probably such basic questions. but this bit of code looks like something that will be useful for a project i'm starting, so i'd love to actually be able to understand it properly...
is there a more extensive arduino 0007 reference guide somewhere?
thanks to anyone who can help me out!
jon.
(here's the snippet of code i'm referencing)
//
// exchange a byte with the sensor
//
byte qt401_transfer(byte data_out)
{
byte i = 8;
byte mask = 0;
byte data_in = 0;
digitalWrite(qt401_ss,LOW); // select slave by lowering ss pin
delayMicroseconds(75); //wait for 75 microseconds
while(0 < i) {
mask = 0x01 << --i; // generate bitmask for the appropriate bit MSB first
// set out byte
if(data_out & mask){ // choose bit
digitalWrite(qt401_do,HIGH); // send 1
}
else{
digitalWrite(qt401_do,LOW); // send 0
}
// lower clock pin, this tells the sensor to read the bit we just put out
digitalWrite(qt401_clk,LOW); // tick
// give the sensor time to read the data
delayMicroseconds(75);
// bring clock back up
digitalWrite(qt401_clk,HIGH); // tock
// give the sensor some time to think
delayMicroseconds(20);
// now read a bit coming from the sensor
if(digitalRead(qt401_di)){
data_in |= mask;
}
// give the sensor some time to think
delayMicroseconds(20);
}
delayMicroseconds(75); // give the sensor some time to think
digitalWrite(qt401_ss,HIGH); // do acquisition burst
return data_in;
}