Anybody have any idea why this works. Specifically the "os.system("sudo shutdown now -P")" and "raise SystemExit" bit.
Code:
b=(200) # brightness
s=(0.065) # scroll speed
x=(100)

def clamp(value, min_value=75, max_value=255):
    return min(max_value, max(min_value, value))

def pushed_up(event):
    global b
    if event.action != ACTION_PRESSED:
        b = clamp(b - 5)

def pushed_down(event):
    global b
    if event.action != ACTION_PRESSED:
        b = clamp(b + 5)

def pushed_left(event):
    global x
    if event.action != ACTION_PRESSED:
        x = clamp(x + 10)
        
def pushed_right(event):
    global x
    if event.action != ACTION_PRESSED:
        x = clamp(x - 10)        

sense.stick.direction_up = pushed_up
sense.stick.direction_down = pushed_down
sense.stick.direction_left = pushed_left
sense.stick.direction_right = pushed_right

    if x > 100:
        os.system("sudo shutdown now -P")
    elif x < 100:
        raise SystemExit
But this won't? Stick right and stick left do nothing? Up down works in both examples.

Code:
def clamp(value, min_value=75, max_value=255):
    return min(max_value, max(min_value, value))

def pushed_up(event):
    global b
    if event.action != ACTION_PRESSED:
        b = clamp(b - 5)

def pushed_down(event):
    global b
    if event.action != ACTION_PRESSED:
        b = clamp(b + 5)

def pushed_left(event):
    if event.action != ACTION_RELEASED:
        os.system("sudo shutdown now -P")
        
def pushed_right(event):
    if event.action != ACTION_RELEASED:
        raise SystemExit        

sense.stick.direction_up = pushed_up
sense.stick.direction_down = pushed_down
sense.stick.direction_left = pushed_left
sense.stick.direction_right = pushed_right