# Brain should be defined by default
brain=Brain()
rollerw=Motor(Ports.PORT1)
colorsense=Optical(Ports.PORT20)
def redUp(speed):
rollerw.spin(FORWARD, speed, VelocityUnits.PERCENT)
while not colorsense.is_near_object() or colorsense.color() != Color.RED:
sleep(50)
rollerw.stop()
In practice the optical sensor may still give Color.RED when it doesn’t really see any color (it has to return something) so it may be better to say while color is blue.