sample sensor reconnect
[svn42.git] / rf433ctl / rf433ctl.pde
index e6ba1bd..f404110 100644 (file)
@@ -22,6 +22,7 @@
 OneWire  onewire(ONE_WIRE_PIN);
 DallasTemperature dallas_sensors(&onewire);
 DeviceAddress onShieldTemp = { 0x10, 0xE7, 0x77, 0xD3, 0x01, 0x08, 0x00, 0x3F };
+#define TEMPC_OFFSET
 
 typedef struct {
   byte offset;
@@ -204,7 +205,7 @@ void printTemperature(DeviceAddress deviceAddress)
   dallas_sensors.requestTemperatures();
   float tempC = dallas_sensors.getTempC(deviceAddress);
   Serial.print("Temp C: ");
-  Serial.println(tempC);
+  Serial.println(tempC TEMPC_OFFSET);
   //Serial.print(" Temp F: ");
   //Serial.println(DallasTemperature::toFahrenheit(tempC)); // Converts tempC to Fahrenheit
 }
@@ -240,12 +241,32 @@ void printLightLevel()
 
 //********************************************************************//
 
+unsigned long wm_start_=0;
+bool wait_millis(unsigned long ms)
+{
+  if (wm_start_ > 0)
+  {
+    if (millis() < wm_start_ || millis() > wm_start_+ ms)
+    {
+      wm_start_=0;
+      return false;
+    }
+    else
+      return true;
+  }
+  else
+  {
+    wm_start_=millis();
+    return true;
+  }
+}
+
 unsigned int flash_led_time_=0;
 void calculate_led_level(unsigned int pwm_pin)
 {
   if (flash_led_time_ == 0)
     return;
-  if (millis() % 10)
+  if (wait_millis(10))
     return;
   flash_led_time_--;
   int c = abs(sin(float(flash_led_time_) / 100.0)) * 256;
@@ -254,7 +275,7 @@ void calculate_led_level(unsigned int pwm_pin)
 
 void flash_led(int times)
 {
-  flash_led_time_=314*times;
+  flash_led_time_ += 314*times;
 }
 
 //********************************************************************//
@@ -313,7 +334,7 @@ void loop()
     {   
       pb_postth_state=1;
       Serial.println("PanicButton");
-      flash_led(7);
+      flash_led(4);
     }
     else if (!pb_state)
       pb_postth_state=0;