def __init__(self): # Start-up in 'paused' mode and # handle button presses to exit paused mode red.on() green.off() #from rcpy.button import modeAI, pauseAI button.ButtonEvent.__init__(self, pause, button.ButtonEvent.PRESSED)
def toggle(self): self.state = not self.state if self.state: red.on() green.off() else: green.on() red.off()
def action(self, event): global paused paused = not paused if paused: red.on() green.off() else: green.on() red.off()
def PushLights(): # Get rcpy running rcpy.set_state(rcpy.RUNNING) # Welcome message print("=" * 65) print("Welcome to PressyLights!") print( "Press <PAUSE> to turn on the red light, or <MODE> to turn on the green light." ) print("Press both <PAUSE> and <MODE> to exit.") print("-" * 65) # Main loop while not (mode.is_pressed() and pause.is_pressed()): if pause.is_pressed(): red.on() green.off() elif mode.is_pressed(): red.off() green.on() # Exit message print("Bye Beaglebone!") print("=" * 65) red.off() green.off()
def __init__(self): # Start-up in 'paused' mode and handle button presses to exit paused mode red.on() green.off() #button.ButtonEvent.__init__(self, pause, button.ButtonEvent.PRESSED) button.ButtonEvent.__init__(self, pauseAI, button.ButtonEvent.PRESSED)
# Redirect input/output to a socket SOCK_OUT = 3001 SOCK_IN = 3002 sock_out = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock_out.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock_out.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) sock_out.connect(("255.255.255.255", SOCK_OUT)) sys.stdout = sock_out.makefile('w', buffering=None) #sock_in = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) #sock_in.connect(("127.0.0.1", SOCK_IN)) #sys.stdin = sock_in.makefile('r', buffering=None) # Start-up in 'paused' mode and handle button presses to exit paused mode paused = True red.on() green.off() class PauseButtonEvent(button.ButtonEvent): def action(self, event): global paused paused = not paused if paused: red.on() green.off() else: green.on() red.off() pause_event = PauseButtonEvent(pause, button.ButtonEvent.PRESSED)