# Activamos curses para controlar la impresion screen = curses.initscr() # Cogemos el cursor curses.noecho() # Desactivamos el echo del input curses.cbreak() # Reconocemos inmediatamente las teclas screen.keypad(True) # Reconocemos teclas "especiales" try: while True: char = screen.getch() if char == ord('q'): break elif char == curses.KEY_UP: screen.addstr(0, 0, 'Moviendo arriba... ') tilt_motor.move_forward(1) elif char == curses.KEY_RIGHT: screen.addstr(0, 0, 'Vuelta arriba...') tilt_motor.round_forward() elif char == curses.KEY_LEFT: screen.addstr(0, 0, 'Vuelta abajo...') tilt_motor.round_backwards() elif char == curses.KEY_DOWN: screen.addstr(0, 0, 'Moviendo abajo...') tilt_motor.move_backwards(1) finally: tilt_motor.off() curses.nocbreak() screen.keypad(0) curses.echo() curses.endwin()
try: from stepper import Stepper GPIO_PA = 1 GPIO_PA_ = 7 GPIO_PB = 8 GPIO_PB_ = 25 GPIO_SWITCH_FULL = 21 GPIO_SWITCH_EMPTY = 20 print "Initializing Syringe Pump" stepper = Stepper(GPIO_PA, GPIO_PA_, GPIO_PB, GPIO_PB_, GPIO_SWITCH_FULL, GPIO_SWITCH_EMPTY) print "Turning off Stepper" stepper.off() except Exception as ex: print "Error initializing Syringe Pump: " + str(ex) class WebpageResource(object): def on_get(self, req, resp): resp.status = falcon.HTTP_200 resp.content_type = falcon.MEDIA_HTML with open('/home/pi/work/syringePump/static/index.html', 'r') as file: resp.body = file.read() class SyringPumpResource(object): def on_get(self, req, resp): print "Received {} {} request with params {}".format(
screen = curses.initscr() # Cogemos el cursor curses.noecho() # Desactivamos el echo del input curses.cbreak() # Reconocemos inmediatamente las teclas screen.keypad(True) # Reconocemos teclas "especiales" try: while True: char = screen.getch() if char == ord('q'): break elif char == curses.KEY_UP: screen.addstr(0, 0, 'Vuelta...') pan_motor.round_forward() elif char == curses.KEY_RIGHT: screen.addstr(0, 0, 'Moviendo a derecha... ') pan_motor.move_forward(1) elif char == curses.KEY_LEFT: screen.addstr(0, 0, 'Moviendo a izquierda...') pan_motor.move_backwards(1) elif char == curses.KEY_DOWN: screen.addstr(0, 0, 'Vuelta...') pan_motor.round_backwards() finally: pan_motor.off() curses.nocbreak(); screen.keypad(0); curses.echo() curses.endwin()
import RPi.GPIO as GPIO from stepper import Stepper import time motor_base = Stepper("Base", 16, 19, 26) motor_base.set_speed(5) print(motor_base.print_info()) try: for i in range(5): print("14 steps <--") motor_base.move_forward(14) time.sleep(1) print("28 steps -->") motor_base.move_backwards(28) time.sleep(1) print("14 steps <--") motor_base.move_forward(14) time.sleep(1) finally: motor_base.off() print("DONE. All ok?")