Skip to content

Commit 4fd3d75

Browse files
committed
v1.0.0
1 parent 643e800 commit 4fd3d75

File tree

9 files changed

+113
-1
lines changed

9 files changed

+113
-1
lines changed

HC_SR04.jpg

62.4 KB
Loading

README.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,39 @@
1-
# hcsr04
1+
= HCSR04 ultrasonic sensor Library for Arduino =
2+
==========
3+
HCSR04 is an [Arduino](http://arduino.cc) library HCSR04 Sensors
4+
5+
![HC-SR04](HC_SR04.jpg)
6+
7+
Documentation
8+
-------------
9+
Documentation for the library is on the
10+
[Github Project Pages](https://github.com/gamegine/HCSR04-ultrasonic-sensor-lib)
11+
12+
[basic example](examples/HCSR04/HCSR04.ino)
13+
14+
![schéma](examples/HCSR04/HC_SR04_cabling.jpg)
15+
```ino
16+
#include <HCSR04.h>
17+
18+
HCSR04 hc(2,3);//initialisation class HCSR04 (trig pin , echo pin)
19+
20+
void setup()
21+
{ Serial.begin(9600); }
22+
23+
void loop()
24+
{ Serial.println( hc.dist() ); } //return current distance (cm) in serial
25+
```
26+
27+
Download
28+
--------
29+
The last version of the Library is available on the github
30+
[HCSR04 Page](https://github.com/gamegine/HCSR04-ultrasonic-sensor-lib/releases)
31+
32+
33+
Install
34+
-------
35+
The library can be installed using the [standard Arduino library install procedure](http://arduino.cc/en/Guide/Libraries)
36+
37+
[License](https://github.com/gamegine/HCSR04-ultrasonic-sensor-lib/blob/master/LICENSE)
38+
-------
39+
[MIT License](https://github.com/gamegine/HCSR04-ultrasonic-sensor-lib/blob/master/LICENSE)

_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
theme: jekyll-theme-slate

examples/HCSR04/HCSR04.ino

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <HCSR04.h>
2+
3+
HCSR04 hc(5,6);//initialisation class HCSR04 (trig pin , echo pin)
4+
5+
void setup()
6+
{ Serial.begin(9600); }
7+
8+
void loop()
9+
{ Serial.println( hc.dist() ); }//return curent distance in serial
41.8 KB
Loading

keywords.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#######################################
2+
# Syntax Coloring Map for HCSR04 #
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1) #
7+
#######################################
8+
9+
HCSR04 KEYWORD1
10+
11+
#######################################
12+
# Methods and Functions (KEYWORD2) #
13+
#######################################
14+
15+
dist KEYWORD2
16+
17+
#######################################
18+
# Constants (LITERAL1) #
19+
#######################################

library.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=HCSR04 ultrasonic sensor
2+
version=1.0.0
3+
author=gamegine
4+
maintainer=gamegine
5+
sentence=Allows an Arduino board to use HCSR04 module.
6+
paragraph=This library allows an Arduino board to use HCSR04 module for get current distance in cm. On the Arduino.
7+
category=Sensors
8+
url=https://github.com/gamegine/HCSR04-ultrasonic-sensor-lib
9+
architectures=*

src/HCSR04.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "HCSR04.h"
2+
////////////////////////////////////consttruct/destruct
3+
HCSR04::HCSR04(int out,int echo)
4+
{
5+
this->out = out;
6+
this->echo = echo;
7+
pinMode(this->out, OUTPUT);
8+
pinMode(this->echo, INPUT);
9+
}
10+
HCSR04::~HCSR04()
11+
{
12+
~this->out;
13+
~this->echo;
14+
}
15+
///////////////////////////////////////////////////dist
16+
float HCSR04::dist() const
17+
{
18+
digitalWrite(this->out, LOW);
19+
delayMicroseconds(2);
20+
digitalWrite(this->out, HIGH);
21+
delayMicroseconds(10);
22+
digitalWrite(this->out, LOW);
23+
return pulseIn(this->echo, HIGH) / 58.0;
24+
}

src/HCSR04.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <Arduino.h>
2+
class HCSR04
3+
{
4+
public:
5+
HCSR04(int out,int echo); //initialisation class HCSR04 (trig pin , echo pin)
6+
~HCSR04(); //destructor
7+
float dist() const; //return curent distance of element 0
8+
9+
private:
10+
int out; //out pin
11+
int echo; //echo pin list
12+
};

0 commit comments

Comments
 (0)