Demo entry 6721520

task1

   

Submitted by anonymous on Mar 21, 2018 at 22:38
Language: C. Code size: 2.0 kB.

#include <p30F6014A.h>
#include <motor_led/e_epuck_ports.h>
#include <motor_led/e_init_port.h>
#include <a_d/advance_ad_scan/e_prox.h>
#include <a_d/advance_ad_scan/e_ad_conv.h>
#include <uart/e_uart_char.h>
#include <stdio.h>

void Wait(long);
int GetSelector(void);
int main()
{
    e_calibrate_ir();
    e_init_motors();
    e_start_agendas_processing();
    e_init_uart1();
 char Buffer[100];
int Buff_Len;
// Initialisation.
e_init_port(); // Initialises the ports.
e_init_ad_scan(ALL_ADC); // Initialises ADC.
e_led_clear(); // Turn off all the LEDs.
e_init_uart1(); // Initialises the UART.
e_start_agendas_processing(); // Allows multiple tasking.

int s0;
int s1;
int s2;
int s3;
int s4;
int s5;
int s6;
int s7;

Wait(4000000);
e_set_speed_left(500);
e_set_speed_right(500);
                    
while(1){
        
        s0 = e_get_prox(0);
        s1 = e_get_prox(1);
        s2 = e_get_prox(2);
        s3 = e_get_prox(3);
        s4 = e_get_prox(4);
        s5 = e_get_prox(5);
        s6 = e_get_prox(6);
        s7 = e_get_prox(7);
   
        if(s7 > 100 || s0 > 100 )
        {                    
                    e_set_speed_left(0);
                    e_set_speed_right(0);
            if( (s2 >= s5) || (s1 >= s6))
                {
                    e_set_speed_left(0);
                    e_set_speed_right(250);
                }
            else if(s2 < s5)
                {
                    e_set_speed_left(250);
                    e_set_speed_right(0);
                }     
        }
        else if( (s1 < 130 && s2 < 350) && (s6 < 130 && s5 < 350) )
        {
                    e_set_led(0,1);
                    e_set_speed_left(500);
                    e_set_speed_right(500);
        }
    }
    return 0;
}
void Wait(long Duration)
{
    long i;
    for(i=0;i<Duration;i++);
}
int GetSelector() {
    return SELECTOR0 + 2*SELECTOR1 + 4*SELECTOR2 + 8*SELECTOR3;
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).