We have a joystick:bit and a pile of small robotics projects that we want to use it with. It has analogue joystick and 4 buttons.
Streaming the state of the controller to a recieving microbit is giving me a headache. It’s easy enough to send event messages over the radio but what’s the best way to send and receive this information in an efficient way?
If this were a low level language, I’d probably send a bitmask (10 bits for each axis, one for each button) and just unpick it at the other end but I can’t seem to do that sort of binary manipulation in Blocks.
I’m also trying to do this in a way my 8yo daughter can understand.
About the easiest approach is to use the radio blocks key/value pair to transmit and receive messages. Here’s an example: https://makecode.microbit.org/S12420-22805-16246-78148 .
I put both transmit and receive in a single program so you can completely test it in the simulator.
I also made a helper function to make checking for equality of strings a bit easier.
There would be ways to combine things into a single message and get a bit higher throughput, but I’m not sure that it’s necessary in most cases. (Often the response time of motors or the people observing the response is slow enough that sending this sort of tagged type is sufficient)