source: de.wigbels.avr/sketchbook/hothotheat/hothotheat.pde @ 789d162

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

no chance to use the Interrupt-API with the Butterfly?!

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