I have a headless Pi running Raspbian with the Sense HAT attached on top. A portable micro USB charger is attached to the outside of the casing, in order to make the Pi handheld. My classes are currently trying to put together a game where, as one can see in the coding, random responses are given at each shake of the Pi. The main problem comes towards the end of the script, however, since it would be helpful to have the Pi shutdown after four minutes of inactivity.
This is the current script:
import random
import time
from sense_hat import SenseHat
from subprocess import call
sh = SenseHat()
sh.set_rotation(90)
sh.show_message("Let's begin Act I...", text_colour=[0, 50, 220], scroll_speed=.055)
time.sleep(4)
replies = ['Scene 1, Ln 12-3',
'Scene 3, Ln 14-5',
'High five Roman +1',
'Scene 6, Ln 87-9',
'Chicken Dance +2',]
while True:
x, y, z = sh.get_accelerometer_raw().values()
x = abs(x)
y = abs(y)
z = abs(z)
if x > 2 or y > 2 or z > 2 :
sh.show_message(random.choice(replies), text_colour=[0, 50, 220], scroll_speed=.055)
elif x==0 and y==0 and z==0 :
time.delay(240)
sh.show_message("Time to shutdown!", text_colour=[0, 50, 220], scroll_speed=.055)
time.delay(1)
call("sudo nohup shutdown -h now", shell=True)
else:
sh.clear()
Python checks to see if the x, y, and z values for the accelerometer are equal to zero, at which point, the time delay should kick in. In browsing, it seems that perhaps instead of calling to the shutdown command, "os.system()" should be used instead in some way?
Thank you!