/* * HotHotHeat * * Compile with the Arduino IDE (http://arduino.cc); is deployed against a * Atmel Butterfly - so you also need the Butteruino project * (http://code.google.com/p/butteruino/) * * ...will * 1) Read the Butterfly temperature sensor and output * the result permanently to UART. * * 2) Read a reed sensor and output * the result permanently to UART * * Contact: Norbert Wigbels * (http://foobla.wigbels.de/uber-foobla/) * * Format: <# of Sensor> * Example: 1 23.4 * 2 HIGH * 3 14 */ #include #include #include #include int inputReed = PBPIN4; int outputLED = PBPIN7; int value = 0; int debounce = 0; int slewRate = 0; int everySecond = 0; unsigned long gasReeds = 0; int temp = 0; void setup() { LCD.prints_f( PSTR( "HOTHOTHEAT" ) ); delay( 2500 ); // Set up the RTC timer to call the secTick() function every second. RTCTimer.init( secTick ); Serial.begin( 9600 ); TempSense.overSample = true; pinMode( inputReed, INPUT ); pinMode( outputLED, OUTPUT ); digitalWrite( outputLED, HIGH ); } void secTick() { LCD.print( gasReeds ); LCD.print( " G " ); LCD.print( temp ); LCD.println( " C" ); everySecond=1; } int getSamples() { temp = TempSense.getTemp( CELSIUS ); // switchtime of reed is 18 ms including debouncing... value = digitalRead( inputReed ); delay( 20 ); debounce = digitalRead( inputReed ); // Reedcontact = Sensor 2 if ( value==debounce ) { if ( value == HIGH ) { slewRate=1; return 1; } else { if( slewRate==1 ) { slewRate=0; gasReeds++; } return 0; } } } void loop() { // LED marks Butterfly working; dark to mark a reed contact if( getSamples()==1 ) { digitalWrite( outputLED, LOW ); } else { digitalWrite( outputLED, HIGH ); } if ( everySecond==1 ) { everySecond = 0; // Temperature Serial.print( "1" ); Serial.print( "\t" ); Serial.println( temp ); // Reed HIGH or Low Serial.print( "2" ); Serial.print( "\t" ); if( slewRate==1 ) { Serial.println( "HIGH" ); } else { Serial.println( "LOW" ); } // Total of Gas Reeds Serial.print( "3" ); Serial.print( "\t" ); Serial.println( gasReeds ); } delay(50); }