Skip to content

Instantly share code, notes, and snippets.

@JamesSwift
Created November 15, 2013 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesSwift/7492869 to your computer and use it in GitHub Desktop.
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.
#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