#include "NXCDefs.h"
int sentido_1=1, sentido_2=1, canal_1, canal_2, mudar_sentido=1;
task canal(){
ReceiveRemoteNumber(1,true,canal_1);
ReceiveRemoteNumber(2,true,canal_2);
}
task acao(){
if(canal_1==1 && sentido_1==2 && sentido_2==2){
SendRemoteNumber(1,5,0);
}
if(canal_1==1 && sentido_1==1 && sentido_2==1){
SendRemoteNumber(1,5,1);
Wait(2000);
mudar_sentido=1;
SendRemoteNumber(2,5,1);
}
if(canal_2==1 && sentido_2==2 && sentido_2==2){
OnFwd(OUT_C,40);
Wait(400);
Off(OUT_C);
Wait(1500);
OnRev(OUT_C,40);
Wait(350);
Off(OUT_C);
Wait(2000);
SendRemoteNumber(2,5,1);
mudar_sentido=1;
}
}
sub BTCheck(int x){
if(!BluetoothStatus(x)==NO_ERR){
if(x==1){
TextOut(5,LCD_LINE2,"Erro na conexao");
TextOut(5,LCD_LINE3,"da esteira");
Wait(2000);
Stop(true);
}
else{
TextOut(5,LCD_LINE2,"Erro na conexao");
TextOut(5,LCD_LINE3,"do carrinho");
Wait(2000);
Stop(true);
}
}
}
task motor_1(){
while(true){
if(mudar_sentido){
switch(sentido_1){
case 1:{
OnFwd(OUT_A,100);
until(SENSOR_1==1);
Off(OUT_A);
sentido_1=2;
break;
}
case 2:{
OnRev(OUT_A,100);
until(SENSOR_2==1);
Off(OUT_A);
sentido_1=1;
break;
}
default:{
}
}
mudar_sentido=0;
}
}
}
task motor_2(){
while(true){
if(mudar_sentido){
switch(sentido_2){
case 1:{
OnFwd(OUT_B,100);
until(SENSOR_3==1);
Off(OUT_B);
sentido_2=2;
break;
}
case 2:{
OnRev(OUT_B,100);
until(SENSOR_4==1);
Off(OUT_B);
sentido_2=1;
break;
}
default:{
}
}
mudar_sentido=0;
}
}
}
task main(){
SetSensor(IN_1,SENSOR_TOUCH);
SetSensor(IN_2,SENSOR_TOUCH);
SetSensor(IN_3,SENSOR_TOUCH);
SetSensor(IN_4,SENSOR_TOUCH);
BTCheck(1);
//BTCheck(2);
while(true){
TextOut(10,LCD_LINE1,"Master Funcionando!");
Precedes(motor_1,motor_2,canal,acao);
//SendRemoteNumber(BT_CONN,OUTBOX,i);
//ReceiveRemoteNumber(INBOX,true,ack);
}
}
Nenhum comentário:
Postar um comentário