This robot is supposed to be a pet. It drives forward until it hears a loud noise and starts to turn around in circles. When it senses a person in front of it, it starts to drive forward again. The cycle continues.
Program:
#pragma config(Sensor, S1, sonarSensor, sensorSONAR)
#pragma config(Sensor, S3, soundSensor, sensorSoundDB)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
task turnaround();
task main()
{
while(true)
{
wait1Msec(500);
while(SensorValue(soundSensor) < 60) // while it's quiet, drive forward until a loud noise
{
motor[motorC] = 40;
motor[motorA] = 40;
wait1Msec(500);
PlaySound(soundShortBlip);
}
while(SensorValue(sonarSensor) > 20)// as long as nothing is close, turn around
{
StartTask(turnaround);
}
motor[motorC] = 40; // when it sees a person, go forward again with different sound
motor[motorA] = 40;
wait1Msec(100);
PlaySound(soundBlip);
}
}
task turnaround()
{
motor[motorC] = 50;
motor[motorA] = -50;
wait1Msec(1000);
}
Video:
http://www.flickr.com/photos/29464331@N02/4166629994/in/set-72157608737193431/Picture:
http://www.flickr.com/photos/29464331@N02/4165839577/in/set-72157608737193431/