Hi Everyone,
I'm doing a little CAN display project. As part of it, the equipment I'm wanting to get information out of uses a couple of bytes in a frame for the status of some features on the equipment.
For example, on frame 14, bytes 6-7 so 16bits total.
Bits 15,14,13 show a status of the AntiLag. Bits 12,11 for Launch Control etc.
Reason for up to 4 bits is there can be up to 7 states a feature is in.
Now what I'm having issues with is grouping the bits and getting them to a decimal output so I can then output a return text to the screen depending on the decimal of those bits.
At the moment, I'm using bitread() fine to display a single bit, but I need to group together multiple bits into a data type where I can then use it.
I've tried word() but that isn't workable with bitread, I'm just wondering if there is something simple I'm missing.
Here is the code I'm currently using
word STATUS1 = 0;
int STATUS2 = 0;
void loop() {
CAN0.readMsgBuf(&rxLen, rxBuf); // Read data, rxLen: data length, rxBuf: data buf
unsigned int canId = CAN0.getCanId(); // Check CAN ID
if ((canId == 0x03E8) && (rxBuf[0] == 13)) {
STATUS1 = word(rxBuf[6], rxBuf[7]);
STATUS2 = word((bitRead(STATUS1, 15), bitRead(STATUS1, 14), bitRead(STATUS1, 13)));
}
display.print(STATUS1, BIN); // returns full 16bit binary ok
display.print(STATUS2); // returns 0
I've tested printing the return of a bitRead() by itself, and I do get the correct bit.
I know word isn't correct here but what can I use to combine these 3 bits and give me the decimal?