示例#1
0
def show_text(string, font_name='courB24', font_width=15, font_height=24):
    lcd = Display()
    lcd.clear()
    strings = wrap(string, width=int(180/font_width))
    for i in range(len(strings)):
        x_val = 89-font_width/2*len(strings[i])
        y_val = 63-(font_height+1)*(len(strings)/2-i)
        lcd.text_pixels(strings[i], False, x_val, y_val, font=font_name)
    lcd.update()
示例#2
0
def show_text(string,
              font_name='courB24',
              font_width=15,
              font_height=24):  # A function to show text on the robot's screen
    '''Function to show a text on EV3 screen.
    This code is copied from ev3python.com'''
    lcd = Display()  # Defining screen
    lcd.clear()  # Clearing the screen so there isnt already text
    strings = wrap(string, width=int(180 / font_width))  #
    for i in range(len(strings)):
        x_val = 89 - font_width / 2 * len(strings[i])
        y_val = 63 - (font_height + 1) * (len(strings) / 2 - i)
        lcd.text_pixels(strings[i], False, x_val, y_val, font=font_name)
    lcd.update()
示例#3
0
文件: demo.py 项目: dkinneyBU/EV3
def display_different_fonts():
    lcd = Display()
    sound = Sound()

    def show_for(seconds):
        lcd.update()
        sound.beep()
        sleep(seconds)
        lcd.clear()

    # Try each of these different sets:
    style = 'helvB'
    #style = 'courB'
    #style = 'lutBS'

    y_value = 0
    str1 = ' The quick brown fox jumped'
    str2 = '123456789012345678901234567890'
    for height in [10, 14, 18, 24]:
        text = style + str(height) + str1
        lcd.text_pixels(text, False, 0, y_value, font=style + str(height))
        y_value += height + 1  # short for  y_value = y_value+height+1
        lcd.text_pixels(str2, False, 0, y_value, font=style + str(height))
        y_value += height + 1
    show_for(6)

    strings = []  # create an empty list
    # Screen width can accommodate 12 fixed
    # width characters with widths 14 or 15
    #               123456789012
    strings.append(style + '24 The')
    strings.append('quick brown ')
    strings.append('fox jumps   ')
    strings.append('over the dog')
    strings.append('123456789012')

    for i in range(len(strings)):
        lcd.text_pixels(strings[i], False, 0, 25 * i, font=style + '24')
    show_for(6)
示例#4
0
ts = TouchSensor()
lcd = Display()
sound = Sound()


def play_welcome():
    global Distance
    while loop == True:  # repeat until 'loop' is set to False in the main thread.
        Distance = us.value()
        if Distance < 400:
            lcd.text_pixels('Welcome', x=40, y=50, font='courB24')
            lcd.update()
            sleep(0.2)
        else:
            sleep(0.1)


loop = True
t = Thread(target=play_welcome)
t.start()
sound.beep()
while True:

    if ts.is_pressed == True:
        lcd.text_pixels('Ignition', x=40, y=70, font='courB24')
        lcd.update()
        sleep(0.2)
        sleep(1)
    else:
        sleep(0.01)
示例#5
0
#!/usr/bin/env python3
from ev3dev2.display import Display
from textwrap import wrap
from time import sleep
lcd = Display()
lcd.clear()
style = 'lutBS24'
string = 'What a wonderful world! Is it good day? Cool Okey'
strings = wrap(string, width=12)
y_value = 0
for i in range(len(strings)):
    lcd.text_pixels(strings[i], False, 0, y_value, font=style)
    y_value += 24
lcd.update()
lcd.update()
sleep(20)
lcd.clear()
示例#6
0
#!/usr/bin/env python3
from ev3dev2.motor import OUTPUT_B, OUTPUT_C, MoveSteering
from ev3dev2.sensor.lego import TouchSensor, UltrasonicSensor
from ev3dev2.button import Button
from time import sleep
from ev3dev2.sound import Sound
from threading import Thread
from ev3dev2.display import Display
us = UltrasonicSensor()
us.mode = 'US-DIST-CM'
ts = TouchSensor()
lcd = Display()
sound = Sound()
sound.beep()
btn = Button()
while True:
    Distance = us.value()
    if ts.is_pressed == True and Distance < 400 and btn.wait_for_pressed(
            'left'):
        lcd.text_pixels('Motor Start& Idle', x=0, y=60, font='courB14')
        lcd.update()
        sound.beep()
        sleep(0.2)
        sleep(1)
    else:
        sleep(0.01)
示例#7
0
log.info('prepare for the initial position')
# prepare for the initial position
# detect the upper position of the lifter
lm_lifter.on( -100, brake=True)
while( not ts.is_pressed ):
	sleep(0.05)
# approaching the initial position with high speed
lm_lifter.on_for_rotations(90, 7)
# nearly approached the initial position, approaching with lower speed
lm_lifter.on_for_degrees(20, 240)

# clear the lcd display
lcd.clear()

# show the steps
lcd.text_pixels( str(steps), True, 80, 50, font='courB18')
lcd.update()

log.info('wait user to supply the steps')
# wait user to supply the steps to go
while( True ):
	if(not btn.buttons_pressed):
		sleep(0.01)
		continue

	if btn.check_buttons(buttons=['up']):
		steps += 1
	elif(btn.check_buttons(buttons=['down']) ):
		steps -= 1
		if( steps < 0 ):
			steps = 0
示例#8
0
#!/usr/bin/env python3
from ev3dev2.sensor.lego import UltrasonicSensor
from ev3dev2.display import Display
from ev3dev2.sound import Sound
from time import sleep
lcd = Display()
us = UltrasonicSensor()
sound = Sound()
sound.beep()
while True:
    distance = us.distance_centimeters
    lcd.text_pixels(str(distance) + ' cm', x=40, y=50, font='courB24')
    lcd.update()
    sleep(0.1)
示例#9
0
    sound.beep()
    sleep(seconds)
    lcd.clear()


# Try each of these different sets:
style = 'helvB'
#style = 'courB'
#style = 'lutBS'

y_value = 0
str1 = ' The quick brown fox jumped'
str2 = '123456789012345678901234567890'
for height in [10, 14, 18, 24]:
    text = style + str(height) + str1
    lcd.text_pixels(text, False, 0, y_value, font=style + str(height))
    y_value += height + 1  # short for  y_value = y_value+height+1
    lcd.text_pixels(str2, False, 0, y_value, font=style + str(height))
    y_value += height + 1
show_for(6)

strings = []  # create an empty list
# Screen width can accommodate 12 fixed
# width characters with widths 14 or 15
#               123456789012
strings.append(style + '24 The')
strings.append('quick brown ')
strings.append('fox jumps   ')
strings.append('over the dog')
strings.append('123456789012')
示例#10
0
#!/usr/bin/env python3
from ev3dev2.button import Button
from ev3dev2.display import Display
from ev3dev2.sound import Sound

btn = Button()
sound = Sound()
lcd = Display()
sound.beep()
while True:
    '''btn.wait_for_bump('left')
     lcd.text_pixels('left', x=40, y=50, font='courB24')
     lcd.update()
     sleep(1)
     sound.beep()'''
    '''btn.wait_for_pressed(['up', 'down'])
     lcd.text_pixels('up or down', x=40, y=50, font='courB24')
     lcd.update()
     sleep(1)
     sound.beep()'''
    btn.wait_for_bump('right')
    lcd.text_pixels('right', x=40, y=50, font='courB24')
    lcd.update()
    sleep(1)
    sound.beep()