Hello everyone,
I have a project where I need 6 function blocks, each performing the functions of a button (0/1), to send their value in binary via the Serial node. As of now, I'm testing this with just 1 such function block. I have the function block for button 1 set up to send out 00000100 as ON and 00000000 as OFF. My question is, how do I configure the Serial Node to send this as a byte so that it will be compatible with my sketch on Arduino (send as uint8). Here is the bit of the Arduino sketch which is reading the button state:
int switch2;
int switch3;
const uint8_t virtual_switch_masks[8] = {
0,
0,
1<<0, // pin 2: virtual switch 0
1<<1, // pin 3: virtual switch 1
1<<2,
1<<3,
1<<4,
1<<5
// etc...
};
uint8_t virtual_switch_states = 0;
int virtualDigitalRead(uint8_t pin) {
uint8_t mask = virtual_switch_masks[pin];
// If this is not a virtual switch, do a regular digitalRead().
if (!mask)
return digitalRead(pin);
// For a virtual switch, extract the relevant bit
// from virtual_switch_states.
if (virtual_switch_states & mask)
return HIGH;
else
return LOW;
}
void loop(){
if (Serial.available()){
virtual_switch_states = Serial.read();
}
switch2=virtualDigitalRead(2);
digitalWrite(9,switch2);
}
Here's a screenshot of my flow right now.
What you need to know about the pink nodes: The first 2 are simply for initialization. The next one, returns a value between 0-100. Here's a screenshot of my function block 'Button 1':
As per my limited understanding, my LED connected to pin 9, should light up, when the payload from the pink node goes above 50, and the function payload becomes [0,0,0,0,0,1,0,0]. I've set the Serial node output to be binary buffers as well. I don't understand what's wrong.
Please help.