Question: Python.I'm using a raspberry pi. What is code that will exit the program when you push on the joystick using a global variable. This isn't

Python.I'm using a raspberry pi. What is code that will exit the program when you push on the joystick using a global variable. This isn't working.

def pushed_middle(event): global x if event.action == ACTION_PRESSED: x = 0 sense.stick.direction_middle = pushed_middle while True: if x == 0: sense.clear() os.system("sudo shutdown now -P") time.sleep(5) elif x == 1: sense.clear() raise SystemExit time.sleep(5)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!