losadw.blogg.se

Arduino using wire library
Arduino using wire library









arduino using wire library

For example, imagine pins 2, 7, and 11 were active reg0 would be 10000100, and reg1 would be 00001000.

arduino using wire library

Since reg1 is the MSB value, it needs to be bit-shifted 8 spaces to the left to allow for the LSB value, reg0, to be added on at the end. Uint16_t is the datatype for a number that is 2 bytes (hence the 16, which is the number of bits) and unsigned, which means it can only be positive, and it also means the first bit will not be treated as a sign flag.

arduino using wire library

Then, combine them into a single unsigned int using: Read data from register 0x00 and 0x01, storing the 8-bit values into variables: To combine them into one larger value, the following operation is performed: This means that the data for the 12 pins is split between the two registers. The MPR121 stores pin states (0 or 1) in two bytes, with the LSB (Least Significant Bit) corresponding to either touch-pin 0 or touch-pin 8, since bytes have only 8 bits. For the MPR121, binary touch data is stored in registers 0x00 and 0x01.











Arduino using wire library