The_Official_Raspberry_Pi_-_Beginner’s_Book_Vol1,_2018 (1)

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

THE OFFICIAL RASPBERRY PI BEGINNER’S GUIDE


ptemp = sense.get_temperature_from_pressure()
temp = (htemp + ptemp) / 2
print(temp)

Click the Run icon, and you’ll see a number printed to the Python console (Figure 7-24). This
time, it’s based on readings from both sensors, which you’ve added together and divided by
two – the number of readings – to get an average of both. If you’re using the emulator, all three
methods – humidity, pressure, and average – will show the same number.


5 Figure 7-24: A temperature based on the readings from both sensors


CHALLENGE: SCROLL & LOOP
Can you change your program to take a reading from each
of the sensors in turn, then scroll them across the LED
matrix rather than printing them to the shell? Can you make
your program loop, so it’s constantly printing the current
environmental conditions?
Free download pdf