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)); } }
protected override void Execute() { senseHat.Display.Clear(); senseHat.Display.Fill(Colors.White); senseHat.Display.Direction = DisplayDirection.Deg90; var font = SingleColorFont.Deserialize(FontBytes); var characters = font.GetChars("The quick brown fox jumps over the lazy dog. Hello Raspberry Pi. "); var characterRenderer = new SingleColorCharacterRenderer(GetCharacterColor); var textScroller = new TextScroller <SingleColorCharacter>(senseHat.Display, characterRenderer, characters); while (!cancellationTokenSource.Token.IsCancellationRequested) { if (!textScroller.Step()) { textScroller.Reset(); } senseHat.Display.Clear(); textScroller.Render(); senseHat.Display.Update(); waitEvent.Wait(100); } }
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)); } }
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)); } }
public void Write(ISenseHatDisplay display, string twoCharText, Color color, int offsetY = 0) { SingleColorCharacter[] chars = Font.GetChars(twoCharText).ToArray(); if (chars.Length == 0) { return; } if (chars.Length > 2) { throw new ArgumentException("Max two characters are allowed!", nameof(twoCharText)); } var characterRenderer = new SingleColorCharacterRenderer(pixelMap => color); int x = 0; foreach (SingleColorCharacter character in chars) { characterRenderer.Render(display, character, x, offsetY); x += 4; } }
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; } }