Created
April 22, 2021 10:02
-
-
Save benoit-cty/c7680d8f47b0a9494c797f89666cf813 to your computer and use it in GitHub Desktop.
Robot Lego RCX 2.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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