Hi.
I've been trying out bit functions.
This is my current state of code:
byte outputBufferA[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte outputBufferB[16] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
int bitPosA[16] = { 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3 };
int bitPosB[16] = { 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3 };
void setup() {
Serial.begin(115200);
Serial.println("READY!");
}
void loop() {
for (int i = 0; i < 16; i++) {
outputBufferA[i] = bitSet(outputBufferA[i], bitPosA[i]);
outputBufferB[i] = bitClear(outputBufferB[i], bitPosB[i]);
Serial.println(outputBufferA[i], BIN);
Serial.println(outputBufferB[i], BIN);
delay(1000);
}
}
What I am trying to achieve is that every time the loop is run, eventually all of each buffer is filled with '0's or '1's depending on which array they are set to (IE. outputBufferA - HIGH / outputBufferB - LOW).
However, the readouts via serial just shifts the 0/1 across to the relevant position, and does not retain the change from the previous write..
How do I achieve what I have set out to do?
Thanks in advance.
All the best!!