Ejemplo n.º 1
0
    buf = ""


# define motors and use brake mode


def waitformotor(motor):
    xxx = 0


paper = Motor("E")
pen1 = Motor("B")
#pen2 = ev3.MediumMotor('outD')
head = Motor("D")

pen1.set_stop_action("brake")
#pen2.stop_action = "brake"
head.set_stop_action("brake")
paper.set_stop_action("brake")
head.set_degrees_counted(0)
pen1.set_degrees_counted(0)
#pen2.reset()
paper.set_degrees_counted(0)

#move paper until color sensor recieves >50 reading

#paper.speed_regulation_enabled=u'on'
pen1.run_for_degrees(30, 40)
#pen2.run_to_rel_pos(speed_sp=400, position_sp=53)
pen1.set_degrees_counted(0)
#pen2.reset()
Ejemplo n.º 2
0
from spike import PrimeHub, LightMatrix, Button, StatusLight, ForceSensor, MotionSensor, Speaker, ColorSensor, App, DistanceSensor, Motor, MotorPair
from spike.control import wait_for_seconds, wait_until, Timer
from math import *

hub = PrimeHub() 
color_sensor_E = ColorSensor('E')
color_sensor_F = ColorSensor('F')

motor_A =  Motor('A') # Set the motor port to the motor.
motor_B = Motor('B') # Set the motor port to the motor.

motor_A.set_default_speed(-30) # Set the default speed of the motor.
motor_B.set_default_speed(30) # Set the default speed of the motor.

motor_A.set_stop_action('brake') # Activate the brakes when the motor stops. The other conditions are 'hold' and 'coast'.
motor_B.set_stop_action('brake') # Activate the brakes when the motor stops.

motor_A_flag = 0 # Create a flag for motor A and set it to OFF.
motor_B_flag = 0 # Create a flag for motor B and set it to OFF.

def stop_at(color):
    motor_A_flag = 0 # Reset the flag for motor A to OFF.
    motor_B_flag = 0 # Reset the flag for motor B to OFF.

    # Move forward.
    motor_A.start()
    motor_B.start()

    while (motor_A_flag == 0) or (motor_B_flag == 0): # Repeat while both sensors ever detect black color.
        if color_sensor_E.get_color() == color: # If the color sensor on port E detect the desired color
            motor_A.stop() # stop the motor an port A and