Skip to content

Commit 901aec5

Browse files
committed
Add SRF10
1 parent 7ebdcc0 commit 901aec5

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

examples/SRF10/SRF10.ino

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// SonarSRF10
3+
// Arduino Library for controlling SRF sonar sensors
4+
// http://www.arduino.cc/playground/Main/SonarSrf08
5+
//
6+
// MIT License
7+
// Copyright(c) 2009 Zach Foresta
8+
// Copyright(c) 2012 Philipp A. Mohrenweiser
9+
// Copyright(c) 2012-2016 Leo Colombaro
10+
//
11+
12+
#include <Wire.h>
13+
#include <SonarSRF10.h>
14+
15+
#define MAIN_10_ADDRESS (0xF8 >> 1)
16+
SonarSRF10 MainSonar(MAIN_10_ADDRESS);
17+
18+
char unit = 'c'; // 'i' for inches, 'c' for centimeters, 'm' for micro-seconds
19+
20+
void setup()
21+
{
22+
Serial.begin(9600);
23+
24+
MainSonar.begin();
25+
isConnected("SRF10", MainSonar.readVersion());
26+
}
27+
28+
void loop()
29+
{
30+
distance("SRF10", MainSonar.readRange(unit));
31+
}
32+
33+
// Print out distance
34+
void distance(String reference, int sensorReading)
35+
{
36+
Serial.print("Distance from " + reference + ": ");
37+
Serial.print(sensorReading);
38+
Serial.println(unit);
39+
}
40+
41+
// Print out distance
42+
void isConnected(String reference, int sensorSoft)
43+
{
44+
if (sensorSoft >= 0)
45+
{
46+
Serial.print("Sensor " + reference + " connected (");
47+
Serial.print(sensorSoft);
48+
Serial.println(")");
49+
}
50+
else
51+
{
52+
Serial.println("Sensor " + reference + " not detected...");
53+
}
54+
}

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
SonarSRF KEYWORD1
1010
SonarSRF02 KEYWORD1
1111
SonarSRF08 KEYWORD1
12+
SonarSRF10 KEYWORD1
1213

1314
#######################################
1415
# Methods and Functions (KEYWORD2)

src/SonarSRF10.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// SonarSRF
3+
// Arduino Library for controlling SRF sonar sensors
4+
// http://www.arduino.cc/playground/Main/SonarSrf08
5+
//
6+
// MIT License
7+
// Copyright(c) 2009 Zach Foresta
8+
// Copyright(c) 2012 Philipp A. Mohrenweiser
9+
// Copyright(c) 2012-2016 Leo Colombaro
10+
//
11+
12+
#ifndef SONARSRF10_H
13+
#define SONARSRF10_H
14+
15+
#include "SonarSRF.h"
16+
17+
class SonarSRF10 : public SonarSRF
18+
{
19+
public:
20+
SonarSRF10(int address, int gainRegister = 0, int rangeLocation = 0)
21+
: SonarSRF(address, gainRegister, rangeLocation) {};
22+
};
23+
24+
#endif // SONARSRF10_H

0 commit comments

Comments
 (0)