[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> |
---|
| 19 | * Example: 1; Temperature in Celsius |
---|
| 20 | * tbd. |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | #include <butterfly_temp.h> |
---|
| 24 | #include <pins_butterfly.h> |
---|
| 25 | |
---|
[71bba07] | 26 | #include <LCD_Driver.h> |
---|
| 27 | #include <timer2_RTC.h> |
---|
| 28 | |
---|
| 29 | |
---|
[4aaeb66] | 30 | int inputReed = PBPIN4; |
---|
[71bba07] | 31 | int outputLED = PBPIN3; |
---|
[4aaeb66] | 32 | |
---|
[454b95c] | 33 | int value = 0; |
---|
[4aaeb66] | 34 | int debounce = 0; |
---|
[454b95c] | 35 | |
---|
[71bba07] | 36 | long gasReeds = 0; |
---|
[454b95c] | 37 | |
---|
| 38 | void setup() { |
---|
[71bba07] | 39 | LCD.prints_f(PSTR("HOTHOTHEAT")); |
---|
| 40 | delay(2500); |
---|
| 41 | |
---|
| 42 | // Set up the RTC timer to call the secTick() function every second. |
---|
| 43 | RTCTimer.init( secTick ); |
---|
| 44 | |
---|
[454b95c] | 45 | Serial.begin(9600); |
---|
[71bba07] | 46 | |
---|
| 47 | TempSense.overSample = true; |
---|
| 48 | |
---|
[4aaeb66] | 49 | pinMode(inputReed, INPUT); |
---|
| 50 | pinMode(outputLED, OUTPUT); |
---|
[454b95c] | 51 | } |
---|
| 52 | |
---|
[71bba07] | 53 | void secTick() |
---|
| 54 | { |
---|
| 55 | LCD.print( gasReeds ); |
---|
| 56 | LCD.println( " tGR" ); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | int getSamples() { |
---|
| 60 | // Temperature = Sensor 1 |
---|
[454b95c] | 61 | Serial.print("1"); |
---|
| 62 | Serial.print("\t"); |
---|
[71bba07] | 63 | Serial.println(TempSense.getTemp(CELSIUS)); |
---|
[454b95c] | 64 | |
---|
[4aaeb66] | 65 | // switchtime of reed is 18 ms including debouncing... |
---|
| 66 | value = digitalRead(inputReed); |
---|
| 67 | delay(20); |
---|
| 68 | debounce = digitalRead(inputReed); |
---|
[71bba07] | 69 | |
---|
| 70 | // Reedcontact = Sensor 2 |
---|
[4aaeb66] | 71 | if (value==debounce) { |
---|
[71bba07] | 72 | Serial.print("2"); |
---|
| 73 | Serial.print("\t"); |
---|
[4aaeb66] | 74 | if (value == HIGH) { |
---|
| 75 | Serial.println("HIGH"); |
---|
[71bba07] | 76 | gasReeds++; |
---|
[4aaeb66] | 77 | return 1; |
---|
| 78 | } |
---|
| 79 | else { |
---|
| 80 | Serial.println("LOW"); |
---|
| 81 | return 0; |
---|
| 82 | } |
---|
[454b95c] | 83 | } |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | void loop() { |
---|
[71bba07] | 87 | // Switch LED on for a certain time to mark a switched Reed contact |
---|
[4aaeb66] | 88 | if(getSamples()==1) { |
---|
| 89 | digitalWrite(outputLED, HIGH); |
---|
| 90 | } else { |
---|
| 91 | digitalWrite(outputLED, LOW); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | delay(100); |
---|
[454b95c] | 95 | } |
---|