發送信號端
#define BT_CONN 1
#define OUTBOX 5
sub BTCheck(int conn)
{
if (!BluetoothStatus(conn) == NO_ERR)
{
TextOut(5,LCD_LINE2,"Error");
Wait(1000);
Stop(true) ;
}
}
task main()
{
BTCheck (BT_CONN);
SetSensorTouch(S1);
bool pressed ;
while(true)
{
pressed = Sensor(S1);
if(Sensor(S1)==1)
{
SendRemoteBool(BT_CONN, OUTBOX,pressed);
OnFwd(OUT_BC,75);
}
}
}
}
接收信號端
//slave
#define INBOX 5
sub BTCheck(int conn)
{
if(!BluetoothStatus(conn)==NO_ERR)
{
TextOut(5,LCD_LINE2,"ERROR");
Wait(1000);
Stop(true);
}//if
}//BTCheck
task main()
{
BTCheck(0);
bool bval;
while(true)
{
ReceiveRemoteBool(INBOX, true,bval);
if(bval == 1)
{
OnFwd(OUT_BC,75);
}
}
}
}
要注意一點就是發送端的BT_CONN 需設為1,接收端BTCheck需設為0,這樣才連得到喔!