public void Print(string message, Color background, Color foreground) { if (senseHat == null) { return; } // Get the characters to scroll. IEnumerable <SingleColorCharacter> characters = font.GetChars(message); // Create the character renderer. SingleColorCharacterRenderer characterRenderer = new SingleColorCharacterRenderer(_ => foreground); // Create the text scroller. var textScroller = new TextScroller <SingleColorCharacter>( senseHat.Display, characterRenderer, characters); while (textScroller.Step()) { // Draw the background. senseHat.Display.Fill(background); // Draw the scroll text. textScroller.Render(); // Update the physical display. senseHat.Display.Update(); // Pause for a short while. waitEvent.Wait(TimeSpan.FromMilliseconds(50)); } }
public override void Run() { // Get a copy of the rainbow colors. SenseHat.Display.Reset(); SenseHat.Display.CopyScreenToColors(_rainbowColors); // Recreate the font from the serialized bytes. SingleColorFont font = SingleColorFont.Deserialize(FontBytes); // Get the characters to scroll. IEnumerable <SingleColorCharacter> characters = font.GetChars(_scrollText); // Create the character renderer. SingleColorCharacterRenderer characterRenderer = new SingleColorCharacterRenderer(GetCharacterColor); // Create the text scroller. var textScroller = new TextScroller <SingleColorCharacter>( SenseHat.Display, characterRenderer, characters); while (true) { // Step the scroller. if (!textScroller.Step()) { // Reset the scroller when reaching the end. textScroller.Reset(); } // Draw the background. FillDisplay(textScroller.ScrollPixelOffset); // Draw the scroll text. textScroller.Render(); // Update the physical display. SenseHat.Display.Update(); // Should the drawing mode change? if (SenseHat.Joystick.Update() && (SenseHat.Joystick.EnterKey == KeyState.Pressing)) { // The middle button is just pressed. SwitchToNextScrollMode(); } // Pause for a short while. Sleep(TimeSpan.FromMilliseconds(50)); } }
private async void StartScrollInternal() { try { SenseHat = await SenseHatFactory.GetSenseHat(); } catch { } if (SenseHat == null) { return; } SenseHat.Display.Direction = DisplayDirection.Deg270; // Get a copy of the rainbow colors. SenseHat.Display.Reset(); SenseHat.Display.CopyScreenToColors(_rainbowColors); // Recreate the font from the serialized bytes. SingleColorFont font = SingleColorFont.Deserialize(FontBytes); // Get the characters to scroll. IEnumerable <SingleColorCharacter> characters = font.GetChars(_scrollText); // Create the character renderer. SingleColorCharacterRenderer characterRenderer = new SingleColorCharacterRenderer(GetCharacterColor); // Create the text scroller. var textScroller = new TextScroller <SingleColorCharacter>( SenseHat.Display, characterRenderer, characters); while (true) { if (this.scrollTaskCancellationTokenSource.IsCancellationRequested) { SenseHat.Display.Clear(); SenseHat.Display.Update(); break; } // Step the scroller. if (!textScroller.Step()) { // Reset the scroller when reaching the end. textScroller.Reset(); } // Draw the background. FillDisplay(textScroller.ScrollPixelOffset); // Draw the scroll text. textScroller.Render(); // Update the physical display. SenseHat.Display.Update(); // Pause for a short while. await Task.Delay(TimeSpan.FromMilliseconds(50)); } }
public async Task display() { try { _scrollText = "Device Bot - Azure IoT Hub"; // Get a copy of the rainbow colors. senseHat = await SenseHatFactory.GetSenseHat(); senseHat.Display.Reset(); senseHat.Display.CopyScreenToColors(_rainbowColors); // Recreate the font from the serialized bytes. SingleColorFont font = SingleColorFont.Deserialize(FontBytes); // Get the characters to scroll. IEnumerable <SingleColorCharacter> characters = font.GetChars(_scrollText); // Create the character renderer. SingleColorCharacterRenderer characterRenderer = new SingleColorCharacterRenderer(GetCharacterColor); // Create the text scroller. var textScroller = new TextScroller <SingleColorCharacter>( senseHat.Display, characterRenderer, characters); while (true) { // Step the scroller. if (!textScroller.Step()) { // Reset the scroller when reaching the end. textScroller.Reset(); } // Draw the background. FillDisplay(textScroller.ScrollPixelOffset); // Draw the scroll text. textScroller.Render(); // Update the physical display. senseHat.Display.Update(); // Should the drawing mode change? if (senseHat.Joystick.Update() && (senseHat.Joystick.EnterKey == KeyState.Pressing)) { // The middle button is just pressed. SwitchToNextScrollMode(); } // Pause for a short while. //Task.wait(TimeSpan.FromMilliseconds(50)); await Task.Delay(500); } } catch (Exception ex) { throw ex; } }