예제 #1
0
def print_to_screen(string):
  string = str(string)

  screen = core.Screen()
  screen.clear()
  
  screen.draw.text((10,10), string, font=fonts.load('luBS24'))
  print(string)
  
  screen.update()
예제 #2
0
#!/usr/bin/env python3
""" 
    remote.py: Checks which button is pressed
    Author: Cristina Serrano Gonzalez (Naeriel)
"""

import ev3dev.ev3 as ev3
import ev3dev.fonts as fonts
from time import sleep

remote = ev3.RemoteControl(sensor=None, channel=1)
lcd = ev3.Screen()

while True:
    if remote.red_up:
        lcd.draw.text((10, 10), 'Red Up', font=fonts.load("luBS14"))
        lcd.update()
        sleep(5)
    else:
        lcd.draw.text((10, 10), 'None pressed', font=fonts.load("luBS14"))
        lcd.update()
        sleep(5)
예제 #3
0
#!/usr/bin/env python3

from ev3dev.ev3 import *
from time import sleep
import ev3dev.fonts as fonts

gy = GyroSensor()
us = UltrasonicSensor()
lcd = Screen()
dispFont = fonts.load('luBS24')

#Put sensor in ANGLE mode
gy.mode = 'GYRO-ANG'
us.mode = 'US-DIST-CM'

units = gy.units

while True:
    lcd.clear()
    angle = gy.value() % 360
    distance = us.value() / 10
    lcd.draw.text((30, 60), str(angle) + " " + units, font=dispFont)
    lcd.draw.text((30, 30), str(distance) + " cm", font=dispFont)
    print("Current angle:", angle, "Current distance:", distance)
    lcd.update()
    sleep(0.5)
예제 #4
0
#!/usr/bin/env python3
from ev3dev.ev3 import *
from time import sleep
import ev3dev.fonts as fonts
from PIL import Image, ImageDraw, ImageFont

#Lab 6


lcd = Screen()

# Connect ultrasonic sensor to any sensor port
# and check it is connected.
us = UltrasonicSensor() 
assert us.connected, "Connect a US sensor to any sensor port"
# Put the US sensor into distance mode.
us.mode='US-DIST-CM'

while True:    # forever
    lcd.clear()
    # convert to cm
    lcd.draw.text((40,50),str(us.value()/10)+' cm', font=fonts.load('helvB24')) 
    lcd.update()
    sleep(0.1) # so the display doesn't change too frequently
예제 #5
0
#!/usr/bin/env python3
#Lab 6
from ev3dev.ev3 import *
from time import sleep, time
import math
import ev3dev.fonts as fonts
from PIL import Image, ImageDraw, ImageFont

lcd = Screen()

# Attach large motors to ports B and C
mB = LargeMotor('outB')
mC = LargeMotor('outC')

# NumRots is number of wheel rotations needed for robot to advance 50 cm
NumRots = 50 / 17.6  # wheel circumference = 17.6 cm
StartTime = time()  # seconds since the 'epoch'

# convert rotations to degrees
mB.run_to_rel_pos(position_sp=NumRots * 360, speed_sp=360, stop_action="brake")
mC.run_to_rel_pos(position_sp=NumRots * 360, speed_sp=360, stop_action="brake")

mB.wait_while('running')
mC.wait_while('running')

TravelTime = time() - StartTime  # seconds since the 'epoch'
Speed = round(50 / TravelTime)  # Speed = distance in cm / time in s
lcd.draw.text((40, 50), str(Speed) + ' cm/s', font=fonts.load('helvB24'))
lcd.update()
sleep(5)  # Give enough time for the screen to be read
예제 #6
0
#!/usr/bin/env python3

#Lab 6

from ev3dev.ev3 import *
from time import sleep
import ev3dev.fonts as fonts
from PIL import Image, ImageDraw, ImageFont

lcd = Screen()

# Connect ultrasonic sensor to any sensor port
# and check it is connected.
us = UltrasonicSensor()
assert us.connected, "Connect a US sensor to any sensor port"
# Put the US sensor into distance mode.
us.mode = 'US-DIST-CM'

while us.value() > 80:  # 8 cm converted to mm
    lcd.clear()
    lcd.draw.text((40, 50),
                  str(us.value() / 10) + ' cm',
                  font=fonts.load('helvB24'))
    lcd.update()
    sleep(0.1)  # so the display doesn't change too frequently

pic = Image.open('pics/Up.bmp')
lcd.image.paste(pic, (0, 0))
lcd.update()

sleep(5)  # when running from Brickman, need time to admire image
예제 #7
0
#!/usr/bin/env python3
""" 
    printLCD.py: Prints a message into EV3 LCD screen
    Author: Cristina Serrano Gonzalez (Naeriel)
"""

import ev3dev.ev3 as ev3
import ev3dev.fonts as fonts
from time import sleep

# Load Screen function and write a text
lcd = ev3.Screen()
lcd.draw.text((10, 10), 'My name is Cristina', font=fonts.load("luBS14"))
lcd.draw.text((10, 25), 'I am an engineer', font=fonts.load("luBS14"))
lcd.update()
sleep(2)
예제 #8
0
파일: set_id.py 프로젝트: nuwud/legoswarm
#!/usr/bin/env python3

import ev3dev.auto as ev3
import time
import ev3dev.fonts as fonts

TOTAL_IDS = 16
DEG_PER_ID = 20

dial = ev3.Motor(ev3.OUTPUT_C)
screen = ev3.Screen()
btn = ev3.Button()

try:
    from id import MY_ID
except:
    MY_ID = 0

dial.position = MY_ID * DEG_PER_ID + DEG_PER_ID // 2
while not btn.enter:
    p = dial.position
    id = (p % (TOTAL_IDS * DEG_PER_ID)) // DEG_PER_ID
    screen.clear()
    screen.draw.text((70, 50), str(id), font=fonts.load('luBS24'))
    screen.update()
    time.sleep(0.01)

id_file = open("id.py", 'w')
id_file.write("MY_ID = {0}\n".format(id))
예제 #9
0
def main():
    gy = GyroSensor()
    mB = LargeMotor('outB')
    mC = LargeMotor('outC')
    cl = ColorSensor()
    lcd = Screen()

    tank_drive = MoveTank(OUTPUT_B, OUTPUT_C)

    #telling it what colors it can see
    cl.mode = 'COL-COLOR'
    colors = ('', 'black', 'blue', 'green', 'yellow', 'red', 'white', 'brown')

    Sound.beep

    # always checking for color
    while True:
        print(colors[cl.value()])
        #what to do when color seen, when see blue it say on screen blue
        sleep(1)

        if colors[cl.value()] == "red":
            lcd.draw.text(
                (10, 10), 'Red', font=fonts.load('luBS24')
            )  # tried 24, trying bigger must use 24 other dont work
            lcd.update()
            sleep(3.75)
        #everything below is still Tessa's, but I change what it said
        elif colors[cl.value()] == "Blue":
            lcd.draw.text((10, 10), 'Blue', font=fonts.load('luBS24'))
            lcd.update()
            sleep(3.75)
            if ts.value():
                sound.speak("Blue").wait()

        elif colors[cl.value()] == "green":
            lcd.draw.text((10, 10), 'Green', font=fonts.load('luBS24'))
            lcd.update()
            sleep(3.75)
            if ts.value == True:
                sound.speak("Green")

        elif colors[cl.value()] == "Black":
            lcd.draw.text((10, 10), 'Black', font=fonts.load('luBS24'))
            lcd.update()
            sleep(3.75)

        elif colors[cl.value()] == "white":
            lcd.draw.text((10, 10), 'White', font=fonts.load('luBS24'))
            lcd.update()
            sleep(3.75)

        elif colors[cl.value()] == "Brown":
            lcd.draw.text((10, 10), 'Brown', font=fonts.load('luBS24'))
            lcd.update()
            sleep(3.75)

        elif colors[cl.value()] == "yellow":
            lcd.draw.text((10, 10), 'Yellow', font=fonts.load('luBS24'))
            lcd.update()
            sleep(3.75)
            while ts.value():
                count = 0
                while count < 4:
                    tank_drive.on_for_rotations(SpeedPercent(30),
                                                SpeedPercent(30), 1)
                    # put gyro sensor into ANGLE mode
                    gy.mode = 'GYRO-ANG'
                    gy.mode = 'GYRO-RATE'
                    gy.mode = 'GYRO-ANG'

                    mB.run_forever(speed_sp=-75)
                    mC.run_forever(speed_sp=75)
                    # never use == with gyro
                    while gy.value() >= -86:  #-90, -87, 86 no posotive
                        sleep(0.2)
                        mB.stop(stop_action="hold")
                        mC.stop(stop_action="hold")
                        count += 1
예제 #10
0
 def print_text(self, text):  #lcd에 글자 출력
     self.clear()
     self.draw.text((10, 10), text, font=fonts.load('luBS12'))
     self.update()