Advertisement
Guest User

CodeRobot

a guest
Mar 21st, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.51 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <util/delay.h>
  3.  
  4. const int trigPin = 13;
  5. const int echoPin = 12;
  6.  
  7. int main (void){
  8.     delay  (5000);
  9.     DDRD = B00111100;
  10.     DDRD = DDRD |B00111100;
  11.     unsigned char sensor_pino_6;
  12.     unsigned char sensor_pino_7;
  13.     unsigned long duracao = 0;
  14.     float distancia;
  15.     DDRB = B11101111;
  16.     Serial.begin(9600);
  17.  
  18.     while (1) {
  19.         sensor_pino_6 = (PIND & 64)>> 6;
  20.         sensor_pino_7 = (PIND & 128)>> 7;
  21.         PORTB = 0B00000000;
  22.         delayMicroseconds(2);
  23.         PORTB = 0B00100000;
  24.         delayMicroseconds(10);
  25.         PORTB = 0B00000000;
  26.         duracao = 0;
  27.         while (!(PINB & 16)>> 4);
  28.         while ((PINB & 16)>> 4)   {
  29.              duracao++;
  30.         }
  31.  
  32.         if (duracao > 0){
  33.             distancia= duracao * 0.00945;
  34.         }
  35.  
  36.         if (sensor_pino_6 == 0 && sensor_pino_7 == 0 && distancia < 45){
  37.             PORTD = B00100100;
  38.         }
  39.  
  40.         else if (sensor_pino_6 == 1 ) {
  41.             if (distancia < 45) {
  42.                 PORTD = B00000000;
  43.             }
  44.             else {
  45.                 PORTD = B00100100;
  46.             }
  47.             else if (sensor_pino_7) {
  48.                 if (distancia < 45) {
  49.                     PORTD = B00100100;
  50.                 }
  51.                 else {
  52.                     PORTD = B00011000;
  53.                 }
  54.             }
  55.             else {
  56.                 analogWrite (9, 80);
  57.                 analogWrite(10, 80);
  58.                 PORTD = B00101000;
  59.             }
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement