Example #1
0
#!/usr/bin/env python3
from ev3dev2.motor import LargeMotor , OUTPUT_B , OUTPUT_C , MoveTank , SpeedPercent
from time import sleep
from ev3dev2.sound import Sound
from ev3dev2.sensor.lego import ColorSensor, TouchSensor, UltrasonicSensor

drive = MoveTank(OUTPUT_B , OUTPUT_C)
cs = ColorSensor()
us = UltrasonicSensor()
ts = TouchSensor()
sound = Sound()

ts.mode = 'TOUCH'
us.mode = 'US-DIST-CM'

blackValue = 20
def moveForward(a = 10, b = 10, c = 0.20):
    drive.on_for_rotations(SpeedPercent(a), SpeedPercent(b), c)
def turning(a = 1.0, b =-1.0, c = 0.025):
    drive.on_for_rotations(SpeedPercent(a), SpeedPercent(b), c)
def pivotRight(c = 0.025):
    drive.on_for_rotations(SpeedPercent(5), SpeedPercent(0), c)
def pivotRight90(a = 20, b = 0, c = 1):
    drive.on_for_rotations(SpeedPercent(a), SpeedPercent(b), c)
def pivotLeft90():
    drive.on_for_rotations(SpeedPercent(0), SpeedPercent(15), 1)
def pivotRightReverse():
    drive.on_for_rotations(SpeedPercent(-5), SpeedPercent(0), 0.025)
def pivotLeft(c = 0.025):
    drive.on_for_rotations(SpeedPercent(0), SpeedPercent(5), c)
def pivotLeftReverse():
Example #2
0
from ev3dev2.sensor import INPUT_1, INPUT_4, INPUT_2, INPUT_3
from ev3dev2.sensor.lego import TouchSensor, InfraredSensor, ColorSensor
from ev3dev2.led import Leds
from ev3dev2.button import Button
from ev3dev2.sound import Sound
ON = True
OFF = False

music = Sound()
music.play_file("Confirm.wav")
tank_drive = MoveTank(OUTPUT_A, OUTPUT_D)
steering_drive = MoveSteering(OUTPUT_A, OUTPUT_D)
ir = InfraredSensor()
ir.mode = "IR-PROX"
touch_sensor = TouchSensor()
touch_sensor.mode = "TOUCH"
color_arm = MediumMotor(OUTPUT_B)
display_button = Button()
color_sensor = ColorSensor()


def deploy_color_sensor():
    color_arm.on_for_rotations(SpeedPercent(5), 0.30)
    time.sleep(4.5)
    if color_sensor.color == 1:
        music.speak("I found something black on the surface of Mars")
    elif color_sensor.color == 2:
        music.speak("I found water on the surface of Mars")
    elif color_sensor.color == 3:
        music.speak("I found a plant on the surface of Mars")
    elif color_sensor.color == 4: