def VibrateMotor(): joystick.run_angle(1400, 180) def CompletionVibrate(): indicator.run_time(1400, 700) uart.clear() while True: while not (xBut.pressed() | yBut.pressed()): wait(100) if uart.waiting() > 0: msg = uart.read(1) uart.clear() #should clear automatically, but needed some help msg = str(msg) if msg[2] == 'T': VibrateMotor() print('|', end='') elif msg[2] == 'F': print('.', end='') elif msg[2] == 'C': CompletionVibrate() while (xBut.pressed() | yBut.pressed()): if xBut.pressed(): uart.write('x') #send uart 'x'
#!/usr/bin/env pybricks-micropython from pybricks.hubs import EV3Brick from pybricks.iodevices import UARTDevice from pybricks.parameters import Port from pybricks.media.ev3dev import SoundFile # Initialize the EV3 ev3 = EV3Brick() # Initialize sensor port 2 as a uart device ser = UARTDevice(Port.S2, baudrate=115200) # Write some data ser.write(b'\r\nHello, world!\r\n') # Play a sound while we wait for some data for i in range(3): ev3.speaker.play_file(SoundFile.HELLO) ev3.speaker.play_file(SoundFile.GOOD) ev3.speaker.play_file(SoundFile.MORNING) print("Bytes waiting to be read:", ser.waiting()) # Read all data received while the sound was playing data = ser.read_all() print(data)
rightMotor.run(Motor_input) leftMotor.run(Motor_input) if error < 10: print('Over!') reset() break #Main Code travel = waiting() while travel == 'on': #Checking for obstacles if dist.distance() > 150: Motor_input = -150 if dist.distance() <= 150: Motor_input = -10 #Serial Commands from cam if uart.waiting() >= 1: data = uart.read() if data.decode('utf-8') == 'y': print('Fire') wait(1000) release() break #Keeps Motors rolling rightMotor.run(Motor_input) leftMotor.run(Motor_input) cleanUp()
from pybricks.robotics import DriveBase from pybricks.iodevices import UARTDevice brick.sound.beep() ymotor = Motor(Port.B, Direction.CLOCKWISE) xmotor = Motor(Port.A, Direction.COUNTERCLOCKWISE) hapticmotor = Motor(Port.C, Direction.COUNTERCLOCKWISE) direction = 1 print('????') uart = UARTDevice(Port.S1, 9600, timeout=10000) wait(500) uart.write('a') while uart.waiting() == 0: wait(10) curr = "" previous = 'q' uart.write('q') while True: xangle = xmotor.angle() yangle = ymotor.angle() holder = uart.read(1) #print(str(xangle) + " " + str(yangle)) if yangle > 20 and xangle > 20: curr = 'x' elif yangle > 20 and (xangle < 20 and xangle > -20): curr = 'y' elif yangle > 20 and (xangle < -20): curr = 'z'
#!/usr/bin/env pybricks-micropython #brickrun -r -- pybricks-micropython from pybricks.hubs import EV3Brick from pybricks.tools import wait, StopWatch, DataLog from pybricks.parameters import Color, Port from pybricks.ev3devices import Motor from pybricks.iodevices import AnalogSensor, UARTDevice # Initialize the EV3 ev3 = EV3Brick() ev3.speaker.beep() uart = UARTDevice(Port.S1, 9600, timeout=2000) # short pins 5/6 (blue and yellow) uart.write('Test') wait(10) data = uart.read_all( ) #if you connect Pin 5 & 6 you should see Test on the screen ev3.screen.print(data) uart.write('Test') uart.waiting() # how many bytes on the port uart.read(uart.waiting()) # Turn the light off ev3.light.off()
fobj = open(filename, 'w') for up in range(20): print(up) watch.reset() watch.resume() while watch.time() < 200: robot.drive(20, 0) robot.drive(0, 0) for side in range(80): watchside.reset() watchside.resume() while watchside.time() < 150: minimotor.run(direction * -50) colorcheck(side, up, direction) direction *= -1 while True: colorcheck() direction = 1 if uart.waiting() != 0: holder = uart.read(1).decode("utf-8") print(holder) if holder == 'q': #forward motorspeed = 0 minispeed = 0 #robot.drive(motorspeed,0) #minimotor.run(minispeed) wait(0.1) fobj.close()
ev3 = EV3Brick() uart = UARTDevice(Port.S4, 9600, timeout=200) paddle = Motor(Port.C) belt = Motor(Port.D) pusher = Motor(Port.B) ev3.speaker.beep() wait(500) paddle_closed = 0 message = '' while True: belt.dc(23) pusher.dc(10) try: # uart.write('PLEASE WORK'.encode()) # wait(50) if(uart.waiting() > 1): message = uart.read(1) # print(message) # print(type(message)) # message = message.decode('utf-8') # not too many options on pybricks micropython print("The Message is: ", message) except: # message = uart.read() print("FAILED MESSAGE: ", message) print(type(message)) if(message == b'2' and paddle_closed == 0): paddle.run_angle(100, 90, stop_type = Stop.HOLD, wait = False) belt.run_time(100, 2500) paddle.run_angle(100, -90, stop_type = Stop.HOLD, wait = False) paddle_closed = 1