Beispiel #1
0
#!/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)
Beispiel #2
0
#!/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()
Beispiel #3
0
from pybricks.iodevices import AnalogSensor, UARTDevice
import time
import random

ev32 = EV3Brick()

# Initializing the uart device
uart2 = UARTDevice(Port.S1, 9600, timeout=2000)

# Initializing all signals
motorx = Motor(Port.A)
motory = Motor(Port.B)
sensor = ColorSensor(Port.S2)

while True: 
    text =uart2.read_all()
    if text == b'R':
        motorx.run(500)
    elif text == b'L':
        motorx.run(-500)
    elif text == b'N':
        motorx.run(0)
    elif text == b'F':
        motory.run(500)
    elif text == b'B':
        motory.run(-500)
    elif text == b'M':
        motory.run(0)

    # Reading out the sensor data and writing it over UART
    if not (sensor.color()) == Color.WHITE):
Beispiel #4
0
    xangle = motor1.angle()

    # Uses the Read positions to drive the system
    print('x=', xangle)
    print('y=', yangle)
    if xangle > 18:
        x = 'R'
    elif xangle < -18:
        x = 'L'
    else:
        x = 'N'
    if yangle > 18:
        y = 'F'
    elif yangle < -18:
        y = 'B'
    else:
        y = 'M'

    # Writes the signal
    uart.write(x)
    uart.write(y)
    fback = uart.read_all()

    # Runs the system
    if fback == b'W':
        motor3.run(1000)
        wait(0.01)
    elif fback == b'H':
        motor3.run(0)
        wait(.01)