def write_text(text0, text1='', text2='', text3=''): dpl.text_pixels(text0, clear_screen=True, x=10, y=15, text_color='black', font=fonts.load('luBS19')) dpl.text_pixels(text1, clear_screen=False, x=10, y=40, text_color='black', font=fonts.load('luBS19')) dpl.text_pixels(text2, clear_screen=False, x=10, y=65, text_color='black', font=fonts.load('luBS19')) dpl.text_pixels(text3, clear_screen=False, x=10, y=90, text_color='black', font=fonts.load('luBS19')) dpl.update()
def show_text(string, font=fonts.load('luBS14'), font_width=15, font_height=24): lcd.clear() logging.info('Fonts available: {}'.format(fonts.available())) lcd.draw.text((font_width, font_height), string, font=font) lcd.update()
def __init__(self, config): threading.Thread.__init__(self) self.roboId = config['id'] self.threadID = 1 self.name = 'ui-thread' self.isRunning = True self.messageText = '-' self.statusText = '-' self.powerSupplyText = '-' self.lcd = Display() self.btn = Button() self.sound = Sound() self.leds = Leds() self.theFont = fonts.load(Ui.M_FONT) self.lcd.clear() self.drawText() self.lcd.update()
exit() ''' console.reset_console() console.text_at('Hello World!', column=1, row=5, reset_console=True, inverse=True) sleep(2) ''' # 在屏幕上显示字体 if True: #显示有效的Display字体 print(fonts.available(), file=sys.stderr) sleep(2) exit() disp.clear() disp.draw.text((10, 10), 'Hello World!', font=fonts.load('courB18')) disp.update() # 改变面板显示灯的颜色 leds.set_color("LEFT", "GREEN") leds.set_color("RIGHT", "RED") # 英文转语音 sleep(1) sounds.speak(text='Welcome to the E V 3 dev project!') sleep(1) # 控制电机转动 m = LargeMotor(OUTPUT_A) #m.on_for_rotations(SpeedPercent(75), 1) m.on_for_degrees(50, 50)
def cmToRotations(cm): return cm/wheelCircumference_cm # inches to millimeters: def inToMillimeters(inches): return inches * 25.4 # centimeters to millimeters: def cmToMillimeters(cm): #hhm it works... questionable -- no syntax errors! return cm * 10 # Yay, no syntax errors! def drive_cm(power, cm): rt = cmToRotations(cm) tank_drive.on_for_rotations(SpeedPercent(power), SpeedPercent(power), int(rt) ) def drive_cm_new(power, cm): rt = cmToRotations(cm) tank_drive.on_for_rotations(SpeedPercent(power), SpeedPercent(power), rt) #--------------------------------------------------------------------------------------------------------------------------------------------- while True: if (btn.down): break pass btn.wait_for_released('enter') finish = time.time() Display_.clear() Display_.draw.text((0,0), str(finish - start), font=fonts.load('helvR24')) Display_.update() time.sleep(5) drive_cm_new(50, 50) time.sleep(5) drive_cm_new(-50, 50) start = time.time()
import logging import time logging.basicConfig(level=logging.DEBUG) gyro = GyroSensor(INPUT_4) disp = Display() b = Button() s = Sound() color_left = ColorSensor(INPUT_1) color_right = ColorSensor(INPUT_3) # 14, 18, ... # See all: https://python-ev3dev.readthedocs.io/en/latest/display.html f = fonts.load('luBS18') def show(text): #disp.text_grid(t, x=5, y=5) disp.clear() # 0 = left, 80 = far right? # align="center" doesn't seem to work lr = 0 down = 20 #down = 50 disp.draw.text((lr, down), text, font=f, align="left") disp.update() def follow_line(speed=10, want_rli=65, edge="right"):
#from ev3dev2.sound import Sound #sound = Sound() #sound.speak('Left') import ev3dev2.fonts as fonts from ev3dev2.display import Display from time import sleep display = Display() display.clear() display.update() display.text_grid('Hello World!', x=2, y=2, text_color='black', font=fonts.load('luBS14')) display.update() sleep(10)
import ev3dev2.fonts as fonts from ev3dev2.display import Display Display.draw.text((10, 10), 'Hello World!', font=fonts.load('luBS14'))
# code_font_path = os.path.join(fileDir, 'assets/CODE2000.ttf') # Some display docs: https://python-ev3dev.readthedocs.io/en/stable/display.html lcd = Display() def show_text(string, font=fonts.load('luBS14'), font_width=15, font_height=24): lcd.clear() logging.info('Fonts available: {}'.format(fonts.available())) lcd.draw.text((font_width, font_height), string, font=font) lcd.update() # https://www.fileformat.info/info/unicode/char/0ca0/index.htm face = 'ಠ_ಠ'.encode('utf-8') #show_text(face, ImageFont.truetype(code_font_path, 15), 30, 30) # TODO: fix OSError: cannot open resource show_text(face, fonts.load('luBS14'), 30, 30) # TODO: find better default font? sleep(20) # def show_eyes(image): # lcd.clear() # lcd.image.paste(image, (0, 0)) # lcd.update() # image = Love.bmp # show_eyes() # sleep(2)