Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gamegine committed Apr 29, 2018
1 parent 643e800 commit 4fd3d75
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 1 deletion.
Binary file added HC_SR04.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 39 additions & 1 deletion README.md
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)
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-slate
9 changes: 9 additions & 0 deletions examples/HCSR04/HCSR04.ino
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
Binary file added examples/HCSR04/HC_SR04_cabling.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions keywords.txt
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) #
#######################################
9 changes: 9 additions & 0 deletions library.properties
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=*
24 changes: 24 additions & 0 deletions src/HCSR04.cpp
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;
}
12 changes: 12 additions & 0 deletions src/HCSR04.h
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
};

0 comments on commit 4fd3d75

Please sign in to comment.