Ejemplo n.º 1
0
def main(screen):
    curses.start_color()
    curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK) # PAIR 1 = GREEN
    screen.nodelay(1)
    nerves.setup()
    red_LED_status = False
    green_LED_status = False
    while True:
        screen.clear()
        screen.border()
        add_multi_str(screen, 3, 23, '''UP\t- Go forward
DOWN\t- Go backwards
LEFT\t- Rotate counter-clockwise
RIGHT\t- Rotate clockwise
s\t- Stop motors
r\t- Toggles red LED
g\t- Toggles blue LED
q\t- Stop motors and quit''', 1)
        char = screen.getch()
        if char == ord('q'):
            nerves.shutdown()
            break
        elif char == curses.KEY_UP:
            stop_motors()
            nerves.on(nerves.LMF)
            nerves.on(nerves.RMF)
        elif char == curses.KEY_DOWN:
            stop_motors()
            nerves.on(nerves.LMB)
            nerves.on(nerves.RMB)
        elif char == curses.KEY_LEFT:
            stop_motors()
            nerves.on(nerves.LMB)
            nerves.on(nerves.RMF)
        elif char == curses.KEY_RIGHT:
            stop_motors()
            nerves.on(nerves.LMF)
            nerves.on(nerves.RMB)
        elif char == ord('s'):
            stop_motors()
        elif char == ord('r'):
            if red_LED_status:
                nerves.off(nerves.R_LED)
                red_LED_status = False
            else:
                nerves.on(nerves.R_LED)
                red_LED_status = True
        elif char == ord('g'):
            if green_LED_status:
                nerves.off(nerves.G_LED)
                green_LED_status = False
            else:
                nerves.on(nerves.G_LED)
                green_LED_status = True
        time.sleep(0.1)
Ejemplo n.º 2
0
            nerves.on(nerves.RMF)
        elif char == curses.KEY_RIGHT:
            stop_motors()
            nerves.on(nerves.LMF)
            nerves.on(nerves.RMB)
        elif char == ord('s'):
            stop_motors()
        elif char == ord('r'):
            if red_LED_status:
                nerves.off(nerves.R_LED)
                red_LED_status = False
            else:
                nerves.on(nerves.R_LED)
                red_LED_status = True
        elif char == ord('g'):
            if green_LED_status:
                nerves.off(nerves.G_LED)
                green_LED_status = False
            else:
                nerves.on(nerves.G_LED)
                green_LED_status = True
        time.sleep(0.1)
                
                

if __name__ == '__main__':
    try:
        wrapper(main)
    finally:
        nerves.shutdown()
Ejemplo n.º 3
0
def main():
    print "Hello, World! I'm Clyde!"
    nerves.setup()
    nerves.test()
    nerves.shutdown()