-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 60e99c8
Showing
6 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Simon Pucheu | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 @@ | ||
# HCSR04 |
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,27 @@ | ||
####################################### | ||
# Syntax Coloring Map | ||
####################################### | ||
|
||
####################################### | ||
# Datatypes (KEYWORD1) | ||
####################################### | ||
|
||
HCSR04 KEYWORD1 | ||
|
||
####################################### | ||
# Methods and Functions (KEYWORD2) | ||
####################################### | ||
|
||
getRawValue KEYWORD2 | ||
getValue KEYWORD2 | ||
|
||
####################################### | ||
# Variables (KEYWORD3) | ||
####################################### | ||
|
||
triggerPin KEYWORD3 | ||
echoPin KEYWORD3 | ||
|
||
###################################### | ||
# 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,11 @@ | ||
name=HCSR04 | ||
version=1.0.0 | ||
author=Simon Pucheu | ||
maintainer=Simon Pucheu | ||
sentence=None | ||
paragraph=None | ||
category=Sensors | ||
url=https://github.com/IngeniumTeam/HCSR04 | ||
architectures=avr | ||
includes=HCSR04.h | ||
depends= |
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,47 @@ | ||
#include <Arduino.h> | ||
|
||
#include "HCSR04.h" | ||
|
||
/** | ||
* Setup the HCSR04 | ||
*/ | ||
HCSR04::HCSR04(uint8_t iTriggerPin, uint8_t iEchoPin, int iLowLimit = 1, int iHighLimit = 100) | ||
{ | ||
triggerPin = iTriggerPin; | ||
echoPin = iEchoPin; | ||
lowLimit = iLowLimit; | ||
highLimit = iHighLimit; | ||
} | ||
|
||
/** | ||
* Get the raw value of readed the HCSR04 | ||
* | ||
* @return int the distance in centimeters readed on the HCSR04 | ||
*/ | ||
bool HCSR04::getRawValue() | ||
{ | ||
digitalWrite(triggerPin, LOW); | ||
delayMicroseconds(2); | ||
digitalWrite(triggerPin, HIGH); | ||
delayMicroseconds(10); | ||
digitalWrite(triggerPin, LOW); | ||
duration = pulseIn(echoPin, HIGH); | ||
distance = duration * 0.034 / 2; | ||
return distance; | ||
} | ||
|
||
/** | ||
* Get the value of the HCSR04 after treatment | ||
* | ||
* @return int -1 if the `rawValue` is less than the `lowLimit`, -2 if more than the `highLimit` and the `rawValue` otherwise | ||
*/ | ||
int HCSR04::getValue() | ||
{ | ||
int value; | ||
int rawValue = getRawValue(); | ||
if (rawValue < lowLimit) | ||
value = -1; | ||
if (rawValue > highLimit) | ||
value = -2; | ||
return value; | ||
} |
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,13 @@ | ||
#include <Arduino.h> | ||
|
||
class HCSR04 | ||
{ | ||
public: | ||
HCSR04(uint8_t iTriggerPin, uint8_t iEchoPin, int iLowLimit = 1, int iHighLimit = 100); | ||
int getRawValue(); | ||
int getValue(); | ||
uint8_t triggerPin; | ||
uint8_t echoPin; | ||
int lowLimit = 1; | ||
int highLimit = 100; | ||
}; |