// navegador auto e manual.c - Criado pelo studio UNO 2.3
// 23 July 2016 5:15:58 pm
#include <uno.h>
// Declaracao das Variaveis
unsigned char A;
unsigned char Acex;
unsigned char Acey;
unsigned char Acez;
unsigned char B;
unsigned char Botc;
unsigned char Botz;
unsigned char Joyx;
unsigned char Joyy;
// Prototipos
void Ajustes RF(void);
void Controle RF(void);
void Esquerda(void);
void Direita(void);
//Funcoes do Usuario
void Ajustes RF(void)
{
Acex = __ControllerGetAccelerometer_X(1);
__delay(5);
Acey = __ControllerGetAccelerometer_Y(1);
__delay(5);
Acez = __ControllerGetAccelerometer_Z(1);
__delay(5);
Joyx = __ControllerGetJoystick_X(1);
__delay(5);
Joyy = __ControllerGetJoystick_Y(1);
__delay(5);
Botc = __ControllerGetButton_C(0);
__delay(5);
Botz = __ControllerGetButton_Z(0);
__delay(5);
}
void Controle RF(void)
{
__lcd_clear();
__lcd_goto(0x7f, 6);
__lcd_puts("Manual");
while(TRUE) {
Ajustes RF();
if ((Botz == 1)) {
return;
}
if ((Joyx == 255)) {
__motor_curso(__RIGHT_TURN);
}
if ((Joyx == 0)) {
__motor_curso(__LEFT_TURN);
}
if ((Joyy == 255)) {
__motor_curso(__FORWARD);
}
if ((Joyy == 0)) {
__motor_curso(__BACKWARD);
}
if ((Acey > 100)) {
__motor_curso(__REVERSE);
__delay(10);
__motor_curso(__STOP);
}
}
}
void Esquerda(void)
{
__motor_curso(__BACKWARD);
__delay(2000);
__motor_curso(__LEFT_TURN);
__delay(600);
}
void Direita(void)
{
__motor_curso(__BACKWARD);
__delay(2000);
__motor_curso(__RIGHT_TURN);
__delay(600);
}
//Funcao Principal
void main(void)
{
__inicializa;
__backlight(__ON);
A = 0;
B = 0;
while(TRUE) {
__lcd_clear();
__lcd_goto(0x7f, 5);
__lcd_puts("Autonomo");
__motor(1, 990);
__motor(2, 990);
if (!__digital_in(5)) {
if ((A == 5)) {
Direita();
B = 0;
}
else {
B++;
if ((B > 3)) {
B = 0;
Esquerda();
}
else {
Direita();
}
}
A = 5;
}
if (!__digital_in(6)) {
if ((A == 6)) {
Esquerda();
B = 0;
}
else {
if ((B > 3)) {
B = 0;
Direita();
}
else {
Esquerda();
}
B++;
}
A = 6;
}
if ((__ControllerGetButton_C(1) || (Botc == 1))) {
Controle RF();
}
}
while(TRUE) { }
}