12 de novembro de 2011

Com o bluetooth

#include "NXCDefs.h"
int aux=0;
int comando=0;
int x;
task main(){
SetSensor(IN_1,SENSOR_TOUCH); //x1
SetSensor(IN_2,SENSOR_TOUCH); //x2
SetSensor(IN_3,SENSOR_TOUCH); //y1
SetSensor(IN_4,SENSOR_TOUCH); //y2
x=BluetoothStatus(1);
/*
SendRemoteString(1,1,"ligar");
ReceiveRemoteString(2,true,comando);
*/
if(x!= NO_ERR){
TextOut(5,LCD_LINE3,"Nao conseguir conectar");
Wait(1000);
Stop(true);
}
else{
while(true){

//tempo pata chegar as bolinhas
Wait(5000);
// chegou as bolinhas

// 1 thread x
OnFwd(OUT_A, 60);
until (SENSOR_1 == 1);
Off(OUT_A);
Wait(100);

// 2 thread y
OnFwd(OUT_B, 60);// 2 thread
until (SENSOR_3 == 1);
Off(OUT_B);
Wait(100);

// 3 thread garra
//comunicação bluetooth
while(comando!=1){
SendRemoteString(1,1,"1");
ReceiveRemoteString(2,true,comando);
}
//comunicação bluetooth - chegou carrinho
if(comando==1){//o carrinho chegou
OnFwd(OUT_C, 60);
Wait(400);
Off(OUT_C);
Wait(100);
OnRev(OUT_C, 60);
Wait(400);
Off(OUT_C);
comando=0;
aux=1;
}
// 1 thread x - depois dar as bolinhas p o carrinho
if(aux==1){
OnRev(OUT_A, 60);
until (SENSOR_2 == 1);
Off(OUT_A);
Wait(100);

// 2 thread y - depois dar as bolinhas p o carrinho
OnRev(OUT_B, 60);// 2 thread
until (SENSOR_4 == 1);
Off(OUT_B);
Wait(100);
aux=0;
}
}
}
}

Nenhum comentário:

Postar um comentário