Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonPucheu authored Nov 24, 2022
0 parents commit 60e99c8
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
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.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# HCSR04
27 changes: 27 additions & 0 deletions keywords.txt
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)
#######################################
11 changes: 11 additions & 0 deletions library.properties
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=
47 changes: 47 additions & 0 deletions src/HCSR04.cpp
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;
}
13 changes: 13 additions & 0 deletions src/HCSR04.h
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;
};

0 comments on commit 60e99c8

Please sign in to comment.