In order to actually run this program on Sense HAT itself, it’s necessary to modify some source code.
Write your code in IDLE as before; there are also a number of examples that can be opened from the emulator’s built-in menu. If you then want to port your code to a physical Sense HAT, you just need to change
at the top of your program. Reverse this if you’re porting a physical Sense HAT program to the emulator, perhaps from one of our educational resources; this step isn’t required in the web version of the emulator.
Basically, it’s necessary to change “sense_emu” to “sense_hat“.
With this in mind, let’s take a closer look at the previous program.
from sense_emu import SenseHat
sense = SenseHat()
green = (0, 255, 0)
white = (255, 255, 255)
humidity = sense.humidity
humidity_value = 64 * humidity / 100
pixels = [green if i < humidity_value else white for i in range(64)]
There is “sense_emu” in the calling part of the program (line 1). When moving Sense HAT main unit, the browser version uses “sense_hat”, and the desktop version uses “sense_emu”. Because the desktop emulator runs the program using IDLE, you need to choose whether to move the Sense HAT itself or start the emulator.
A web-based emulator with an editor is a perfect tool for those who want to get started using Sense HAT immediately. It’s quite for checking and practicing programming. In addition, the biggest advantage of the browser emulator is that you can still test and play without the physical Raspberry Pi device. If you are connected to an Internet with a web browser, you can play with Sense HAT anywhere, anytime!
For those with actual Raspberry Pi device, desktop emulator with more features is recommended. You can easily test your programs using the desktop emulator by changing the source code (i.e. sense_emu to sense_hat).