Color 28 Robot Bowling
Color 28 Robot Bowling
use Libraries.Robots.Lego.Button //ROBOT BOWLING
use Libraries.Robots.Lego.Sound
use Libraries.Robots.Lego.Screen
use Libraries.Robots.Lego.Motor
use Libraries.Robots.Lego.ColorSensor
use Libraries.Robots.Lego.TouchSensor
Button button
Sound sound
Screen screen
Motor motor
ColorSensor colorSensor
TouchSensor touchSensor
colorSensor:SetPort(1)
touchSensor:SetPort(4)
integer speed = 40
integer speedFactor=1
repeat until button:IsButtonPressed(button:CENTER_BUTTON)
screen:OutputCenter("ROBOT", 1)
screen:OutputCenterLarge("BOLWING", 2)
screen:OutputCenter("UP=faster", 4)
screen:OutputCenter("DOWN=slower", 5)
screen:OutputCenter("CENTER=Go", 6)
button:WaitForButtonPress()
if button:IsButtonPressed(button:UP_BUTTON)
speedFactor=speedFactor+1
speed = speed*speedFactor
elseif button:IsButtonPressed(button:DOWN_BUTTON)
speedFactor=speedFactor+1
speed = speed/speedFactor
end
screen:OutputCenter("speed= " + speed, 7)
end
repeat until colorSensor:GetColor() = "yellow"
if colorSensor:GetColor() = "blue"
button:SetLightPattern(5)
motor:Stop("D")
motor:SetSpeed("B", speed)
motor:SetSpeed("C", speed/4)
button:SetLightPattern(4)
motor:RotateForward("B")
motor:RotateForward("C")
sound:PlayTone(110,200)
elseif colorSensor:GetColor() = "red"
button:SetLightPattern(6)
motor:Stop("D")
motor:SetSpeed("B", speed/4)
motor:SetSpeed("C", speed)
button:SetLightPattern(7)
motor:RotateForward("B")
motor:RotateForward("C")
sound:PlayTone(182,200)
else
button:SetLightPattern(1)
motor:SetSpeed("B", speed) //Move Forward
motor:SetSpeed("C", speed)
motor:SetSpeed("D", speed/2)
motor:RotateForward("B")
motor:RotateForward("C")
motor:RotateForward ("D")
sound:PlayTone(440,200)
motor:RotateBackward ("D")
sound:PlayTone(220,200)
end
end //end of forward movement
button:SetLightPattern(8)
motor:RotateBackward("B")
motor:RotateBackward("C")
motor:Stop("D")
sound:PlayTone(110,2000)
repeat until colorSensor:GetColor() = "yellow"
if colorSensor:GetColor() = "blue"
button:SetLightPattern(7)
motor:Stop ("D")
motor:SetSpeed("B", speed)
motor:SetSpeed("C", speed/4)
button:SetLightPattern(8)
motor:RotateBackward("B")
motor:RotateBackward("C")
sound:PlayTone(110,100)
elseif colorSensor:GetColor() = "red"
button:SetLightPattern(9)
motor:Stop ("D")
motor:SetSpeed("B", speed/4)
motor:SetSpeed("C", speed)
button:SetLightPattern(7)
motor:RotateBackward("B")
motor:RotateBackward("C")
sound:PlayTone(182,100)
else
button:SetLightPattern(3)
motor:SetSpeed("B", speed) //Move Forward
motor:SetSpeed("C", speed)
motor:RotateBackward("B")
motor:RotateBackward("C")
motor:Stop ("D")
sound:PlayTone(220,100)
sound:PlayTone(320,100)
end
end