Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <util/delay.h>
- const int trigPin = 13;
- const int echoPin = 12;
- int main (void){
- delay (5000);
- DDRD = B00111100;
- DDRD = DDRD |B00111100;
- unsigned char sensor_pino_6;
- unsigned char sensor_pino_7;
- unsigned long duracao = 0;
- float distancia;
- DDRB = B11101111;
- Serial.begin(9600);
- while (1) {
- sensor_pino_6 = (PIND & 64)>> 6;
- sensor_pino_7 = (PIND & 128)>> 7;
- PORTB = 0B00000000;
- delayMicroseconds(2);
- PORTB = 0B00100000;
- delayMicroseconds(10);
- PORTB = 0B00000000;
- duracao = 0;
- while (!(PINB & 16)>> 4);
- while ((PINB & 16)>> 4) {
- duracao++;
- }
- if (duracao > 0){
- distancia= duracao * 0.00945;
- }
- if (sensor_pino_6 == 0 && sensor_pino_7 == 0 && distancia < 45){
- PORTD = B00100100;
- }
- else if (sensor_pino_6 == 1 ) {
- if (distancia < 45) {
- PORTD = B00000000;
- }
- else {
- PORTD = B00100100;
- }
- else if (sensor_pino_7) {
- if (distancia < 45) {
- PORTD = B00100100;
- }
- else {
- PORTD = B00011000;
- }
- }
- else {
- analogWrite (9, 80);
- analogWrite(10, 80);
- PORTD = B00101000;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement