Blame | Last modification | View Log | Download
#include "D:\@Kaklik\programy\PIC_C\robot\auto\main.h"#DEFINE CIDLO1L PIN_B0#DEFINE CIDLO1R PIN_B1#DEFINE CIDLO2L PIN_B2#DEFINE CIDLO2R PIN_B3#DEFINE RELE1 PIN_B5#DEFINE RELE2 PIN_B6#DEFINE MOTOR1 PIN_B4#DEFINE MOTOR2 PIN_A0#DEFINE MOTOR2a PIN_A1#DEFINE LASER PIN_A2#DEFINE L 0#DEFINE R 1int cara;int movement;void left(){output_high(RELE1);output_high(RELE2);delay_ms(100);output_high(MOTOR1);output_high(MOTOR2);output_high(MOTOR2a);}void right(){output_low(RELE1);output_low(RELE2);delay_ms(100);output_high(MOTOR1);output_high(MOTOR2);output_high(MOTOR2a);}void rovne(){output_low(RELE1); // oba motory vpredoutput_high(RELE2);delay_ms(100);output_high(MOTOR1);output_high(MOTOR2);output_high(MOTOR2a);}void stop(){output_low(MOTOR1);output_low(MOTOR2);output_low(MOTOR2a);delay_ms(100);}void main(){cara=L;movement=R;output_low(RELE1); // oba motory vpredoutput_high(RELE2);delay_ms(100);while (true){if (!input(CIDLO1R)) cara=R; // cara vpravoif (!input(CIDLO1L)) cara=L; // cara vlevoif (!input(CIDLO1L) || !input(CIDLO1R)){stop();rovne();delay_ms(100);};if (cara != movement){switch(cara){case L:output_high(LASER);stop();left();movement=L;break;case R:output_low(LASER);stop();right();movement=R;break;}}}}