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

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

new putzaleit dir

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*
2 * HotHotHeat
3 *
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
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 *
15 * Contact: Norbert Wigbels
16 * (http://foobla.wigbels.de/uber-foobla/)
17 *
18 * Format: <# of Sensor> <data>
19 * Example: 1  23.4    --    Temperature
20 *          2  HIGH    --    Reed count
21 *          3  14      --    Total of Reed counts since start of programm
22 */
23 
24#include <butterfly_temp.h>
25#include <pins_butterfly.h>
26
27#include <LCD_Driver.h>
28#include <timer2_RTC.h>
29
30
31int inputReed = PBPIN4;
32int outputLED = PBPIN7;
33
34int value = 0;
35int debounce = 0;
36int slewRate = LOW;
37int everySecond = 0;
38
39unsigned long gasReeds = 0;
40int  temp = 0;
41
42
43void setup() {
44  // Identify butterfly running program...
45  LCD.prints_f( PSTR( "HOTHOTHEAT" ) );
46  delay( 1400 );
47
48  TempSense.overSample = true;
49  pinMode( inputReed, INPUT );
50  pinMode( outputLED, OUTPUT );
51 
52  digitalWrite( outputLED, HIGH );
53  temp = TempSense.getTemp( CELSIUS );
54 
55  Serial.begin( 9600 );
56}
57
58
59void logOutput()
60{
61  LCD.print( gasReeds );
62  LCD.print( " G " );
63  LCD.print( temp );
64  LCD.println( " C" );
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 );
84}
85
86
87int getSamples() {
88  // Sensor 1 - Temperature
89  temp = TempSense.getTemp( CELSIUS );
90 
91  // switchtime of reed is 18 ms including debouncing...
92  value = digitalRead( inputReed );
93  delay( 20 );
94  debounce = digitalRead( inputReed );
95
96  // Sensor 2 - Reedcontact
97  // ...we are just interested in falling levels
98  // __|----|count_here__|----|_count_here__
99  if ( value==debounce ) {   
100    if ( value==HIGH ) {
101      slewRate=HIGH;
102      return HIGH;
103    }
104    else {
105      if( slewRate==HIGH ) {
106        slewRate=LOW;
107        gasReeds++;
108      }
109      return LOW;
110    }
111  }
112}
113
114
115void loop() { 
116  // LED marks Butterfly working; dark to mark a reed contact
117  if( getSamples()==HIGH ) {
118    digitalWrite( outputLED, LOW );
119  } else {
120    digitalWrite( outputLED, HIGH );
121  }
122   
123  if ( everySecond > 20 ) {
124    everySecond = 0;
125    logOutput();
126  } else {
127    everySecond++;
128  }
129   
130  delay( 30 );
131}
Note: See TracBrowser for help on using the repository browser.