-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,39 @@ | ||
# hcsr04 | ||
= HCSR04 ultrasonic sensor Library for Arduino = | ||
========== | ||
HCSR04 is an [Arduino](http://arduino.cc) library HCSR04 Sensors | ||
|
||
![HC-SR04](HC_SR04.jpg) | ||
|
||
Documentation | ||
------------- | ||
Documentation for the library is on the | ||
[Github Project Pages](https://github.com/gamegine/HCSR04-ultrasonic-sensor-lib) | ||
|
||
[basic example](examples/HCSR04/HCSR04.ino) | ||
|
||
![schéma](examples/HCSR04/HC_SR04_cabling.jpg) | ||
```ino | ||
#include <HCSR04.h> | ||
|
||
HCSR04 hc(2,3);//initialisation class HCSR04 (trig pin , echo pin) | ||
|
||
void setup() | ||
{ Serial.begin(9600); } | ||
|
||
void loop() | ||
{ Serial.println( hc.dist() ); } //return current distance (cm) in serial | ||
``` | ||
Download | ||
-------- | ||
The last version of the Library is available on the github | ||
[HCSR04 Page](https://github.com/gamegine/HCSR04-ultrasonic-sensor-lib/releases) | ||
Install | ||
------- | ||
The library can be installed using the [standard Arduino library install procedure](http://arduino.cc/en/Guide/Libraries) | ||
[License](https://github.com/gamegine/HCSR04-ultrasonic-sensor-lib/blob/master/LICENSE) | ||
------- | ||
[MIT License](https://github.com/gamegine/HCSR04-ultrasonic-sensor-lib/blob/master/LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
theme: jekyll-theme-slate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <HCSR04.h> | ||
|
||
HCSR04 hc(5,6);//initialisation class HCSR04 (trig pin , echo pin) | ||
|
||
void setup() | ||
{ Serial.begin(9600); } | ||
|
||
void loop() | ||
{ Serial.println( hc.dist() ); }//return curent distance in serial |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
####################################### | ||
# Syntax Coloring Map for HCSR04 # | ||
####################################### | ||
|
||
####################################### | ||
# Datatypes (KEYWORD1) # | ||
####################################### | ||
|
||
HCSR04 KEYWORD1 | ||
|
||
####################################### | ||
# Methods and Functions (KEYWORD2) # | ||
####################################### | ||
|
||
dist KEYWORD2 | ||
|
||
####################################### | ||
# Constants (LITERAL1) # | ||
####################################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name=HCSR04 ultrasonic sensor | ||
version=1.0.0 | ||
author=gamegine | ||
maintainer=gamegine | ||
sentence=Allows an Arduino board to use HCSR04 module. | ||
paragraph=This library allows an Arduino board to use HCSR04 module for get current distance in cm. On the Arduino. | ||
category=Sensors | ||
url=https://github.com/gamegine/HCSR04-ultrasonic-sensor-lib | ||
architectures=* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "HCSR04.h" | ||
////////////////////////////////////consttruct/destruct | ||
HCSR04::HCSR04(int out,int echo) | ||
{ | ||
this->out = out; | ||
this->echo = echo; | ||
pinMode(this->out, OUTPUT); | ||
pinMode(this->echo, INPUT); | ||
} | ||
HCSR04::~HCSR04() | ||
{ | ||
~this->out; | ||
~this->echo; | ||
} | ||
///////////////////////////////////////////////////dist | ||
float HCSR04::dist() const | ||
{ | ||
digitalWrite(this->out, LOW); | ||
delayMicroseconds(2); | ||
digitalWrite(this->out, HIGH); | ||
delayMicroseconds(10); | ||
digitalWrite(this->out, LOW); | ||
return pulseIn(this->echo, HIGH) / 58.0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <Arduino.h> | ||
class HCSR04 | ||
{ | ||
public: | ||
HCSR04(int out,int echo); //initialisation class HCSR04 (trig pin , echo pin) | ||
~HCSR04(); //destructor | ||
float dist() const; //return curent distance of element 0 | ||
|
||
private: | ||
int out; //out pin | ||
int echo; //echo pin list | ||
}; |