forked from LeoColomb/Arduino-SRF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSonarSRF.h
45 lines (38 loc) · 1.08 KB
/
SonarSRF.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// SonarSRF
// Arduino Library for controlling SRF sonar sensors
// http://www.arduino.cc/playground/Main/SonarSrf08
//
// MIT License
// Copyright(c) 2009 Zach Foresta
// Copyright(c) 2012 Leo Colombaro
// Copyright(c) 2012 Philipp A. Mohrenweiser
//
// Sensor connections:
// * SDA - Analog pin 4
// * SCL - Analog pin 5
#ifndef SonarSRF_h
#define SonarSRF_h
#include <Wire.h>
#include <Arduino.h>
#define INCHES 0x50
#define CENTIMETERS 0x51
#define MICROSECONDS 0x52
#define COMMAND_REGISTER (byte)0x00
#define RESULT_REGISTER 0x02
class SonarSRF
{
public:
void connect(int address, int gainRegister = NULL, int rangeLocation = NULL);
virtual void startRanging(char unit);
virtual int getRange(char unit = 'c', bool andStart = true);
int getSoft();
void changeAddress(int newAddress);
protected:
virtual void waitForCompletion();
void sendCommand(int command = NULL, int addressRegister = COMMAND_REGISTER);
int _address;
int _gainRegister;
int _rangeLocation;
};
#endif