Skip to content

Commit

Permalink
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
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 0 deletions.
67 changes: 67 additions & 0 deletions LM35DZ/LM35DZ.cpp
@@ -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;
}
42 changes: 42 additions & 0 deletions LM35DZ/LM35DZ.h
@@ -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

21 changes: 21 additions & 0 deletions LM35DZ/keywords.txt
@@ -0,0 +1,21 @@
#######################################
# Syntax Coloring Map For EEEPROM
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

LM35DZ KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

read KEYWORD2
sample KEYWORD2

#######################################
# Constants (LITERAL1)
#######################################

0 comments on commit 2c5a9b1

Please sign in to comment.