Commits

Anonymous committed c09c294

- formatting

Comments (0)

Files changed (2)

power_display/power_display.pde

 #define LINEFEED 0x0A
 #define RETURN 0x0D
 
+// max power reading considered to be valid
+#define MAX_VALID_POWER 30
+
+
 //--------------------------------------------------------------------------------
 void setup()  
 {
       float v = atof(buf);
       
       // if the power reading is sensible, add it to the total
-      if (v < 30) {
+      if (v < MAX_VALID_POWER) {
         powerSum += v;
         ct++;
       }

power_sensor/power_sensor.pde

 // counts total pulses seen - used to get total power used since the last reset
 uint32_t culmulativePulses = 0;
 
+#define pinLED 13
+#define SECONDS_PER_HR 3600
 
 
 /*-----------------------------------------------------------------*/
   Serial.print(255);
    
   // use the built-in LED on pin 13 to show when data is reported
-  pinMode(13, OUTPUT);
+  pinMode(pinLED, OUTPUT);
    
   // attach the ISR to interrupt 0, pin 2 - tis is where the phototransistor is connected
   attachInterrupt(0, countLEDPulses, RISING);
     // turn off interrupts so that the calculations are atomic
     cli();
     
-    // 
+    // average pulse interval in seconds
     float avgPulseInterval = pulseIntervalSum  / (float(pulseCt) * 1000000);
     culmulativePulses += pulseCt;
     
     sei();
  
     // calculate the current power and accumulated use
-    float kiloWatts = 3600 / (avgPulseInterval * PULSES_PER_KWH);
+    float kiloWatts = SECONDS_PER_HR / (avgPulseInterval * PULSES_PER_KWH);
     float kWh = culmulativePulses / float(PULSES_PER_KWH);
    
     // send data out over the xbee
     Serial.println(kWh);
     
     // flash the LED
-    digitalWrite(13, HIGH);
+    digitalWrite(pinLED, HIGH);
     delay(50);
-    digitalWrite(13, LOW);
+    digitalWrite(pinLED, LOW);
     
   }