Beispiel #1
0
def main():
    '''The main function of our program'''

    # set the console just how we want it
    reset_console()
    set_cursor(OFF)
    set_font('Lat15-Terminus24x12')

    # print something to the output panel in VS Code
    debug_print('Hello VS Code!')

    sound = Sound()
    sound.play('internet7.wav')

    color_sensor = ColorSensor()
    motor_pair = MoveSteering(OUTPUT_B, OUTPUT_C)
    andar = False
    while True:
        move(motor_pair, color_sensor, andar, sound)
Beispiel #2
0
    far away...
"""))

speaker = Sound()

speaker.play_song((
    ('D4', 'e3'),
    ('D4', 'e3'),
    ('D4', 'e3'),
    ('G4', 'h'),
    ('D5', 'h'),
    ('C5', 'e3'),
    ('B4', 'e3'),
    ('A4', 'e3'),
    ('G5', 'h'),
    ('D5', 'q'),
    ('C5', 'e3'),
    ('B4', 'e3'),
    ('A4', 'e3'),
    ('G5', 'h'),
    ('D5', 'q'),
    ('C5', 'e3'),
    ('B4', 'e3'),
    ('C5', 'e3'),
    ('A4', 'h.'),
))

speaker.play(os.path.join(_HERE, 'snd/r2d2.wav'))

#speaker.speak("Luke, I am your father")
Beispiel #3
0
from serverInfo import serverInfo

from ev3dev2.sensor import INPUT_2
from ev3dev2.sensor.lego import TouchSensor
from ev3dev2.sound import Sound

sound = Sound()
ts = TouchSensor(INPUT_2)

cm = CubeMover()
cr = ColorReader(cm)


def getSolution():
    colorString = cr.getCubeString()
    cubeString = CubeSolver.translateColors(colorString)
    print(cubeString)
    return get('http://' + serverInfo['hostName'] + ':' + serverInfo['port'] +
               '/' + cubeString)


while True:
    print('ready')
    sound.play('alert.wav')
    ts.wait_for_pressed()
    sol = getSolution()
    print(sol)
    if (sol.status_code == 200):
        cm.move(sol.text)
        sound.play('khaled.wav')
Beispiel #4
0
class Bot:
    def __init__(self, wheel_radius, wheel_spacing):
        self._container_motor = MediumMotor(OUTPUT_C)
        self._steering_drive = MoveSteering(OUTPUT_D, OUTPUT_A)
        self._touch_sensor_front = TouchSensor(INPUT_1)
        self._touch_sensor_top = TouchSensor(INPUT_2)
        #self._ultrasonic_sensor = UltrasonicSensor(INPUT_2)
        self._color_sensor = ColorSensor(INPUT_3)
        #self._color_sensor.calibrate_white()
        #self._color_sensor.mode = "RGB-RAW"
        self._color_sensor.mode = "COL-REFLECT"
        self._leds = Leds()
        self._sound = Sound()
        self.WHEEL_RADIUS = wheel_radius
        self.WHEEL_SPACING = wheel_spacing

    def empty_container(self):
        self._container_motor.on_for_rotations(-15, 2)

    def read_touch_front(self):
        return self._touch_sensor_front.is_pressed

    def read_touch_top(self):
        return self._touch_sensor_top.is_pressed

    def read_ultrasonic(self):
        return self._ultrasonic_sensor.distance_centimeters

    def set_color_sensor_reflect(self):
        self._color_sensor.mode = "COL-REFLECT"

    def set_color_sensor_rgb(self):
        self._color_sensor.mode = "RGB-RAW"

    def read_color(self):
        if self._color_sensor.mode == "RGB-RAW":
            return tuple(map(self._color_sensor.value, [0, 1, 2]))
        elif self._color_sensor.mode == "COL-REFLECT":
            return self._color_sensor.reflected_light_intensity

    def detect_red_tape(self):
        tape_found = False
        self.set_color_sensor_rgb()
        while not tape_found:
            self.move_forward(1, 10, blocking=False)
            red, green, blue = self.read_color()
            print("red {} green {} blue {}".format(red, green, blue))
            if red > 120 and green < 80 and blue < 80:
                tape_found = True
                self.stop()
        self.set_color_sensor_reflect()

    def _cm_movement_to_rotations(self, distance):
        return distance / (pi * 2 * self.WHEEL_RADIUS) * 1.667

    def move_forward(self, distance, speed_percent, blocking=True):
        rots = self._cm_movement_to_rotations(distance)
        self._steering_drive.on_for_rotations(FORWARD,
                                              -speed_percent,
                                              rots,
                                              block=blocking)

    def move_backward(self, distance, speed_percent, blocking=True):
        self.move_forward(distance, -speed_percent, blocking=blocking)

    def stop(self):
        self._steering_drive.off()

    def rotate_left(self, degrees, speed_percent, blocking=True):
        distance = self.WHEEL_SPACING * pi * degrees / 360
        rots = self._cm_movement_to_rotations(distance)
        self._steering_drive.on_for_rotations(LEFT_ROTATION,
                                              speed_percent,
                                              rots,
                                              block=blocking)

    def rotate_right(self, degrees, speed_percent, blocking=True):
        distance = self.WHEEL_SPACING * pi * degrees / 360
        rots = self._cm_movement_to_rotations(distance)
        self._steering_drive.on_for_rotations(RIGHT_ROTATION,
                                              speed_percent,
                                              rots,
                                              block=blocking)

    def wav_processor(self):
        #self._sound.play('sounds/t2_learning_computer_x.wav')
        self._sound.play('sounds/breadcrumbs.wav')

    def tts(self, text):
        self._sound.speak(text, volume=100)

    def set_led_color(self, side, color):
        self._leds.set_color(side, color)
Beispiel #5
0
###############################################################################
# 1. The touch sensor
#    This is a simple switch.
###############################################################################

touch_sensor = TouchSensor()
sound.speak('Please press the touch sensor')

## This is a 'while' loop. The condition after 'while' is tested each time the indented code runs
while True:  # <- The condition here is "True". This means the loop runs continuously.
    if touch_sensor.is_pressed == True:  # <- This is a condition. The 'break' code underneath runs if the condition is true.
        break  # <- This "jumps out" of the while loop.
    time.sleep(0.1)  # <- What do you think this does?

#  The while loop above runs until you press the switch. And then we...
sound.play('breaking_glass.wav')

## Note that we could have written the while loop in fewer lines of code. Read
## these lines and see if they make sense
#while not touch_sensor.is_pressed:
#    time.sleep(0.1)

###############################################################################
# 2. The infrared sensor
#    This sensor can tell you how far away an object is (it's not very accurate).
###############################################################################

#
# 2.1 Uncomment this code to see how the IR sensor detects distance
#
def music():
    Sound.play("sounds/titanic.wav").wait()