source: de.wigbels.avr/sketchbook/hothotheat/hothotheat.pde @ 86f2c9a

Last change on this file since 86f2c9a was 86f2c9a, checked in by njw <njw@…>, 15 years ago

hothotheat identifies real gas reeds (reads) now

  • outout to UART about every second
  • displays tGR and temperature
  • Property mode set to 100644
File size: 2.3 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>
[86f2c9a]19 * Example: 1  23.4
20 *          2  HIGH
21 *          3  14
[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;
[86f2c9a]36int slewRate = 0;
37int everySecond = 0;
38
39unsigned long gasReeds = 0;
40int  temp = 0;
[454b95c]41
42
43void setup() {
[86f2c9a]44  LCD.prints_f( PSTR( "HOTHOTHEAT" ) );
45  delay( 2500 );
[71bba07]46 
47  // Set up the RTC timer to call the secTick() function every second.
48  RTCTimer.init( secTick );
49 
[86f2c9a]50  Serial.begin( 9600 );
[71bba07]51
52  TempSense.overSample = true;
53
[86f2c9a]54  pinMode( inputReed, INPUT );
55  pinMode( outputLED, OUTPUT );
56 
57  digitalWrite( outputLED, HIGH );
[454b95c]58}
59
[86f2c9a]60
[71bba07]61void secTick()
62{
63  LCD.print( gasReeds );
[86f2c9a]64  LCD.print( " G " );
65  LCD.print( temp );
66  LCD.println( " C" );
67  everySecond=1;
[71bba07]68}
69
[86f2c9a]70
[71bba07]71int getSamples() {
[454b95c]72
[86f2c9a]73  temp = TempSense.getTemp( CELSIUS );
74 
[4aaeb66]75  // switchtime of reed is 18 ms including debouncing...
[86f2c9a]76  value = digitalRead( inputReed );
77  delay( 20 );
78  debounce = digitalRead( inputReed );
[71bba07]79
80  // Reedcontact = Sensor 2
[86f2c9a]81  if ( value==debounce ) {   
82    if ( value == HIGH ) {
83      slewRate=1;
[4aaeb66]84      return 1;
85    }
86    else {
[86f2c9a]87      if( slewRate==1 ) {
88        slewRate=0;
89        gasReeds++;
90      }
[4aaeb66]91      return 0;
92    }
[454b95c]93  }
94}
95
[86f2c9a]96
[454b95c]97void loop() { 
[86f2c9a]98  // LED marks Butterfly working; dark to mark a reed contact
99  if( getSamples()==1 ) {
100    digitalWrite( outputLED, LOW );
[4aaeb66]101  } else {
[86f2c9a]102    digitalWrite( outputLED, HIGH );
[4aaeb66]103  }
104
[86f2c9a]105  if ( everySecond==1 ) {
106    everySecond = 0;
107
108    // Temperature
109    Serial.print( "1" );
110    Serial.print( "\t" );
111    Serial.println( temp );
112
113    // Reed HIGH or Low 
114    Serial.print( "2" );
115    Serial.print( "\t" );
116    if( slewRate==1 ) {
117        Serial.println( "HIGH" );
118    } else {
119        Serial.println( "LOW" );
120    }
121 
122    // Total of Gas Reeds
123    Serial.print( "3" );
124    Serial.print( "\t" );
125    Serial.println( gasReeds );
126  }
127   
128  delay(50);
[454b95c]129}
Note: See TracBrowser for help on using the repository browser.