Help with Formatting payload

I'm trying to use the following flow to control some relays on an Arduino Nano. I sort of understand how the function node is working (I didn't write it), but I'm at a bit of a loss when it comes to bitSet and bitClear and buffers, etc.



I'm able to inject into the hard coded function nodes and the relay turns on and off as expected. However, when I try to pass a variable based on which relay, I'm not able to turn it on, getting a buffer[2] payload instead of the expected buffer[1], but the off functionality works fine.

Flow:
[{"id":"b88301ba.690d18","type":"debug","z":"afead276.d8b918","name":"DEBUG","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":750,"y":110,"wires":[]}]

The end goal is to have input_booleans from Home Assistant controlling the various relays, so if anyone has any suggestions on how to streamline this if I'm going down the wrong path, please let me know.


Thank you!