+#define BATT_N_LEVELS (sizeof(batt_levels) / sizeof(batt_levels[0]))
+
+/* output power and PWM calculation */
+#define PWM_TOP 255
+#define PWM_MAX (PWM_TOP - 8) // to allow for ADC "batt_off" measurements
+#define PWM_MIN 8 // to allow for ADC "batt_on" measurements
+
+/*
+ * The values in power_levels[] array are voltages at which the load
+ * would give the expected power (we don't have sqrt() function,
+ * so we cannot use mW values directly. They can be calculated as
+ * voltage[V] = sqrt(load_resistance[Ohm] * expected_power[W])
+ * or
+ * voltage[mV] = sqrt(load_resistance[mOhm] * expected_power[mW])
+ *
+ * I use 1.25 W as minimum power, each step is sqrt(2)*previous_step,
+ * so the 5th step is 5 W.
+ */
+static unsigned char power_levels[] = {
+ MV_TO_ADC8(1581), // 1250 mW for 2 Ohm load
+ MV_TO_ADC8(1880), // 1768 mW for 2 Ohm load
+ MV_TO_ADC8(2236), // 2500 mW for 2 Ohm load
+ MV_TO_ADC8(2659), // 3536 mW for 2 Ohm load
+ MV_TO_ADC8(3162), // 5000 mW for 2 Ohm load
+};
+#define N_POWER_LEVELS (sizeof(power_levels) / sizeof(power_levels[0]))
+
+static unsigned char power_level = 0; // selected power level
+
+#define LED_BATTEMPTY_COUNT 60