Created
November 15, 2013 22:37
-
-
Save JamesSwift/7492869 to your computer and use it in GitHub Desktop.
NQC Code to alow a Lego RCX brick to stand on two wheels. I place this code in the public domain. No rights reserved.
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
#define FULL_POWER_OFFSET 3 | |
task main() | |
{ | |
SetSensor(SENSOR_2,SENSOR_LIGHT); | |
int last_reading=SENSOR_2; | |
//start adjust_power; | |
SetPower(OUT_A+OUT_C,7); | |
while (true) { | |
if (SENSOR_2 > last_reading){ | |
OnFwd(OUT_A+OUT_C); | |
Wait(0); | |
if (SENSOR_2-last_reading>FULL_POWER_OFFSET){ | |
//OnFwd(OUT_A+OUT_C); | |
until(SENSOR_2<=last_reading+FULL_POWER_OFFSET); | |
OnRev(OUT_C+OUT_A); | |
Wait(0); | |
Off(OUT_A+OUT_C); | |
} | |
Off(OUT_A+OUT_C); | |
Wait(0); | |
} | |
if (SENSOR_2 < last_reading){ | |
OnRev(OUT_C+OUT_A); | |
Wait(0); | |
if (last_reading-SENSOR_2>FULL_POWER_OFFSET){ | |
//OnRev(OUT_C+OUT_A); | |
until(SENSOR_2>=last_reading-FULL_POWER_OFFSET); | |
OnFwd(OUT_C+OUT_A); | |
Wait(0); | |
Off(OUT_A+OUT_C); | |
} | |
Off(OUT_A+OUT_C); | |
Wait(0); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment