#include "lights.h"
static uint16_t ambient_val;
-unsigned char ambient_zone;
-unsigned char ambient_zone_set;
+volatile unsigned char ambient_zone;
+static unsigned char ambient_zone_set;
static uint16_t ambient_zones[] = {
- 1, 2, 10, 20, 256
+ 0x10, 0x18, 0x20, 0x40, 0x100, 0x400, 0x1000, 0x4000, 0xffff
};
#define N_AMBIENT_ZONES (sizeof(ambient_zones)/sizeof(ambient_zones[0]))
if (!ambient_zone_set)
ambient_val = adcval << 4;
-
- // running sum
- ambient_val += adcval - (ambient_val >> 4);
+ else // running sum
+ ambient_val += adcval - (ambient_val >> 4);
newzone = 0;
while (newzone < N_AMBIENT_ZONES-1
- && ambient_zones[newzone] <= ambient_val)
+ && ambient_zones[newzone] < ambient_val)
newzone++;
if (!ambient_zone_set || newzone != ambient_zone) {
ambient_zone = newzone;
- ambient_zone_changed();
ambient_zone_set = 1;
+ ambient_zone_changed();
}
}
-
-