Created
December 21, 2011 11:30
-
-
Save pepijndevos/1505699 to your computer and use it in GitHub Desktop.
NBC version of the NXT bike
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 INTERVAL 100 | |
#define POWMUL -30 | |
#define LIGHTSENSOR IN_2 | |
#define ULTRASONICSENSOR IN_1 | |
dseg segment | |
distance sword 0 | |
oldlight byte | |
newlight byte | |
deltalight sword | |
lowlimit sbyte | |
highlimit sbyte | |
limitrange byte | |
power sbyte | |
temp byte | |
temp2 byte | |
temp3 byte | |
dseg ends | |
thread main | |
SetSensorColorRed(LIGHTSENSOR) | |
SetSensorUltrasonic(ULTRASONICSENSOR) | |
ResetRotationCount(OUT_A) | |
OnFwd(OUT_A, 30) | |
wait 1000 | |
Off(OUT_A) | |
getout highlimit, OUT_A, RotationCount | |
OnRev(OUT_A, 30) | |
wait 1000 | |
Off(OUT_A) | |
getout lowlimit, OUT_A, RotationCount | |
sub highlimit highlimit 5 | |
add lowlimit lowlimit 5 | |
sub limitrange, highlimit, lowlimit | |
precedes balance, fwd | |
endt | |
thread balance | |
getin newlight LIGHTSENSOR ScaledValue | |
Forever: | |
mov oldlight, newlight | |
getin newlight LIGHTSENSOR ScaledValue | |
sub deltalight oldlight newlight | |
mul power deltalight POWMUL | |
getout temp, OUT_A, RotationCount | |
cmp LT temp2 temp highlimit | |
tst GT temp3 power | |
and temp2 temp2 temp3 | |
brtst NEQ Skip temp2 | |
cmp GT temp2 temp lowlimit | |
tst LT temp3 power | |
and temp2 temp2 temp3 | |
brtst NEQ Skip temp2 | |
OnFwd(OUT_A, power) | |
Skip: | |
wait INTERVAL | |
jmp Forever | |
endt | |
thread fwd | |
wait 2000 | |
Restart: | |
OnFwd(OUT_BC,100) | |
Loop: | |
wait INTERVAL | |
ReadSensorUS(ULTRASONICSENSOR, distance) | |
brcmp GT, Restart, distance, 30 | |
Off(OUT_BC) | |
jmp Loop | |
endt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment