source: de.wigbels.avr/sketchbook/hothotheat/hothotheat.pde@ c54b74b

Last change on this file since c54b74b was 5fb6ac6, checked in by njw <njw@…>, 14 years ago

new putzaleit dir

  • Property mode set to 100644
File size: 2.6 KB
RevLine 
[454b95c]1/*
2 * HotHotHeat
3 *
[78394ea]4 * Compile with the Arduino IDE (http://arduino.cc); is deployed against a
5 * Atmel Butterfly - so you also need the Butteruino project
6 * (http://code.google.com/p/butteruino/)
7 *
8 * ...will
[454b95c]9 * 1) Read the Butterfly temperature sensor and output
10 * the result permanently to UART.
11 *
12 * 2) Read a reed sensor and output
13 * the result permanently to UART
14 *
[78394ea]15 * Contact: Norbert Wigbels
16 * (http://foobla.wigbels.de/uber-foobla/)
[454b95c]17 *
18 * Format: <# of Sensor> <data>
[789d162]19 * Example: 1 23.4 -- Temperature
20 * 2 HIGH -- Reed count
21 * 3 14 -- Total of Reed counts since start of programm
[454b95c]22 */
23
24#include <butterfly_temp.h>
25#include <pins_butterfly.h>
26
[71bba07]27#include <LCD_Driver.h>
28#include <timer2_RTC.h>
29
30
[4aaeb66]31int inputReed = PBPIN4;
[86f2c9a]32int outputLED = PBPIN7;
[4aaeb66]33
[454b95c]34int value = 0;
[4aaeb66]35int debounce = 0;
[789d162]36int slewRate = LOW;
[5fb6ac6]37int everySecond = 0;
[86f2c9a]38
39unsigned long gasReeds = 0;
40int temp = 0;
[454b95c]41
42
43void setup() {
[789d162]44 // Identify butterfly running program...
[86f2c9a]45 LCD.prints_f( PSTR( "HOTHOTHEAT" ) );
[5fb6ac6]46 delay( 1400 );
[71bba07]47
48 TempSense.overSample = true;
[86f2c9a]49 pinMode( inputReed, INPUT );
50 pinMode( outputLED, OUTPUT );
51
52 digitalWrite( outputLED, HIGH );
[789d162]53 temp = TempSense.getTemp( CELSIUS );
[5fb6ac6]54
55 Serial.begin( 9600 );
[454b95c]56}
57
[86f2c9a]58
[5fb6ac6]59void logOutput()
[71bba07]60{
61 LCD.print( gasReeds );
[86f2c9a]62 LCD.print( " G " );
63 LCD.print( temp );
64 LCD.println( " C" );
[5fb6ac6]65
66 // Temperature
67 Serial.print( "1" );
68 Serial.print( "\t" );
69 Serial.println( temp );
70
71 // Reed HIGH or Low
72 Serial.print( "2" );
73 Serial.print( "\t" );
74 if( slewRate==1 ) {
75 Serial.println( "HIGH" );
76 } else {
77 Serial.println( "LOW" );
78 }
79
80 // Total of Gas Reeds
81 Serial.print( "3" );
82 Serial.print( "\t" );
83 Serial.println( gasReeds );
[71bba07]84}
85
[86f2c9a]86
[71bba07]87int getSamples() {
[789d162]88 // Sensor 1 - Temperature
[86f2c9a]89 temp = TempSense.getTemp( CELSIUS );
90
[4aaeb66]91 // switchtime of reed is 18 ms including debouncing...
[86f2c9a]92 value = digitalRead( inputReed );
93 delay( 20 );
94 debounce = digitalRead( inputReed );
[71bba07]95
[789d162]96 // Sensor 2 - Reedcontact
97 // ...we are just interested in falling levels
98 // __|----|count_here__|----|_count_here__
[86f2c9a]99 if ( value==debounce ) {
[789d162]100 if ( value==HIGH ) {
101 slewRate=HIGH;
102 return HIGH;
[4aaeb66]103 }
104 else {
[789d162]105 if( slewRate==HIGH ) {
106 slewRate=LOW;
[86f2c9a]107 gasReeds++;
108 }
[789d162]109 return LOW;
[4aaeb66]110 }
[454b95c]111 }
112}
113
[86f2c9a]114
[454b95c]115void loop() {
[86f2c9a]116 // LED marks Butterfly working; dark to mark a reed contact
[789d162]117 if( getSamples()==HIGH ) {
[86f2c9a]118 digitalWrite( outputLED, LOW );
[4aaeb66]119 } else {
[86f2c9a]120 digitalWrite( outputLED, HIGH );
[4aaeb66]121 }
[86f2c9a]122
[5fb6ac6]123 if ( everySecond > 20 ) {
124 everySecond = 0;
125 logOutput();
126 } else {
127 everySecond++;
128 }
129
130 delay( 30 );
[454b95c]131}
Note: See TracBrowser for help on using the repository browser.