Touch21 This time we let the touch sensor work with the motors. Be sure have the sensor pointing in the direction of motion and is sticking out beyond the body of the robot. The sounds in this example let you know when the switch has be activated they also create time for the motors to backup and the turn the robot around. There are no new commands or ideas in the lesson.
Click here to see the code without comments to copy &paste. ==>
//just the code no comments
use Libraries.Robots.Lego.Buttonuse Libraries.Robots.Lego.Sounduse Libraries.Robots.Lego.TouchSensoruse Libraries.Robots.Lego.MotorButton buttonSound soundTouchSensor touchMotor motortouch:SetPort(1) motor:SetSpeed("B",60)motor:SetSpeed("C",60)repeat until button:IsButtonPressed(button:ESCAPE_BUTTON) motor:RotateForward("B") motor:RotateForward("C") if touch:IsPressed() motor:RotateBackward("B") motor:RotateBackward("C") sound:PlayTone(440,500) sound:PlayTone(220,500) motor:RotateForward("B") motor:RotateBackward("C") sound:PlayTone(880,333) sound:PlayTone(440,333) endend
use Libraries.Robots.Lego.Buttonuse Libraries.Robots.Lego.Sounduse Libraries.Robots.Lego.TouchSensoruse Libraries.Robots.Lego.MotorButton buttonSound soundTouchSensor touchMotor motortouch:SetPort(1) motor:SetSpeed("B",60)motor:SetSpeed("C",60)repeat until button:IsButtonPressed(button:ESCAPE_BUTTON) motor:RotateForward("B") motor:RotateForward("C") if touch:IsPressed() motor:RotateBackward("B") motor:RotateBackward("C") sound:PlayTone(440,500) sound:PlayTone(220,500) motor:RotateForward("B") motor:RotateBackward("C") sound:PlayTone(880,333) sound:PlayTone(440,333) endend
Sample Video appears to the right.Scroll down to see student summited videos
Student Videos
Student Videos
GITHUB BUTTON HERE