131 lines
2.6 KiB
Text
131 lines
2.6 KiB
Text
/*
|
|
* HotHotHeat
|
|
*
|
|
* Compile with the Arduino IDE (http://arduino.cc); is deployed against a
|
|
* Atmel Butterfly - so you also need the Butteruino project
|
|
* (http://code.google.com/p/butteruino/)
|
|
*
|
|
* ...will
|
|
* 1) Read the Butterfly temperature sensor and output
|
|
* the result permanently to UART.
|
|
*
|
|
* 2) Read a reed sensor and output
|
|
* the result permanently to UART
|
|
*
|
|
* Contact: Norbert Wigbels
|
|
* (http://foobla.wigbels.de/uber-foobla/)
|
|
*
|
|
* Format: <# of Sensor> <data>
|
|
* Example: 1 23.4 -- Temperature
|
|
* 2 HIGH -- Reed count
|
|
* 3 14 -- Total of Reed counts since start of programm
|
|
*/
|
|
|
|
#include <butterfly_temp.h>
|
|
#include <pins_butterfly.h>
|
|
|
|
#include <LCD_Driver.h>
|
|
#include <timer2_RTC.h>
|
|
|
|
|
|
int inputReed = PBPIN4;
|
|
int outputLED = PBPIN7;
|
|
|
|
int value = 0;
|
|
int debounce = 0;
|
|
int slewRate = LOW;
|
|
int everySecond = 0;
|
|
|
|
unsigned long gasReeds = 0;
|
|
int temp = 0;
|
|
|
|
|
|
void setup() {
|
|
// Identify butterfly running program...
|
|
LCD.prints_f( PSTR( "HOTHOTHEAT" ) );
|
|
delay( 1400 );
|
|
|
|
TempSense.overSample = true;
|
|
pinMode( inputReed, INPUT );
|
|
pinMode( outputLED, OUTPUT );
|
|
|
|
digitalWrite( outputLED, HIGH );
|
|
temp = TempSense.getTemp( CELSIUS );
|
|
|
|
Serial.begin( 9600 );
|
|
}
|
|
|
|
|
|
void logOutput()
|
|
{
|
|
LCD.print( gasReeds );
|
|
LCD.print( " G " );
|
|
LCD.print( temp );
|
|
LCD.println( " C" );
|
|
|
|
// Temperature
|
|
Serial.print( "1" );
|
|
Serial.print( "\t" );
|
|
Serial.println( temp );
|
|
|
|
// Reed HIGH or Low
|
|
Serial.print( "2" );
|
|
Serial.print( "\t" );
|
|
if( slewRate==1 ) {
|
|
Serial.println( "HIGH" );
|
|
} else {
|
|
Serial.println( "LOW" );
|
|
}
|
|
|
|
// Total of Gas Reeds
|
|
Serial.print( "3" );
|
|
Serial.print( "\t" );
|
|
Serial.println( gasReeds );
|
|
}
|
|
|
|
|
|
int getSamples() {
|
|
// Sensor 1 - Temperature
|
|
temp = TempSense.getTemp( CELSIUS );
|
|
|
|
// switchtime of reed is 18 ms including debouncing...
|
|
value = digitalRead( inputReed );
|
|
delay( 20 );
|
|
debounce = digitalRead( inputReed );
|
|
|
|
// Sensor 2 - Reedcontact
|
|
// ...we are just interested in falling levels
|
|
// __|----|count_here__|----|_count_here__
|
|
if ( value==debounce ) {
|
|
if ( value==HIGH ) {
|
|
slewRate=HIGH;
|
|
return HIGH;
|
|
}
|
|
else {
|
|
if( slewRate==HIGH ) {
|
|
slewRate=LOW;
|
|
gasReeds++;
|
|
}
|
|
return LOW;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void loop() {
|
|
// LED marks Butterfly working; dark to mark a reed contact
|
|
if( getSamples()==HIGH ) {
|
|
digitalWrite( outputLED, LOW );
|
|
} else {
|
|
digitalWrite( outputLED, HIGH );
|
|
}
|
|
|
|
if ( everySecond > 20 ) {
|
|
everySecond = 0;
|
|
logOutput();
|
|
} else {
|
|
everySecond++;
|
|
}
|
|
|
|
delay( 30 );
|
|
}
|