/// <summary> /// Prints a text string on the microbit screen, one character at a time. /// </summary> /// <param name="str">The string to print.</param> /// <param name="durationMs">The duration of time to display each character.</param> /// <param name="brightness">The brightness of the screen.</param> public void PrintText(string str, int durationMs = DefaultPrintSpeed, int brightness = DefaultBrightness) { if (!_port.IsOpen || _status != EDeviceStatus.READY) { return; } if (str.Length == 0 || str.Length > 0xff) { return; } if (durationMs < 0 || durationMs > 0xffff) { return; } if (brightness < 0 || brightness > 0xff) { return; } if (DisplayBusy) { // System.Diagnostics.Debug.WriteLine("Display Busy"); return; } // Block the display int totalDurationMs = str.Length * durationMs; _displayFreeTime = DateTime.Now + TimeSpan.FromMilliseconds(totalDurationMs); MicroBitMessageWriter writer = new MicroBitMessageWriter(); writer.WriteChar(Protocol.CMD_PRINT_TEXT); writer.WriteU16Hex(durationMs); writer.WriteU8Hex(brightness); writer.WriteString(str); QueueForSend(writer.ToString()); }