Hey everyone,
for a university project, I am trying to synchronize the clocks of two BBC Micro:Bit controllers.
To start, I want one controller to send its system time to the second controller via radio.
For the time calculation, I need the system time in an integer format.
But from my point of view, I can just send the time via radio in a ManagedString format.
This would be my code for the sending controller:
int main()
{
uBit.init();
uBit.radio.enable();while (1) { if (uBit.buttonA.isPressed()) { int b = uBit.systemTime(); ManagedString timestampMaster(b); uBit.radio.datagram.send(timestampMaster); } }
}
And this for the receiving controller:
void onData(MicroBitEvent e)
{
timestampSlave = uBit.systemTime();
ManagedString timestampMaster = uBit.radio.datagram.recv();
offset = timestampMaster - timestampSlave;
}int main()
{
uBit.init();
uBit.radio.enable();
while (1)
{
uBit.messageBus.listen(MICROBIT_ID_RADIO, MICROBIT_RADIO_EVT_DATAGRAM, onData);
}
}
Is it possible to convert the ManagedString format to an integer?
Or is it possible the send and receive data in an integer format directly?
Thank you so much in advance!
Tim