// pega t 2.c - Criado pelo studio UNO 2.3
// 18 April 2016 7:30:00 pm
#include <uno.h>
// Declaracao das Variaveis
unsigned int tempo;
// Prototipos
void retinho(void);
void freio(void);
//Funcoes do Usuario
void retinho(void)
{
if ((__EncoderGetValue(1) > __EncoderGetValue(2))) {
__motor_curso(__LEFT_TURN);
}
if ((__EncoderGetValue(2) > __EncoderGetValue(1))) {
__motor_curso(__RIGHT_TURN);
}
if ((__EncoderGetValue(2) == __EncoderGetValue(1))) {
__motor_curso(__FORWARD);
}
}
void freio(void)
{
__motor_curso(__REVERSE);
__delay(30);
__motor_curso(__STOP);
}
//Funcao Principal
void main(void)
{
__inicializa;
__SmartSensorCmd(1, 1, 8, 0);
__SmartSensorCmd(1, 1, 9, 0);
__SmartSensorCmd(1, 2, 9, 0);
bitset(__TRIS_PWM, __DIGITAL1);
__PWM1 = 180;
__delay(500);
__timer_sistema = 0;
while((__analog_in(0) < 500)) {
retinho();
}
tempo = __timer_sistema;
freio();
__PWM1 = 35;
__delay(500);
__SmartSensorCmd(1, 2, 9, 0);
__motor_curso(__LEFT_ROTATE);
while((__EncoderGetValue(2) <= 34)) {
while(!(__EncoderGetValue(2) > 34)) { __delay(10); }
}
__SmartSensorCmd(1, 1, 9, 0);
__SmartSensorCmd(1, 2, 9, 0);
__timer_sistema = 0;
while((__timer_sistema <= tempo)) {
retinho();
}
freio();
__PWM1 = 180;
while(TRUE) { }
}