use Libraries.Robots.Lego.Motor
use Libraries.Robots.Lego.TouchSensor
use Libraries.Robots.Lego.Button
class main
action Main
//object and variable list
Motor motor
TouchSensor touchSensor
Button button
boolean caneTip = false
boolean escape = false
motor:SetSpeed(motor:MOTOR_C, 30)
motor:SetSpeed(motor:MOTOR_B, 90)
motor:SetSpeed(motor:MOTOR_A, 90)
touchSensor:SetPort(touchSensor:PORT_1)
//This next conditional will control whether the robot keeps running or stops.
if button:IsButtonPressed(button:ESCAPE_BUTTON)
escape = true
else
escape = false
end
if touchSensor:IsPressed()
caneTip = true
else
caneTip = false
end
if escape = false
//This is where we will create our if statements to control the robot’s actions.
if caneTip = true
Whack()
else
repeat while caneTip = false
Sweep()
ForwardMotion()
end
end
else
motor:Stop(motor:MOTOR_A)
motor:Stop(motor:MOTOR_B)
motor:Stop(motor:MOTOR_C)
end
end
action Sweep
motor:RotateByDegrees(motor:MOTOR_C, 90)
motor:Wait(motor:MOTOR_C)
motor:RotateByDegrees(motor:MOTOR_C, -90)
motor:Wait(motor:MOTOR_C)
end
action ForwardMotion
motor:RotateForward(motor:MOTOR_A)
motor:RotateForward(motor:MOTOR_B)
end
action Whack
motor:SetSpeed(motor:MOTOR_C, 180)
motor:SetSpeed(motor:MOTOR_A, 60)
motor:SetSpeed(motor:MOTOR_B, 60)
motor:RotateByDegrees(motor:MOTOR_A, -20)
motor:RotateByDegrees(motor:MOTOR_B, -20)
motor:Wait(motor:MOTOR_C)
motor:RotateByDegrees(motor:MOTOR_C, -90)
motor:Wait(motor:MOTOR_C)
motor:RotateByDegrees(motor:MOTOR_C, 90)
caneTip = false
end
end