36 lines
824 B
C
36 lines
824 B
C
#ifndef SONAR_H
|
|
#define SONAR_H
|
|
|
|
#include "common.h"
|
|
|
|
// Trigger
|
|
#define TRIG_DDR DDRC
|
|
#define TRIG_PORT PORTC
|
|
#define TRIG_PIN PINC
|
|
#define TRIG_BIT PC4
|
|
|
|
// Echo
|
|
#define ECHO_DDR DDRC
|
|
#define ECHO_PORT PORTC
|
|
#define ECHO_PIN PINC
|
|
#define ECHO_BIT PC5
|
|
|
|
#define SPEED_OF_SOUND 343 // (m/s)
|
|
#define US_PER_CM 58 // Time for sound to travel distance of 1cm
|
|
#define MAX_SONAR_RANGE 8 // Trigger + echo (m)
|
|
#define DELAY_BETWEEN_TESTS 500 // Timeout for return signal
|
|
#define TIMER_MAX 65535 // Depends on the timer used
|
|
|
|
#define CYCLES_PER_US F_CPU / 1000000
|
|
#define SONAR_TIMEOUT (F_CPU * MAX_SONAR_RANGE) / SPEED_OF_SOUND
|
|
|
|
#define TRIG_ERROR -1
|
|
#define ECHO_ERROR -2
|
|
|
|
|
|
void init_sonar(void);
|
|
void trigger_sonar(void);
|
|
int read_sonar(void);
|
|
|
|
#endif /* SONAR_H */
|