Last active
October 25, 2016 14:42
-
-
Save nadavmatalon/92d3e7bccaa0580c9d16213ad8610f67 to your computer and use it in GitHub Desktop.
ARDUINO: Update Specific Bits in a Byte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
byte _config = 0x00; // byte to be updated | |
typedef enum:byte { | |
MODE_MASK = 0x0C, // 12 - B00001100 (set all bits to be changed - and only them - to 1) | |
MODE_1 = 0x00, // 0 - B00000000 (Defualt) | |
MODE_2 = 0x08 // 8 - B00001000 | |
} dev_mode_t; | |
void setDevMode(dev_mode_t newMode) { // PARAMS: MODE_1 / MODE_2 | |
setConfig((_config & ~MODE_MASK) | (newMode & MODE_MASK)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment