first commit
This commit is contained in:
21
libraries/Sensor/LICENSE
Executable file
21
libraries/Sensor/LICENSE
Executable file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 Alex Piechowski
|
||||
|
||||
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.
|
||||
2
libraries/Sensor/README.md
Executable file
2
libraries/Sensor/README.md
Executable file
@@ -0,0 +1,2 @@
|
||||
# Sensor
|
||||
A simple Arduino Sensor/map wrapper
|
||||
10
libraries/Sensor/library.properties
Executable file
10
libraries/Sensor/library.properties
Executable file
@@ -0,0 +1,10 @@
|
||||
name=Sensor
|
||||
version=0.1.0
|
||||
author=Alex Piechowski
|
||||
maintainer=Alex Piechowski
|
||||
sentence=A simple Arduino Sensor/map wrapper
|
||||
paragraph=This sensor wrapper makes retreiving mapped sensor values a breeze
|
||||
category=Signal Input/Output
|
||||
url=https://github.com/pachonk/Sensor
|
||||
architectures=*
|
||||
includes=Sensor.h
|
||||
19
libraries/Sensor/src/Sensor.cpp
Executable file
19
libraries/Sensor/src/Sensor.cpp
Executable file
@@ -0,0 +1,19 @@
|
||||
#include "Arduino.h"
|
||||
#include "Sensor.h"
|
||||
|
||||
#define NUMSAMPLES 5
|
||||
|
||||
Sensor::Sensor(int pin, double min_voltage, double max_voltage, double min_value, double max_value)
|
||||
: pin(pin), min_voltage(min_voltage), max_voltage(max_voltage), min_value(min_value), max_value(max_value) {}
|
||||
|
||||
|
||||
float Sensor::value() {
|
||||
float value;
|
||||
for (unsigned int i = 0; i < NUMSAMPLES; i++) {
|
||||
value += analogRead(pin);
|
||||
}
|
||||
|
||||
value /= NUMSAMPLES;
|
||||
|
||||
return map(value, min_voltage, max_voltage, min_value, max_value);
|
||||
}
|
||||
25
libraries/Sensor/src/Sensor.h
Executable file
25
libraries/Sensor/src/Sensor.h
Executable file
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// Created by alex on 6/1/17.
|
||||
//
|
||||
|
||||
#ifndef SENSOR_H
|
||||
#define SENSOR_H
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
class Sensor {
|
||||
public:
|
||||
Sensor(int pin, double min_voltage, double max_voltage, double min_value, double max_value);
|
||||
|
||||
float value();
|
||||
|
||||
private:
|
||||
int pin;
|
||||
double min_voltage;
|
||||
double max_voltage;
|
||||
double min_value;
|
||||
double max_value;
|
||||
};
|
||||
|
||||
|
||||
#endif //SENSOR_H
|
||||
Reference in New Issue
Block a user