The_Official_Raspberry_Pi_-_Beginner’s_Book_Vol1,_2018 (1)

(singke) #1
Chapter 7 Physical Computing with the Sense HAT 193

THE OFFICIAL RASPBERRY PI BEGINNER’S GUIDE


These lines assign a sensor to each of the five possible directions on the joystick: up reads
from the orientation sensor; down reads from the magnetometer; left reads from the humidity
sensor; right from the temperature sensor; and pressing the stick in the middle reads from the
pressure sensor.
Finally, you need a main loop so the program will keep listening out for joystick presses and
not just immediately quit. At the very bottom of your program, type the following:


while True:
pass

Click Run, and try moving the joystick to take a reading from one of the sensors
(Figure 7-30). When it has finished scrolling the result, press a different direction.
Congratulations: you’ve built a hand-held tricorder that would make the Federation of
Planets proud!


5 Figure 7-30: Each reading scrolls across the display


For more Sense HAT projects, follow the links in Appendix D, Further reading.
Free download pdf