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 |
---|
20 | * 2 HIGH |
---|
21 | * 3 14 |
---|
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 | |
---|
31 | int inputReed = PBPIN4; |
---|
32 | int outputLED = PBPIN7; |
---|
33 | |
---|
34 | int value = 0; |
---|
35 | int debounce = 0; |
---|
36 | int slewRate = 0; |
---|
37 | int everySecond = 0; |
---|
38 | |
---|
39 | unsigned long gasReeds = 0; |
---|
40 | int temp = 0; |
---|
41 | |
---|
42 | |
---|
43 | void setup() { |
---|
44 | LCD.prints_f( PSTR( "HOTHOTHEAT" ) ); |
---|
45 | delay( 2500 ); |
---|
46 | |
---|
47 | // Set up the RTC timer to call the secTick() function every second. |
---|
48 | RTCTimer.init( secTick ); |
---|
49 | |
---|
50 | Serial.begin( 9600 ); |
---|
51 | |
---|
52 | TempSense.overSample = true; |
---|
53 | |
---|
54 | pinMode( inputReed, INPUT ); |
---|
55 | pinMode( outputLED, OUTPUT ); |
---|
56 | |
---|
57 | digitalWrite( outputLED, HIGH ); |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | void secTick() |
---|
62 | { |
---|
63 | LCD.print( gasReeds ); |
---|
64 | LCD.print( " G " ); |
---|
65 | LCD.print( temp ); |
---|
66 | LCD.println( " C" ); |
---|
67 | everySecond=1; |
---|
68 | } |
---|
69 | |
---|
70 | |
---|
71 | int getSamples() { |
---|
72 | |
---|
73 | temp = TempSense.getTemp( CELSIUS ); |
---|
74 | |
---|
75 | // switchtime of reed is 18 ms including debouncing... |
---|
76 | value = digitalRead( inputReed ); |
---|
77 | delay( 20 ); |
---|
78 | debounce = digitalRead( inputReed ); |
---|
79 | |
---|
80 | // Reedcontact = Sensor 2 |
---|
81 | if ( value==debounce ) { |
---|
82 | if ( value == HIGH ) { |
---|
83 | slewRate=1; |
---|
84 | return 1; |
---|
85 | } |
---|
86 | else { |
---|
87 | if( slewRate==1 ) { |
---|
88 | slewRate=0; |
---|
89 | gasReeds++; |
---|
90 | } |
---|
91 | return 0; |
---|
92 | } |
---|
93 | } |
---|
94 | } |
---|
95 | |
---|
96 | |
---|
97 | void loop() { |
---|
98 | // LED marks Butterfly working; dark to mark a reed contact |
---|
99 | if( getSamples()==1 ) { |
---|
100 | digitalWrite( outputLED, LOW ); |
---|
101 | } else { |
---|
102 | digitalWrite( outputLED, HIGH ); |
---|
103 | } |
---|
104 | |
---|
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); |
---|
129 | } |
---|