![]() |
RUI3 (RAK Unified Interface 3) - RAK4631
|
Macros | |
#define | bitRead(value, bit) (((value) >> (bit)) & 0x01) |
#define | bitSet(value, bit) ((value) |= (1UL << (bit))) |
#define | bitClear(value, bit) ((value) &= ~(1UL << (bit))) |
#define | bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet(value, bit) : bitClear(value, bit)) |
#define | bit(b) (1UL << (b)) |
#define | lowByte(w) ((uint8_t) ((w) & 0xff)) |
#define | highByte(w) ((uint8_t) ((w) >> 8)) |
value | the number from which to read |
bit | which bit to read, starting at 0 for the least-significant (rightmost) bit |
void setup() { Serial.begin(115200); Serial.println("Read the bits of 6(0110)"); Serial.print("bitRead(6, 0) = "); Serial.println(bitRead(6, 0)); //print the first bit of 6 Serial.print("bitRead(6, 1) = "); Serial.println(bitRead(6, 1)); //print the second bit of 6 Serial.print("bitRead(6, 2) = "); Serial.println(bitRead(6, 2)); //print the third bit of 6 Serial.print("bitRead(6, 3) = "); Serial.println(bitRead(6, 3)); //print the fourth bit of 6 } void loop() { }
#define bitSet | ( | value, | |
bit | |||
) | ((value) |= (1UL << (bit))) |
value | the numeric variable whose bit to set |
bit | which bit to set, starting at 0 for the least-significant (rightmost) bit |
void setup() { Serial.begin(115200); Serial.print("Before bitSet(): 6 => "); Serial.println(6, BIN); Serial.print("After bitSet(6, 0) => "); int value = 6; int pos = 0; Serial.println(bitSet(value,pos), BIN); //set the first bit of 6(0110) to 1 } void loop() { }
#define bitClear | ( | value, | |
bit | |||
) | ((value) &= ~(1UL << (bit))) |
value | the numeric variable whose bit to clear |
bit | which bit to clear, starting at 0 for the least-significant (rightmost) bit |
void setup() { Serial.begin(115200); Serial.print("Before bitClear(): 6 => "); Serial.println(6, BIN); Serial.print("After bitClear(6, 1) => "); int value = 6; int pos = 1; Serial.println(bitClear(value,ipos), BIN); // set the second bit of 6(0110) to 0 } void loop() { }
value | the numeric variable to which to write |
bit | which bit of the number to write, starting at 0 for the least-significant (rightmost) bit |
bitvalue | the value to write to the bit (0 or 1) |
void setup() { Serial.begin(115200); int target = 6; // set the bitWrite target to 6 Serial.print("Before bitWrite(): 6 => "); Serial.println(target, BIN); Serial.print("After bitWrite(target, 0, 1) => "); // Set the first bit of target to 1 Serial.println(bitWrite(target, 0,1), BIN); Serial.print("After bitWrite(target, 1, 0) => "); // Set the second bit of target to 0 Serial.println(bitWrite(target, 1,0), BIN); Serial.print("After bitWrite(target, 2, 0) => "); // Set the third bit of target to 0 Serial.println(bitWrite(target, 2,0), BIN); Serial.print("After bitWrite(target, 3, 1) => "); // Set the fourth bit of target to 1 Serial.println(bitWrite(target, 3,1), BIN); Serial.println(""); Serial.println("target now should be 9(1001)"); Serial.print("target = "); Serial.println(target); } void loop() { }
#define bit | ( | b | ) | (1UL << (b)) |
b | the bit whose value to compute |
void setup() { Serial.begin(115200); Serial.print("bit 0: "); Serial.println(bit(0)); Serial.print("bit 3: "); Serial.println(bit(3)); } void loop() { }
#define lowByte | ( | w | ) | ((uint8_t) ((w) & 0xff)) |
w | a value of any type |
void setup() { Serial.begin(115200); Serial.println("Test target 0xABCD"); Serial.print("lowByte() of 0xABCD = "); // extract the low-order byte of the target Serial.println(lowByte(target), HEX); Serial.print("highByte() of 0xABCD = "); // extract the low-order byte of the target Serial.println(highByte(target), HEX); } void loop() { }
#define highByte | ( | w | ) | ((uint8_t) ((w) >> 8)) |
w | a value of any type |
void setup() { Serial.begin(115200); Serial.println("Test target 0xABCD"); Serial.print("lowByte() of 0xABCD = "); // extract the low-order byte of the target Serial.println(lowByte(target), HEX); Serial.print("highByte() of 0xABCD = "); // extract the low-order byte of the target Serial.println(highByte(target), HEX); } void loop() { }