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

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

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

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