Skip to content

Instantly share code, notes, and snippets.

@benoit-cty
Created April 22, 2021 10:02
Show Gist options
  • Save benoit-cty/c7680d8f47b0a9494c797f89666cf813 to your computer and use it in GitHub Desktop.
Save benoit-cty/c7680d8f47b0a9494c797f89666cf813 to your computer and use it in GitHub Desktop.
Robot Lego RCX 2.0
int speed, __speed;
task music()
{
while (true)
{
PlayTone(262,40); Wait(50);
PlayTone(294,40); Wait(50);
PlayTone(330,40); Wait(50);
PlayTone(294,40); Wait(50);
PlayTone(262,160); Wait(200);
}
}
task avance()
{
while (true)
{
__speed = speed;
if (__speed > 0) {OnFwd(OUT_A+OUT_B);}
if (__speed < 0) {OnRev(OUT_A+OUT_B); __speed = -__speed;}
/*Wait(__speed);
Off(OUT_A+OUT_B);*/
}
}
task obstacle()
{
SetSensor(SENSOR_1,SENSOR_TOUCH);
SetSensor(SENSOR_2,SENSOR_TOUCH);
while (true)
{
if ((SENSOR_1 == 1) || (SENSOR_2 == 1))
{
stop avance;
OnRev(OUT_A+OUT_B); Wait(30);
OnFwd(OUT_A); Wait(80);
start avance;
}
}
}
task main()
{
speed = 30;
start music;
speed = 5;
start avance;
start obstacle;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment