public SenseHat() { InitSenseHat().Wait(); // Recreate the font from the serialized bytes. font = SingleColorFont.Deserialize(FontBytes); }
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 SenseHat() { try { InitSenseHat().Wait(); } catch (Exception e) { Debug.WriteLine(e.Message); } // Recreate the font from the serialized bytes. font = SingleColorFont.Deserialize(FontBytes); }
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; } }