Uint8_t trigger meaning

A 'mask' or 'bitmask' is a pattern of bits where the bits you are interested in are '1' and the bits you are not interested in are '0'.

In this case, 'mask' is a single bit calculated by taking the low-order bit (0x01 == 0b00000001) and shifting it to the left (<<) by i-1 bits. The variable 'i' starts at 8 so the first mask is 1<<7 or 0b10000000(==0x80).

The 'mask' is used to select one bit from 'data'. When you use the bitwise AND operator (&) you keep only those bits that are 1 in both. This means that if the top bit of 'data' is 0, the result is 0. If the top bit of 'data' is 1, the result is 0b10000000.

The 'if' statement takes a boolean (true/false) value. When converting a number to boolean, zero == false and any other value == true. The statement 'if (number)' can be read as "if number is not zero".

The end result: If the selected ('masked') bit is 1, execute the 'if' and set the pin to HIGH. If the selected ('masked') bit is 0, execute the 'else' and set the pin to LOW.

1 Like