well, i'm pretty new to programming, so sorry if this seems really basic to some of you...
i want to receive 2 bytes of data from an external chip (Qprox QT300) in single bit pulses, then assemble the received bits into bytes, then send these 2 bytes on to the PC via the usb cable.
the method of getting the individual bits is quite straightforward: 1. set a clock pin output HIGH, the wait a few microseconds. 2. receive a HIGH or LOW bit on a digital pin, and store the value in a variable. 3. set the clock pin output LOW and wait a few microseconds. 4. repeat 16 times (with a short pause in between bytes).
so: now you have 16 zeros or ones, which you might store in an array, or as 16 individual integers, etc. but how do you assemble them into 2 seperate bytes? it seems really clumsy to write a function which steps through each bit in turn an adds them up according to the bit order value (ie 1,1,1,1,1,1,1,1 = 1+2+4+8+16+32+64+128 = 255).
is there an easier or at least more elegant way?? like, if they were stored in an array, is there some function that i'm unaware of that automatically sums the array as a byte value?