Code: Select all
int x;
task grab()
{
while(true)
{
until(SENSOR_2 == 1)
until(SENSOR_2 == 0)
RemoteOnRev(1, OUT_A, 100);
until(SENSOR_2 == 1)
until(SENSOR_2 == 0)
RemoteOnFwd(1, OUT_A, 100);
Wait(1000);
RemoteOff(1, OUT_A);
}
}
task determine()
{
while(true)
{
if(ButtonPressed(BTNCENTER, true))
{
if(ButtonPressed(BTNLEFT, true))
{
if(ButtonPressed(BTNRIGHT, true))
{
}
else
{
x = 3;
}
}
if(ButtonPressed(BTNRIGHT, true))
{
if(ButtonPressed(BTNRIGHT, true))
{
}
else
{
x = 2;
}
}
else
{
if(ButtonPressed(BTNRIGHT, true))
{
}
else
{
x = 1;
}
}
}
else
{
if(ButtonPressed(BTNLEFT, true))
{
if(ButtonPressed(BTNRIGHT, true))
{
}
else
{
x = 5;
}
}
if(ButtonPressed(BTNRIGHT, true))
{
if(ButtonPressed(BTNLEFT, true))
{
}
else
{
x = 4;
}
}
else
{
if(ButtonPressed(BTNLEFT, true))
{
}
else
{
x = 0;
}
}
}
ClearScreen();
NumOut(50, LCD_LINE4, x);
Wait(30);
}
}
task operate()
{
if(x == 0)
{
RemoteOff(1, OUT_BC);
}
if(x == 1)
{
if(SENSOR_1 == 1)
{
RemoteOnFwd(1, OUT_BC, 75);
}
else
{
RemoteOnRev(1, OUT_BC, 75);
}
if(x == 2)
{
if(SENSOR_1 == 1)
{
RemoteOnFwdSync(1, OUT_BC, 75, 100);
}
else
{
RemoteOnRevSync(1, OUT_BC, 75, 100);
}
}
if(x == 3)
{
if(SENSOR_1 == 1)
{
RemoteOnFwdSync(1, OUT_BC, 75, -100);
}
else
{
RemoteOnRevSync(1, OUT_BC, 75, -100);
}
}
if(x == 4)
{
if(SENSOR_1 == 1)
{
RemoteOnFwd(1, OUT_B, 75);
}
else
{
RemoteOnRev(1, OUT_B, 75);
}
}
if(x == 5)
{
if(SENSOR_1 == 1)
{
RemoteOnFwd(1, OUT_C, 75);
}
else
{
RemoteOnRev(1, OUT_C, 75);
}
}
}
task main()
{
SetSensorTouch(IN_1);
SetSensorTouch(IN_2);
Precedes(grab, determine, operate);
}
P.S. If you're Muntoo viewing this, I know you told me not to use "
until(cond);
" and to instead use "while(!(cond));
" because it's more C like. Well the former is easier to remember so I'm going to stick with that.