Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added LM35DZ library (temperature sensor)
Signed-off-by: Lincoln Stoll <lstoll@lstoll.net> committer: Lincoln Stoll <lstoll@lstoll.net> --HG-- extra : convert_revision : e4e0829c21b2bde5fdf914d197cb9d5720a4dfa4
- Loading branch information
Amadeusz Jasak
committed
Apr 16, 2009
1 parent
a926454
commit 2c5a9b1
Showing
3 changed files
with
130 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,67 @@ | ||
/* | ||
LM35DZ.h - LM35DZ temperature sensor | ||
Copyright (c) 2009 Amadeusz Jasak. All right reserved. | ||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
This library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with this library; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
/****************************************************************************** | ||
* Includes | ||
******************************************************************************/ | ||
|
||
#include "WConstants.h" | ||
#include "LM35DZ.h" | ||
|
||
/****************************************************************************** | ||
* Definitions | ||
******************************************************************************/ | ||
|
||
/****************************************************************************** | ||
* Constructors | ||
******************************************************************************/ | ||
LM35DZ::LM35DZ(uint8_t pin) | ||
{ | ||
this->pin = pin; | ||
this->min = 255; | ||
this->max = -255; | ||
} | ||
|
||
/****************************************************************************** | ||
* User API | ||
******************************************************************************/ | ||
int LM35DZ::read() | ||
{ | ||
int temp = (500.0 * analogRead(this->pin)) / 1024.0; | ||
|
||
if (temp > this->max) | ||
this->max = temp; | ||
if (temp < this->min) | ||
this->min = temp; | ||
|
||
return temp; | ||
} | ||
|
||
int LM35DZ::sample(uint8_t samples = 3, uint8_t dl = 500) | ||
{ | ||
int sum = 0; | ||
|
||
for (uint8_t i = 0; i < samples; i++) | ||
{ | ||
sum += this->read(); | ||
delay(dl); | ||
} | ||
|
||
return sum/samples; | ||
} |
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,42 @@ | ||
/* | ||
LM35DZ.h - LM35DZ temperature sensor | ||
Copyright (c) 2009 Amadeusz Jasak. All right reserved. | ||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
This library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with this library; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#ifndef LM35DZ_h | ||
#define LM35DZ_h | ||
|
||
#include <inttypes.h> | ||
|
||
class LM35DZ | ||
{ | ||
private: | ||
uint8_t pin; | ||
|
||
public: | ||
int min; | ||
int max; | ||
|
||
public: | ||
LM35DZ(uint8_t pin); | ||
|
||
int read(); | ||
int sample(uint8_t, uint8_t); | ||
}; | ||
|
||
#endif | ||
|
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 @@ | ||
####################################### | ||
# Syntax Coloring Map For EEEPROM | ||
####################################### | ||
|
||
####################################### | ||
# Datatypes (KEYWORD1) | ||
####################################### | ||
|
||
LM35DZ KEYWORD1 | ||
|
||
####################################### | ||
# Methods and Functions (KEYWORD2) | ||
####################################### | ||
|
||
read KEYWORD2 | ||
sample KEYWORD2 | ||
|
||
####################################### | ||
# Constants (LITERAL1) | ||
####################################### | ||
|