I'm trying to figure out the new Bricxcc 3.3.8.8 version with the new RS-485 communication controls. here's my code:
Code: Select all
task main();
OnFwd(CONN_HS4, OUT_A, 50);
Wait(SEC_1);
Off(CONN_HS4, OUT_A);
jojoguy10
Code: Select all
task main();
OnFwd(CONN_HS4, OUT_A, 50);
Wait(SEC_1);
Off(CONN_HS4, OUT_A);
Code: Select all
task main()
{
OnFwd(CONN_HS4, OUT_A, 50);
Wait(SEC_1);
Off(CONN_HS4, OUT_A);
}
Code: Select all
task main()
{
OnFwd(CONN_HS4, OUT_A, 50);
Wait(SEC_1);
Off(CONN_HS4, OUT_A);
}
Actually, there's lots of different coding styles, but I prefer this:mattallen37 wrote:Like that, only typically, white space would be more like this.Code: Select all
task main() { OnFwd(CONN_HS4, OUT_A, 50); Wait(SEC_1); Off(CONN_HS4, OUT_A); }
Code: Select all
class Animal
{
public:
string name;
};
task main()
{
Animal robot;
robot.name = "Marvin";
NumOut(0, 8, 6 * 9, 0);
NumOut(0, 0, 42, 0);
Wait(1000);
}
Code: Select all
task main()
{
OnFwd(CONN_HS4, OUT_A, 50);
Wait(SEC_1);
Off(CONN_HS4, OUT_A);
}
Code: Select all
#define RS485
#ifdef RS485
#define theConn CONN_HS4
#else
#define theConn CONN_BT1
#endif
void OnFwdAny(byte conn, byte output, char speed)
{
if (conn == CONN_BT0)
OnFwd(output, speed);
else
RemoteSetOutputState(conn, output, speed, OUT_MODE_MOTORON+OUT_MODE_BRAKE, OUT_REGMODE_IDLE, 0, OUT_RUNSTATE_RUNNING, 0);
}
void OffAny(byte conn, byte output)
{
if (conn == CONN_BT0)
Off(output);
else
RemoteSetOutputState(conn, output, 0, OUT_MODE_MOTORON+OUT_MODE_BRAKE, OUT_REGMODE_IDLE, 0, OUT_RUNSTATE_RUNNING, 0);
}
void OnRevAny(byte conn, byte output, byte speed)
{
if (conn == CONN_BT0)
OnRev(output, speed);
else
{
speed *= -1;
RemoteSetOutputState(conn, output, speed, OUT_MODE_MOTORON+OUT_MODE_BRAKE, OUT_REGMODE_IDLE, 0, OUT_RUNSTATE_RUNNING, 0);
}
}
long MotorRotationCountAny(byte conn, byte output)
{
if (conn == CONN_BT0)
return MotorRotationCount(output);
else
{
OutputStateType params;
params.Port = output;
RemoteGetOutputState(conn, params);
return params.RotationCount;
}
}
task main()
{
byte len, cmd, cnt;
string name;
byte data[];
int mvolts;
#ifdef RS485
UseRS485();
RS485Initialize();
SetHSDataMode(DATA_MODE_NXT);
#endif
RemotePlayTone(theConn, TONE_A5, 1000);
until(RemoteConnectionIdle(theConn));
Wait(SEC_1);
RemoteGetCurrentProgramName(theConn, name);
TextOut(0, LCD_LINE4, name);
Wait(SEC_5);
ClearScreen();
RemoteGetContactCount(theConn, cnt);
NumOut(0, LCD_LINE4, cnt);
Wait(SEC_5);
ClearScreen();
RemoteGetConnectionCount(theConn, cnt);
NumOut(0, LCD_LINE4, cnt);
Wait(SEC_5);
ClearScreen();
RemoteGetBatteryLevel(theConn, mvolts);
NumOut(0, LCD_LINE4, mvolts);
Wait(SEC_5);
ClearScreen();
OutputStateType params;
params.Port = OUT_A;
while (true) {
ClearScreen();
if (RemoteGetOutputState(theConn, params) != NO_ERR)
break;
NumOut(0, LCD_LINE1, params.Power);
NumOut(0, LCD_LINE2, params.Mode);
NumOut(0, LCD_LINE3, params.RegMode);
NumOut(0, LCD_LINE4, params.TurnRatio);
NumOut(0, LCD_LINE5, params.RunState);
NumOut(0, LCD_LINE6, params.TachoLimit);
NumOut(0, LCD_LINE7, params.TachoCount);
NumOut(0, LCD_LINE8, params.RotationCount);
Wait(MS_50);
}
while (true) {
OnFwdAny(CONN_BT1, OUT_A, 75);
Wait(SEC_4);
OnRevAny(CONN_BT1, OUT_A, 75);
Wait(SEC_4);
OffAny(CONN_BT1, OUT_A);
Wait(SEC_1);
NumOut(0, LCD_LINE1, MotorRotationCountAny(CONN_BT1, OUT_A));
}
Stop(true);
}
Well, as you say, there are many different ways of using white space. When I program in BASIC, I only indent one space, but in NXC and NQC, I indent two spaces. I also use tab, but I have it set to 2 spaces.muntoo wrote:Actually, there's lots of different coding styles, but I prefer this:
...
Also, I indent using tabs with width of 4 spaces.
Well, I didn't compile the code, I was just mentioning the whole thing with white space. I honestly doubted that it would compile, seeing an extra parameter in the OnFwd and Off commands.jojoguy14 wrote:... So...could this just be a bug? Maybe?
Users browsing this forum: No registered users and 1 guest