Show
Ignore:
Timestamp:
05/20/09 18:50:07 (3 years ago)
Author:
njw
Message:

hothotheat identifies real gas reeds (reads) now

- outout to UART about every second
- displays tGR and temperature

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • de.wigbels.avr/sketchbook/hothotheat/hothotheat.pde

    r23 r27  
    1717 * 
    1818 * Format: <# of Sensor> <data> 
    19  * Example: 1; Temperature in Celsius 
    20  * tbd. 
     19 * Example: 1  23.4 
     20 *          2  HIGH 
     21 *          3  14 
    2122 */ 
    2223  
     
    2930 
    3031int inputReed = PBPIN4; 
    31 int outputLED = PBPIN3; 
     32int outputLED = PBPIN7; 
    3233 
    3334int value = 0; 
    3435int debounce = 0; 
     36int slewRate = 0; 
     37int everySecond = 0; 
    3538 
    36 long gasReeds = 0; 
     39unsigned long gasReeds = 0; 
     40int  temp = 0; 
     41 
    3742 
    3843void setup() { 
    39   LCD.prints_f(PSTR("HOTHOTHEAT")); 
    40   delay(2500); 
     44  LCD.prints_f( PSTR( "HOTHOTHEAT" ) ); 
     45  delay( 2500 ); 
    4146  
    4247  // Set up the RTC timer to call the secTick() function every second. 
    4348  RTCTimer.init( secTick ); 
    4449   
    45   Serial.begin(9600);  
     50  Serial.begin( 9600 );  
    4651 
    4752  TempSense.overSample = true; 
    4853 
    49   pinMode(inputReed, INPUT); 
    50   pinMode(outputLED, OUTPUT); 
     54  pinMode( inputReed, INPUT ); 
     55  pinMode( outputLED, OUTPUT ); 
     56   
     57  digitalWrite( outputLED, HIGH ); 
    5158} 
     59 
    5260 
    5361void secTick() 
    5462{ 
    5563  LCD.print( gasReeds ); 
    56   LCD.println( " tGR" ); 
     64  LCD.print( " G " ); 
     65  LCD.print( temp ); 
     66  LCD.println( " C" ); 
     67  everySecond=1; 
    5768} 
    5869 
     70 
    5971int getSamples() { 
    60   // Temperature = Sensor 1 
    61   Serial.print("1"); 
    62   Serial.print("\t"); 
    63   Serial.println(TempSense.getTemp(CELSIUS)); 
    6472 
     73  temp = TempSense.getTemp( CELSIUS ); 
     74   
    6575  // switchtime of reed is 18 ms including debouncing... 
    66   value = digitalRead(inputReed); 
    67   delay(20); 
    68   debounce = digitalRead(inputReed); 
     76  value = digitalRead( inputReed ); 
     77  delay( 20 ); 
     78  debounce = digitalRead( inputReed ); 
    6979 
    7080  // Reedcontact = Sensor 2 
    71   if (value==debounce) { 
    72     Serial.print("2"); 
    73     Serial.print("\t"); 
    74     if (value == HIGH) { 
    75       Serial.println("HIGH"); 
    76       gasReeds++; 
     81  if ( value==debounce ) {     
     82    if ( value == HIGH ) { 
     83      slewRate=1; 
    7784      return 1; 
    7885    } 
    7986    else { 
    80       Serial.println("LOW"); 
     87      if( slewRate==1 ) { 
     88        slewRate=0; 
     89        gasReeds++; 
     90      } 
    8191      return 0; 
    8292    } 
     
    8494} 
    8595 
     96 
    8697void loop() {   
    87   // Switch LED on for a certain time to mark a switched Reed contact 
    88   if(getSamples()==1) { 
    89     digitalWrite(outputLED, HIGH); 
     98  // LED marks Butterfly working; dark to mark a reed contact 
     99  if( getSamples()==1 ) { 
     100    digitalWrite( outputLED, LOW ); 
    90101  } else { 
    91     digitalWrite(outputLED, LOW); 
     102    digitalWrite( outputLED, HIGH ); 
    92103  } 
    93104 
    94   delay(100); 
     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); 
    95129}