root/de.wigbels.avr/sketchbook/hothotheat/hothotheat.pde @ 28

Revision 28, 2.7 kB (checked in by njw, 16 months ago)

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

RevLine 
[20]1/*
2 * HotHotHeat
3 *
[21]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
[20]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 *
[21]15 * Contact: Norbert Wigbels
16 * (http://foobla.wigbels.de/uber-foobla/)
[20]17 *
18 * Format: <# of Sensor> <data>
[28]19 * Example: 1  23.4    --    Temperature
20 *          2  HIGH    --    Reed count
21 *          3  14      --    Total of Reed counts since start of programm
[20]22 */
23 
24#include <butterfly_temp.h>
25#include <pins_butterfly.h>
26
[23]27#include <LCD_Driver.h>
28#include <timer2_RTC.h>
29
30
[22]31int inputReed = PBPIN4;
[27]32int outputLED = PBPIN7;
[22]33
[20]34int value = 0;
[22]35int debounce = 0;
[28]36int slewRate = LOW;
37int everySecond = false;
[20]38
[27]39unsigned long gasReeds = 0;
40int  temp = 0;
[20]41
[27]42
[20]43void setup() {
[28]44  // Identify butterfly running program...
[27]45  LCD.prints_f( PSTR( "HOTHOTHEAT" ) );
46  delay( 2500 );
[23]47 
48  // Set up the RTC timer to call the secTick() function every second.
49  RTCTimer.init( secTick );
50 
[27]51  Serial.begin( 9600 );
[23]52
53  TempSense.overSample = true;
54
[27]55  pinMode( inputReed, INPUT );
56  pinMode( outputLED, OUTPUT );
57 
58  digitalWrite( outputLED, HIGH );
[28]59  temp = TempSense.getTemp( CELSIUS );
[20]60}
61
[27]62
[23]63void secTick()
64{
65  LCD.print( gasReeds );
[27]66  LCD.print( " G " );
67  LCD.print( temp );
68  LCD.println( " C" );
[28]69  everySecond=true;
[23]70}
71
[27]72
[23]73int getSamples() {
[28]74  // Sensor 1 - Temperature
[27]75  temp = TempSense.getTemp( CELSIUS );
76 
[22]77  // switchtime of reed is 18 ms including debouncing...
[27]78  value = digitalRead( inputReed );
79  delay( 20 );
80  debounce = digitalRead( inputReed );
[23]81
[28]82  // Sensor 2 - Reedcontact
83  // ...we are just interested in falling levels
84  // __|----|count_here__|----|_count_here__
[27]85  if ( value==debounce ) {   
[28]86    if ( value==HIGH ) {
87      slewRate=HIGH;
88      return HIGH;
[22]89    }
90    else {
[28]91      if( slewRate==HIGH ) {
92        slewRate=LOW;
[27]93        gasReeds++;
94      }
[28]95      return LOW;
[22]96    }
[20]97  }
98}
99
[27]100
[20]101void loop() { 
[27]102  // LED marks Butterfly working; dark to mark a reed contact
[28]103  if( getSamples()==HIGH ) {
[27]104    digitalWrite( outputLED, LOW );
[22]105  } else {
[27]106    digitalWrite( outputLED, HIGH );
[22]107  }
108
[28]109  // Output of
110  if ( everySecond==true ) {
111    everySecond = false;
[27]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   
[28]133  delay(30);
[20]134}
Note: See TracBrowser for help on using the browser.