#include "NXCDefs.h"
int sentido_1=2, sentido_2=1, canal_1=1, canal_2=0, mudar_sentido_1=1, mudar_sentido_2=1, i=0;
//RECEBER INBOX 2
//ENVIAR OUTOBOX 5
task canal(){
while(true){
//ReceiveRemoteNumber(1,true,canal_1);
ReceiveRemoteNumber(2,true,canal_2);
}
}
void limpar_lcd(){
TextOut(10,LCD_LINE4," ");
TextOut(10,LCD_LINE5," ");
TextOut(10,LCD_LINE6," ");
TextOut(10,LCD_LINE7," ");
TextOut(10,LCD_LINE8," ");
}
task acao(){
while(true){
if(mudar_sentido_1==0 && mudar_sentido_2==0){
if(canal_1==1 && sentido_1==1 && sentido_2==2){
limpar_lcd();
TextOut(10,LCD_LINE4,"Recebendo");
TextOut(10,LCD_LINE5,"bolinhas");
TextOut(10,LCD_LINE6,"Enviando 1");
TextOut(10,LCD_LINE7,"para esteira");
for(i=0;i<10;i++){
SendRemoteNumber(1,5,1);
Wait(50);
}
Wait(2000);
mudar_sentido_1=1;
mudar_sentido_2=1;
limpar_lcd();
TextOut(10,LCD_LINE6,"Enviando 1");
TextOut(10,LCD_LINE7,"para carrinho");
for(i=0;i<10;i++){
SendRemoteNumber(2,4,1);
Wait(50);
}
limpar_lcd();
//canal_1=0;
}
if(canal_2==1 && sentido_1==2 && sentido_2==1){
limpar_lcd();
TextOut(10,LCD_LINE4,"Soltando");
TextOut(10,LCD_LINE5,"bolinhas");
OnFwd(OUT_C,40);
Wait(400);
Off(OUT_C);
Wait(1500);
OnRev(OUT_C,40);
Wait(350);
Off(OUT_C);
Wait(2000);
limpar_lcd();
TextOut(10,LCD_LINE6,"Enviando 1");
TextOut(10,LCD_LINE7,"para carrinho");
for(i=0;i<10;i++){
SendRemoteNumber(2,4,1);
Wait(50);
}
mudar_sentido_1=1;
mudar_sentido_2=1;
limpar_lcd();
canal_2=0;
}
if(canal_1==0 || canal_2==0){
TextOut(10,LCD_LINE8,"Aguardando..");
}
}
}
}
sub BTCheck(int x){
if(!BluetoothStatus(x)==NO_ERR){
switch(x){
case 1:{
TextOut(5,LCD_LINE2,"Erro na conexao");
TextOut(5,LCD_LINE3,"da esteira");
Wait(2000);
Stop(true);
break;
}
case 2:{
TextOut(5,LCD_LINE2,"Erro na conexao");
TextOut(5,LCD_LINE3,"do carrinho");
Wait(2000);
Stop(true);
break;
}
default:{
}
}
}
}
task motor_1(){
while(true){
if(mudar_sentido_1){
switch(sentido_1){
case 1:{
OnFwd(OUT_A,50);
until(SENSOR_2==1);
Off(OUT_A);
sentido_1=2;
break;
}
case 2:{
OnRev(OUT_A,50);
until(SENSOR_3==1);
Off(OUT_A);
sentido_1=1;
break;
}
default:{
}
}
mudar_sentido_1=0;
}
}
}
task motor_2(){
while(true){
if(mudar_sentido_2){
switch(sentido_2){
case 1:{
OnFwd(OUT_B,40);
until(SENSOR_1==1);
Off(OUT_B);
sentido_2=2;
break;
}
case 2:{
OnRev(OUT_B,40);
until(SENSOR_4==1);
Off(OUT_B);
sentido_2=1;
break;
}
default:{
break;
}
}
mudar_sentido_2=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);
TextOut(10,LCD_LINE1," Master");
TextOut(10,LCD_LINE2," Funcionando");
Precedes(motor_1,motor_2,canal,acao);
//SendRemoteNumber(BT_CONN,OUTBOX,i);
//ReceiveRemoteNumber(INBOX,true,ack);
}
Nenhum comentário:
Postar um comentário