feat: 全量同步 254 个常用的 Arduino 扩展库文件
This commit is contained in:
32
arduino-libs/arduino-cli/libraries/ML8511_uv_sensor_arduino_library/.gitignore
vendored
Normal file
32
arduino-libs/arduino-cli/libraries/ML8511_uv_sensor_arduino_library/.gitignore
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
@@ -0,0 +1,8 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map For ML8511
|
||||
#######################################
|
||||
Datatypes KEYWORD1
|
||||
ML8511 KEYWORD1
|
||||
begin KEYWORD2
|
||||
getoutputVoltage KEYWORD2
|
||||
getuvIntensity KEYWORD2
|
||||
@@ -0,0 +1,165 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
@@ -0,0 +1 @@
|
||||
# ML8511 sensor library for Arduino and Arduino compatible boards.
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
ML8511_library_test.ino
|
||||
Emanuele Signoretta, 2017
|
||||
*/
|
||||
#include <ML8511.h>
|
||||
|
||||
#define UVOUT A0 // define the pin attached to the ML8511 output
|
||||
#define REF_3V3 A1 //define the 3.3 reference pin
|
||||
|
||||
double uvIntensity;
|
||||
double outputVoltage;
|
||||
|
||||
|
||||
ML8511 uv(UVOUT, REF_3V3); //create the ML8511's uv object
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200); // begin the serial communication
|
||||
Serial.print("ML8511 uv sensor library test. \n \n");
|
||||
Serial.print("Emanuele Signoretta. 2017 \n \n");
|
||||
Serial.print("Starting sensor. ");
|
||||
|
||||
while (!uv.begin()) { //wait until the sensor is ready
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
Serial.println("Sensor started!");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
outputVoltage = uv.getoutputVoltage(); // get the output voltage from the sensor
|
||||
uvIntensity = uv.getuvIntensity(); // get the UV intensity from the sensor
|
||||
|
||||
|
||||
//print the data on the serial port
|
||||
Serial.print("Output voltage: ");
|
||||
Serial.print(outputVoltage);
|
||||
Serial.print(" v ");
|
||||
Serial.print("UV intensity: ");
|
||||
Serial.print(uvIntensity);
|
||||
Serial.println(" mW/cm^2.");
|
||||
delay (1000);
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
ML8511 UV Sensor Read Example
|
||||
By: Nathan Seidle
|
||||
SparkFun Electronics
|
||||
Date: January 15th, 2014
|
||||
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
|
||||
|
||||
The ML8511 UV Sensor outputs an analog signal in relation to the amount of UV light it detects.
|
||||
|
||||
These last two connections are a little different. Connect the EN pin on the breakout to 3.3V on the breakout.
|
||||
This will enable the output. Also connect the 3.3V pin of the breakout to Arduino pin 1.
|
||||
|
||||
This example uses a neat trick. Analog to digital conversions rely completely on VCC. We assume
|
||||
this is 5V but if the board is powered from USB this may be as high as 5.25V or as low as 4.75V:
|
||||
http://en.wikipedia.org/wiki/USB#Power Because of this unknown window it makes the ADC fairly inaccurate
|
||||
in most cases. To fix this, we use the very accurate onboard 3.3V reference (accurate within 1%). So by doing an
|
||||
ADC on the 3.3V pin (A1) and then comparing this against the reading from the sensor we can extrapolate
|
||||
a true-to-life reading no matter what VIN is (as long as it's above 3.4V).
|
||||
|
||||
Test your sensor by shining daylight or a UV LED: https://www.sparkfun.com/products/8662
|
||||
|
||||
This sensor detects 280-390nm light most effectively. This is categorized as part of the UVB (burning rays)
|
||||
spectrum and most of the UVA (tanning rays) spectrum.
|
||||
|
||||
There's lots of good UV radiation reading out there:
|
||||
http://www.ccohs.ca/oshanswers/phys_agents/ultravioletradiation.html
|
||||
https://www.iuva.org/uv-faqs
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
* Website:
|
||||
https://hshop.vn/products/cam-bien-anh-sang-uvm-30a
|
||||
https://hshop.vn/products/lcd1602-keypad-shield
|
||||
https://hshop.vn/products/vietduino-uno
|
||||
https://hshop.vn/search?type=product&q=day%20cam%20breadboard
|
||||
|
||||
Connect the following ML8511 breakout board to Arduino:
|
||||
3.3V = 3.3V
|
||||
OUT = A2
|
||||
GND = GND
|
||||
EN = 3.3V
|
||||
3.3V = A1
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include <LiquidCrystal.h>
|
||||
LiquidCrystal lcd(8,9,4,5,6,7);
|
||||
|
||||
// https://learn.sparkfun.com/tutorials/ml8511-uv-sensor-hookup-guide
|
||||
|
||||
//Hardware pin definitions
|
||||
int UVOUT = A2; //Output from the sensor
|
||||
int REF_3V3 = A1; //3.3V power on the Arduino board
|
||||
|
||||
const int numReadings = 100;
|
||||
|
||||
int readings[numReadings]; // the readings from the analog input
|
||||
int readIndex = 0; // the index of the current reading
|
||||
int total = 0; // the running total
|
||||
int average = 0; // the average
|
||||
|
||||
int inputPin = A0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
lcd.begin(16, 2);
|
||||
lcd.print("UV value:");
|
||||
pinMode(UVOUT, INPUT);
|
||||
pinMode(REF_3V3, INPUT);
|
||||
|
||||
Serial.println("ML8511 example");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// int uvLevel = averageAnalogRead(UVOUT);
|
||||
float uvLevel = readAnalog_();
|
||||
float refLevel = averageAnalogRead(REF_3V3);
|
||||
|
||||
//Use the 3.3V power pin as a reference to get a very accurate output value from sensor
|
||||
float outputVoltage = 3.3 / refLevel * uvLevel;
|
||||
|
||||
float uvIntensity = mapfloat(outputVoltage, 0.99, 2.8, 0.0, 15.0); //Convert the voltage to a UV intensity level
|
||||
|
||||
Serial.print("output: ");
|
||||
Serial.print(refLevel);
|
||||
|
||||
Serial.print("ML8511 output: ");
|
||||
Serial.print(uvLevel);
|
||||
|
||||
Serial.print(" / ML8511 voltage: ");
|
||||
Serial.print(outputVoltage);
|
||||
|
||||
Serial.print(" / UV Intensity (mW/cm^2): ");
|
||||
Serial.print(uvIntensity);
|
||||
|
||||
Serial.println();
|
||||
lcd.setCursor(0, 1);
|
||||
// print the number of seconds since reset:
|
||||
// String dataStr =
|
||||
lcd.print(String(uvIntensity) + " ");
|
||||
|
||||
delay(100);
|
||||
}
|
||||
|
||||
//Takes an average of readings on a given pin
|
||||
//Returns the average
|
||||
int averageAnalogRead(int pinToRead)
|
||||
{
|
||||
byte numberOfReadings = 300;
|
||||
unsigned int runningValue = 0;
|
||||
|
||||
for(int x = 0 ; x < numberOfReadings ; x++)
|
||||
runningValue += analogRead(pinToRead);
|
||||
runningValue /= numberOfReadings;
|
||||
|
||||
return(runningValue);
|
||||
}
|
||||
|
||||
//The Arduino Map function but for floats
|
||||
//From: http://forum.arduino.cc/index.php?topic=3922.0
|
||||
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
|
||||
{
|
||||
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||
}
|
||||
|
||||
float readAnalog_()
|
||||
{
|
||||
total = total - readings[readIndex];
|
||||
// read from the sensor:
|
||||
readings[readIndex] = analogRead(UVOUT);
|
||||
// add the reading to the total:
|
||||
total = total + readings[readIndex];
|
||||
// advance to the next position in the array:
|
||||
readIndex = readIndex + 1;
|
||||
|
||||
// if we're at the end of the array...
|
||||
if (readIndex >= numReadings) {
|
||||
// ...wrap around to the beginning:
|
||||
readIndex = 0;
|
||||
}
|
||||
|
||||
// calculate the average:
|
||||
average = total / numReadings;
|
||||
// send it to the computer as ASCII digits
|
||||
Serial.print("KXN = " + String(average) + "====");\
|
||||
return average;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
name=ML8511
|
||||
version=1.0.0
|
||||
author=Emanuele Signoretta
|
||||
maintainer=signorettae@gmail.com
|
||||
sentence=
|
||||
paragraph=
|
||||
category=Sensors
|
||||
url=
|
||||
includes=ML8511.h
|
||||
architectures=avr,pic32
|
||||
@@ -0,0 +1,243 @@
|
||||
/*
|
||||
ML8511.cpp- Library for ML8511 UV sensor
|
||||
Copyright (c) 2017 Emanuele Signoretta. All right reserved.
|
||||
Based on the orininal project of Nathan Seidle: https://learn.sparkfun.com/tutorials/ml8511-uv-sensor-hookup-guide
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
|
||||
VERSION 1.0.0 - INITIAL VERSION
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include <ML8511.h>
|
||||
|
||||
|
||||
ML8511::ML8511(uint8_t UVOUT, uint8_t REF3V3) {
|
||||
_REF_3V3 = REF3V3;
|
||||
_UVOUT = UVOUT;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool ML8511::begin(void)
|
||||
{
|
||||
pinMode(_UVOUT, INPUT);
|
||||
pinMode(_REF_3V3, INPUT);
|
||||
return true;
|
||||
}
|
||||
|
||||
int averageAnalogRead(int pinToRead)
|
||||
{
|
||||
byte numberOfReadings = 8;
|
||||
unsigned int runningValue = 0;
|
||||
|
||||
for (int x = 0 ; x < numberOfReadings ; x++)
|
||||
runningValue += analogRead(pinToRead);
|
||||
runningValue /= numberOfReadings;
|
||||
|
||||
return (runningValue);
|
||||
}
|
||||
|
||||
|
||||
double ML8511::getoutputVoltage(void) {
|
||||
int uvLevel = averageAnalogRead(_UVOUT);
|
||||
int refLevel = averageAnalogRead(_REF_3V3);
|
||||
double outputVoltage = 0;
|
||||
|
||||
outputVoltage = 3.3 / refLevel * uvLevel;
|
||||
|
||||
return outputVoltage;
|
||||
}
|
||||
|
||||
|
||||
double ML8511::getuvIntensity(void) {
|
||||
|
||||
|
||||
|
||||
int uvLevel = averageAnalogRead(_UVOUT);
|
||||
int refLevel = averageAnalogRead(_REF_3V3);
|
||||
double uvIntensity = 0;
|
||||
|
||||
double outputVoltage = 0;
|
||||
|
||||
|
||||
outputVoltage = (3.3 / refLevel * uvLevel);
|
||||
|
||||
|
||||
uvIntensity = mapfloat(outputVoltage, 0.99, 2.8, 0.0, 15.0);
|
||||
|
||||
return uvIntensity;
|
||||
}
|
||||
|
||||
|
||||
|
||||
double mapfloat(float x, float in_min, float in_max, float out_min, float out_max) {
|
||||
|
||||
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
|
||||
/*
|
||||
ML8511.h- Library for ML8511 UV sensor
|
||||
Copyright (c) 2017 Emanuele Signoretta. All right reserved.
|
||||
|
||||
Based on the orininal project of Nathan Seidle: https://learn.sparkfun.com/tutorials/ml8511-uv-sensor-hookup-guide
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
|
||||
VERSION 1.0.0 - INITIAL VERSION
|
||||
|
||||
*/
|
||||
|
||||
#ifndef ML8511__H
|
||||
#define ML8511__H
|
||||
|
||||
#if ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
|
||||
class ML8511 {
|
||||
public:
|
||||
ML8511(uint8_t UVOUT, uint8_t REF_3V3 );
|
||||
bool begin(void);
|
||||
double getuvIntensity(void);
|
||||
double getoutputVoltage(void);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
int uvLevel;
|
||||
int refLevel;
|
||||
uint8_t _UVOUT;
|
||||
uint8_t _REF_3V3;
|
||||
byte numberOfReadings = 8;
|
||||
unsigned int runningValue = 0;
|
||||
|
||||
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
|
||||
{
|
||||
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user