NXC: BT direct commands and Multi button presses
Posted: 10 Oct 2011, 20:35
Hey guys, I'm still not super experienced with NXC so please bear with me. I am right now trying to make a remote in NXC with direct Bluetooth commands, using an NXT with two touch sensors. I would like for someone to modify my code so that the multi-button pressing in lines 23-44 works. I looked at John's website and in his book, but he used some API functions in the sample programs that were not covered in Daniele's tutorial, so I found them hard to understand, as well as in his book. Also, I would like for you to help me out with the Bluetooth direct control. It seems I'm not doing it right since I get some compiler errors, see lines 10, 16, and 95-155. I also had the same comprehension problems with this as I did the multi button pressing. Daniele's tutorial touched up on it slightly, but not enough for me to do it properly. So, without further ado, heres my code:
The sooner you guys can reply the better, cause I've got a deadline for this project.
P.S. If you're Muntoo viewing this, I know you told me not to use "
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.