Master Bluetooth NXT - UnbDroid/sekksi2016 GitHub Wiki
//MASTER
#define BT_CONN 1
#define INBOX 1
#define OUTBOX 5
sub BTCheck(int conn){
if (!BluetoothStatus(conn)==NO_ERR){
TextOut(5,LCD_LINE2,"Error");
Wait(1000);
Stop(true);
}
}
task main(){
string in, out, iStr;
int i = 0;
unsigned long timeNow, timeLater;
BTCheck(BT_CONN); //check slave connection
while(i<20){
timeNow = CurrentTick();
iStr = NumToStr(i);
out = StrCat("M",iStr);
TextOut(10,LCD_LINE1,"Master Test");
TextOut(0,LCD_LINE2,"IN:");
TextOut(0,LCD_LINE4,"OUT:");
ReceiveRemoteString(INBOX, true, in);
SendRemoteString(BT_CONN,OUTBOX,out);
timeLater = CurrentTick();
TextOut(10,LCD_LINE3,in);
TextOut(10,LCD_LINE5,out);
TextOut(10, LCD_LINE6, "Delay:");
NumOut(10, LCD_LINE7, timeLater - timeNow);
Wait(100);
i++;
}
while(true);
}