Example #1
0
def api_pin(pin_name):
    if request.method == 'PUT':
        if request.json['status'] == 'high':
            nerves.on(pin_name)
        elif request.json['status'] == 'low':
            nerves.off(pin_name)
        return Response('OK', mimetype='text/plain')
    elif request.method == 'GET':
        # Return 501 not implemented error
        abort(501)
Example #2
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)