Today we’ll go over how to use a web-based Sense HAT emulator! We’ll take a look at both the web-based and desktop versions of Sense HAT emulators.
The first release was the browser version of the emulator. The official Raspberry Pi website describes that the emulator is intended for people who own a Raspberry Pi but not a Sense HAT. So even though you don’t physically own the Sense HAT, you can test and play using the emulator.
Figure 1
Figure 1 shows the initial screen of the emulator. It’s also embedded on the official Raspberry Pi website blog.
Code-Example
1 2 3 4 5 |
from sense_hat import SenseHat sense = SenseHat() red = (255, 0, 0) sense.show_message("How cool is this?", text_colour = red) |
The above 5-line code will display the message “How cool is this?” in red color, as shown in the video below. Please refer to The Sense HAT Add-On Board For Raspberry Pi – Operating The LED Display for details on LED display, including the show_message function.)
This screen is an editor, so you can also edit other programs.
In the video, the default text color was set to red. The second time I edited the source code in the editor and changed the color to blue, and now the texts are displayed in blue.
Figure 2
To run the program, click the play (“View the result”) button in the menu bar above. Then a screen with a virtual Raspberry Pi connected to a Sense HAT appears and the contents of the program are displayed.
To return to the code editor screen, click the pen icon to the left of the play button.
You can also adjust the sliders above to change the sensor values of the simulated temperature, pressure, and humidity.
There is also a button to change the direction of the main body. You can operate the joystick with the arrow keys and enter key on the keyboard.
Joystick input is possible only during the program execution. Otherwise, you’ll just see your browser page scrolled up and down…
The browser version of the emulator seems to be slightly incompatible with Firefox; processing is slow and it often freezes. Chrome is recommended!