Добавлены поворотники и заряд батареи

Добавлены поворотники и заряд батареи

--- main.ino
+++ main.ino
@@ -10,6 +10,7 @@

 // #define FIRST_LOADING
 // #define DEBUG
+// #define ENGINEERING_MODE

 #define set_bit(m,b)	((m) |= (b))
 #define unset_bit(m,b)	((m) &= ~(b))
@@ -31,6 +32,17 @@
 	B11111,
 	B11111,
 	B11111
+};
+
+static byte	signal_icon[8] = {
+	B00001,
+	B00011,
+	B11111,
+	B11111,
+	B11111,
+	B11111,
+	B00011,
+	B00001
 };

 /*bits system_byte*/
@@ -88,14 +100,16 @@
 #define	BUT_UP				2
 #define	BUT_DOWN			3
 #define	BUT_SIGNAL			4
+#define BATTERY_ICON		0
+#define SIGNAL_ICON			1

 /*Для определения заряда батарей*/
 #define TYPVBG				1.1
-#define R1_P0				0
-#define R2_P0				0
-#define R1_P1				0
-#define R2_P1				0
-
+#define R1_P0				469.3
+#define R2_P0				2254.0
+#define R1_P1				467.4
+#define R2_P1				2195.0
+#define VCC					5.02

 /*bits turn_signals*/
 #define TURN_SIGNAL_ON		(1 << 0)
@@ -104,16 +118,16 @@
 #define SIGNAL_LEFT_ON		(1 << 3)
 #define SIGNAL_RIGHT_ON		(1 << 4)
 #define EMERGENCY_SIGNAL	(1 << 5)
+#define SECOND_ITERATION	(1 << 6)
+#define BIP_SIGNAL			(1 << 7)

 unsigned long	lastturn;	// Время последнего обращения

 float		speed_now		= 0.0,	// Скорость
 			distance		= 0.0;	// Расстояние

-byte		bat_percent		= 100,
-			system_mode		= 0,
-			alarm_now		= false,
-			turn_signals;
+byte		system_mode		= 0,
+			alarm_now		= false;

 /*system_mode*/
 #define SPEED_MODE			0
@@ -121,7 +135,6 @@
 #define MENU_MODE			2
 #define SETTING_MODE		3
 #define SLEEP_MODE			4
-#define ENGINEERING_MODE	5

 sys_conf		btc_config; // Конфигурация системы

@@ -163,7 +176,8 @@

 	analogReference(DEFAULT);	// DEFAULT INTERNAL использовать Vcc как AREF

-	lcd.createChar(0, bat_icon);	// Загрузка иконки батареи
+	lcd.createChar(BATTERY_ICON, bat_icon);	// Загрузка иконки батареи
+	lcd.createChar(SIGNAL_ICON, signal_icon);	// Загрузка иконки батареи

 	#ifdef DEBUG
 	lcd.clear();
@@ -244,10 +258,11 @@
 	Serial.println(btc_config.wheel_length);
 	#endif

+	#ifdef ENGINEERING_MODE
 	if ((analog_to_byte(analogRead(ACTION_BUTTON)) > (btc_config.button_ok_signal - 5)) && (analog_to_byte(analogRead(ACTION_BUTTON)) > (btc_config.button_ok_signal - 5))) {
-		system_mode	= ENGINEERING_MODE;
 		engineering_menu();
 	}
+	#endif

 	registerWrite(0);

@@ -268,9 +283,6 @@
 							break;

 		case SLEEP_MODE:	break;
-
-		case ENGINEERING_MODE:	engineering_menu();
-								break;
 	}
 }

@@ -316,7 +328,7 @@

 		key_now	= analogRead(ACTION_BUTTON);

-		#ifdef DEBUG_1
+		#ifdef DEBUG
 		Serial.println("****");
 		Serial.print("Key pressed: ");
 		Serial.println(key_now);
@@ -332,7 +344,7 @@

 		key_now	= analog_to_byte(key_now);

-		#ifdef DEBUG_1
+		#ifdef DEBUG
 		Serial.println(key_now);
 		#endif

@@ -371,7 +383,7 @@
 		delay_time++;
 	}

-	#ifdef DEBUG_1
+	#ifdef DEBUG
 	Serial.println("****");
 	#endif

@@ -420,7 +432,16 @@

 			case 2:	break;

-			case 3:	break;
+			case 3:	lcd.clear();
+					lcd.print("Internal: ");
+					lcd.print(bat_state(0));
+					lcd.print("%");
+					lcd.setCursor(0, 1);
+					lcd.print("External: ");
+					lcd.print(bat_state(1));
+					lcd.print("%");
+					key_pressed(true);
+					break;

 			case 4:	system_mode	= SETTING_MODE;
 					break;
@@ -440,12 +461,13 @@
 		"Password",
 		"Light settings",
 		"Time setting",
+		"Wheel length",
 		"About system",
 		"Back"
 	};

 	while ((system_mode	== SETTING_MODE) && (sys_watch())) {
-		switch (display_list(setting_array, 6)) {
+		switch (display_list(setting_array, 7)) {
 			case 0: if (digitalRead(LOWER_LIGHT) == HIGH) {
 						digitalWrite(LOWER_LIGHT, LOW);
 					} else {
@@ -476,7 +498,11 @@
 					else time_settings();
 					break;

-			case 4: about();
+			case 4:	input_float_number("Wheel length (m)", 0.0, 50.0, btc_config.wheel_length);
+					changes	= true;
+					break;
+
+			case 5: about();
 					break;

 			default:	system_mode	= MENU_MODE;
@@ -551,11 +577,9 @@
 	}
 }

-byte input_int_number(const char *text, byte min_num, byte max_num, byte stnd) {	// Ввод целочисленного числа
+byte input_int_number(const char *text, byte min_num, byte max_num, byte same_num) {	// Ввод целочисленного числа
 	lcd.clear();
 	lcd.print(text);
-
-	byte	same_num = stnd;

 	while (true) {
 		lcd.setCursor(0, 1);
@@ -585,11 +609,9 @@
 	}
 }

-float input_float_number(char text[], float min_num, float max_num) {	// Ввод числа с точкой
+float input_float_number(const char *text, float min_num, float max_num, float same_num) {	// Ввод числа с точкой
 	lcd.clear();
 	lcd.print(text);
-
-	float	same_num = min_num;

 	while (true) {
 		lcd.setCursor(0, 1);
@@ -738,7 +760,12 @@
 }

 void road_mode() {	// Режим спидометра
-	float	speed_old = 0.1;
+	float	speed_old		= 0.1;
+
+	byte	turn_signals	= 0,
+			baterry_percent	= 0;
+
+	int		road_delay;

 	lcd.clear();
 	lcd.print("km/h: ");
@@ -747,7 +774,7 @@
 	lcd.print("km:");

 	lcd.setCursor(15, 1);
-	lcd.write(0);
+	lcd.write(BATTERY_ICON);

 	#ifdef DEBUG
 	int	key_now;
@@ -788,33 +815,117 @@
 		lcd.print(distance);

 		lcd.setCursor(12, 1);
-		if (bat_percent == 100) {
-			lcd.print("100");
-		} else if ((bat_percent > 100) && (bat_percent <= 10)){
+		baterry_percent	= bat_state(0);
+
+		if ((100 > baterry_percent) && (baterry_percent >= 10))
 			lcd.print(" ");
-			lcd.print(bat_percent);
-		} else if (bat_percent > 10){
-			lcd.print("	");
-			lcd.print(bat_percent);
-		}
-
-		switch(key_pressed(false)) {
-			case BUT_OK:		system_mode	= MENU_MODE;
+
+		if (baterry_percent < 10)
+			lcd.print("  ");
+
+		lcd.print(baterry_percent);
+
+
+		if (bit_seted(turn_signals, TURN_SIGNAL_ON)) {
+			if (bit_seted(turn_signals, TURN_SIGNAL_LEFT)) {
+				if ((bit_seted(turn_signals, SIGNAL_LEFT_ON)) && (bit_seted(turn_signals, SECOND_ITERATION))) {
+					registerWrite(LEFT_TURN_LIGHT, 0);
+					lcd.setCursor(8, 1);
+					lcd.print(" ");
+				} else if ((bit_seted(turn_signals, SIGNAL_LEFT_ON)) && !(bit_seted(turn_signals, SECOND_ITERATION))) {
+					registerWrite(LEFT_TURN_LIGHT, 1);
+					lcd.setCursor(8, 1);
+					lcd.print("<");
+				}
+			}
+
+			if (bit_seted(turn_signals, TURN_SIGNAL_RIGHT)) {
+				if ((bit_seted(turn_signals, SIGNAL_RIGHT_ON)) && (bit_seted(turn_signals, SECOND_ITERATION))) {
+					registerWrite(RIGHT_TURN_LIGHT, 0);
+					lcd.setCursor(10, 1);
+					lcd.print(" ");
+				} else if ((bit_seted(turn_signals, SIGNAL_RIGHT_ON)) && !(bit_seted(turn_signals, SECOND_ITERATION))) {
+					registerWrite(RIGHT_TURN_LIGHT, 1);
+					lcd.setCursor(10, 1);
+					lcd.print(">");
+				}
+			}
+		}
+
+		for (road_delay	= 0; road_delay < 500; road_delay++) {
+
+			switch(key_pressed(false)) {
+				case BUT_OK:		system_mode	= MENU_MODE;
+									break;
+
+				case BUT_UP:		if (bit_seted(turn_signals, TURN_SIGNAL_RIGHT)) {
+										turn_signals	= 0;
+										registerWrite(0);
+										lcd.setCursor(10, 1);
+										lcd.print("  ");
+									}
+									if (!bit_seted(turn_signals, TURN_SIGNAL_ON)) {
+										set_bit(turn_signals, TURN_SIGNAL_ON);
+										set_bit(turn_signals, TURN_SIGNAL_LEFT);
+										set_bit(turn_signals, SIGNAL_LEFT_ON);
+										registerWrite(LEFT_TURN_LIGHT, 1);
+										lcd.setCursor(8, 1);
+										lcd.print("<");
+									}
+									break;
+
+				case BUT_DOWN:		if (bit_seted(turn_signals, TURN_SIGNAL_LEFT)) {
+										turn_signals	= 0;
+										registerWrite(0);
+										lcd.setCursor(8, 1);
+										lcd.print("   ");
+									}
+									if (!bit_seted(turn_signals, TURN_SIGNAL_ON)) {
+										set_bit(turn_signals, TURN_SIGNAL_ON);
+										set_bit(turn_signals, TURN_SIGNAL_RIGHT);
+										set_bit(turn_signals, SIGNAL_RIGHT_ON);
+										registerWrite(RIGHT_TURN_LIGHT, 1);
+										lcd.setCursor(10, 1);
+										lcd.print(">");
+									}
+									break;
+
+				case BUT_SIGNAL:	tone(BIP, 2000, 250);
+									set_bit(turn_signals, BIP_SIGNAL);
+									lcd.setCursor(9, 1);
+									lcd.write(SIGNAL_ICON);
+									break;
+
+				default:		if (bit_seted(turn_signals, TURN_SIGNAL_ON)) {
+									turn_signals	= 0;
+									registerWrite(0);
+									lcd.setCursor(8, 1);
+									lcd.print("   ");
+								}
 								break;
-
-			case BUT_UP:		break;
-			case BUT_DOWN:		break;
-			case BUT_SIGNAL:	break;
-		}
-
-		#ifdef DEBUG
-		delay(500);
-		#endif
-	}
-
+			}
+			delay(1);
+		}
+
+		if (bit_seted(turn_signals, BIP_SIGNAL)) {
+			lcd.setCursor(9, 1);
+			lcd.print(" ");
+		}
+
+		if (bit_seted(turn_signals, TURN_SIGNAL_ON)) {
+			if (bit_seted(turn_signals, SECOND_ITERATION)) {
+				unset_bit(turn_signals, SECOND_ITERATION);
+			} else {
+				set_bit(turn_signals, SECOND_ITERATION);
+			}
+		}
+	}
+
+	registerWrite(0);
 	while ((analogRead(ACTION_BUTTON) > 5) && (sys_watch()));	// Ожидание отжатия кнопки
 }

+#if defined(ENGINEERING_MODE) || defined(FIRST_LOADING)
 void calibration() {
 	byte	key_num = 0;

@@ -887,7 +998,9 @@
 	lcd.print("Calibration end!");
 	delay(2000);
 }
-
+#endif
+
+#ifdef ENGINEERING_MODE
 void self_test() {
 	byte	i;

@@ -974,12 +1087,14 @@
 		"Continue"
 	};

+	bool	cycle	= true;
+
 	lcd.clear();
 	lcd.print("ENGINEERING MODE");

 	while (analogRead(ACTION_BUTTON) > 5);

-	while ((sys_watch()) && (system_mode == ENGINEERING_MODE)) {
+	while (cycle) {
 		switch (display_list(en_menu, 3)) {
 			case 0:	calibration();
 					WriteSysConfEEPROM(btc_config, 0);
@@ -988,61 +1103,26 @@
 			case 1:	self_test();
 					break;

-			default:	system_mode	= SPEED_MODE;
+			default:	cycle	= false;
 						break;
 		}
 	}
 }
-
-byte bat_state(byte pin) {
-	float	vcc			= 0.0,
-			curVoltage	= 0.0;
-
-	for (byte	i	= 0; i < 5; i++) {	// Получение точного значения опорного напряжения
-		// Read 1.1V reference against AVcc
-		// set the reference to Vcc and the measurement to the internal 1.1V reference
-		#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
-			ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
-		#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
-			ADMUX = _BV(MUX5) | _BV(MUX0);
-		#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
-			ADMUX = _BV(MUX3) | _BV(MUX2);
-		#else	// works on an Arduino 168 or 328
-			ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
-		#endif
-
-		delay(3); // Wait for Vref to settle
-		ADCSRA |= _BV(ADSC); // Start conversion
-		while (bit_is_set(ADCSRA,ADSC)); // measuring
-
-		uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH
-		uint8_t high = ADCH; // unlocks both
-
-		vcc = vcc + (TYPVBG * 1023.0) / ((high<<8) | low);
-
-		sys_watch();
-		delay(5);
-	}
-
-	vcc	= vcc / 5;
-
-	for (byte	i	= 0; i < 5; i++) {
-		curVoltage = curVoltage + analogRead(pin);
-		sys_watch();
-		delay(10);
-	}
-
-	curVoltage = curVoltage / 5;
-
-	#ifdef DEBUG
-	Serial.print("Current voltage: ");
-	Serial.println(curVoltage);
-	#endif
-
+#endif
+
+byte bat_state(byte pin) {
 	if (pin == 0) {
-		return (byte)(((((curVoltage * vcc) / 1024.0) / (R2_P0 / (R1_P0 + R2_P0))) - 2.4) / 1.8 * 100);
+		if ((((analogRead(0) * VCC) / 1024.0) / (R2_P0 / (R1_P0 + R2_P0))) < 1.0) {
+			return 0;
+		} else {
+			return (byte)(((((analogRead(0) * VCC) / 1024.0) / (R2_P0 / (R1_P0 + R2_P0))) - 2.4) / 1.8 * 100);
+		}
 	} else {
-		return (byte)(((((curVoltage * vcc) / 1024.0) / (R2_P1 / (R1_P1 + R2_P1))) - 2.4) / 1.8 * 100);
+		if ((((analogRead(1) * VCC) / 1024.0) / (R2_P1 / (R1_P1 + R2_P1))) < 1.0) {
+			return 0;
+		} else {
+			return (byte)(((((analogRead(1) * VCC) / 1024.0) / (R2_P1 / (R1_P1 + R2_P1))) - 2.4) / 1.8 * 100);
+		}
 	}

 	return 0;
@@ -1233,4 +1313,8 @@

 void delay_w(int delay_num) {
 	for (int	delay_count	= 0; ((delay_count < delay_num) && (sys_watch())); delay_count++, delay(1));
+}
+
+void system_sleep() {
+
 }


Update Sync.ino

Update Sync.ino

--- examples/More/Sync/Sync.ino
+++ examples/More/Sync/Sync.ino
@@ -16,7 +16,7 @@
  * You can synchronize the state of widgets with hardware,
  * event if hardware resets or looses connection temporarily
  *
- * App dashboard setup:
+ * Project setup in the Blynk app:
  *   Slider widget (0...100) on V0
  *   Slider widget (0...100) on V2
  *   Button widget on digital pin (connected to an LED)


server address added to transport level

server address added to transport level

--- nest.ino
+++ nest.ino
@@ -59,8 +59,8 @@
   mqtt.connect();

   /// connected message
-  uint8_t data[9] = { macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5], 255, 255, 255};
-  uint8_t len = 9;
+  uint8_t data[10] = { macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5],SERVER_ADDRESS, 255, 255, 255};
+  uint8_t len = 10;
   publish(data, len);
   Serial.println(F("setup() done"));
 }
@@ -109,8 +109,8 @@
     uint8_t len = 2;
     uint8_t from;
     if (manager.recvfromAck(buf, &len, &from)) {
-      uint8_t data[9] = { macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5], from, buf[0], buf[1]};
-      uint8_t len = 9;
+      uint8_t data[10] = { macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5], SERVER_ADDRESS, from, buf[0], buf[1]};
+      uint8_t len = 10;
       publish(data, len);
       // Send a reply back to the originator client
       if (!manager.sendtoWait(buf, 2, from)) {


Updated comments about pressure readings.

Added note and formula for converting from mb to in.Hg.

--- firmware/examples/SparkFun_Photon_Weather_Shield_Example.ino
+++ firmware/examples/SparkFun_Photon_Weather_Shield_Example.ino
@@ -138,10 +138,16 @@

   Serial.print("Pressure:");
   Serial.print(pascals/100);
-  Serial.println("hPa, ");
+  Serial.print("hPa, ");
+  Serial.print((pascals/100) * 0.0295300);
+  Serial.println("in.Hg");
   //The MPL3115A2 outputs the pressure in Pascals. However, most weather stations
   //report pressure in hectopascals or millibars. Divide by 100 to get a reading
   //more closely resembling what online weather reports may say in hPa or mb.
+  //Another common unit for pressure is Inches of Mercury (in.Hg). To convert
+  //from mb to in.Hg, use the following formula. P(inHg) = 0.0295300 * P(mb)
+  //More info on conversion can be found here:
+  //www.srh.noaa.gov/images/epz/wxcalc/pressureConversion.pdf

   //If in altitude mode, print with these lines
   //Serial.print("Altitude:");


Convert global variables to local

Convert global variables to local

Just a minor edit to move these (unnecessary) global variables into local scope.

--- spi_read_eeprom.ino
+++ spi_read_eeprom.ino
@@ -2,9 +2,6 @@

 #define SPI_READ_CMD 0x03
 #define CS_PIN 10
-
-unsigned int num_bytes;
-unsigned int i;

 void setup() {
   Serial.begin(115200);
@@ -34,6 +31,8 @@
 }

 void loop() {
+  unsigned int num_bytes;
+  unsigned int i;

   /* wait for the integer with the requested number of bytes */
   if (Serial.available() == 4) {


Removed last traces of obsolete error logic

--- arduferm/arduferm.ino
+++ arduferm/arduferm.ino
@@ -5,7 +5,7 @@
 #include <avr/pgmspace.h>

 // Pin layout
-const byte compressorPin = 2;
+const byte compressorPin = 3;
 const byte incrSetPointPin = 7;
 const byte decrSetPointPin = 6;

@@ -28,10 +28,6 @@
 boolean needCooling = LOW;
 boolean canCool = HIGH;
 unsigned long coolingStarted;
-const unsigned long starterPeriod = 500;
-boolean starting = LOW;
-int starterMeasurement;
-int maxStarterMeasurement;

 boolean inGracePeriod = LOW;
@@ -108,7 +104,6 @@
   digitalWrite(decrSetPointPin, HIGH);

   // Relays
-  pinMode(starterPin, OUTPUT);
   pinMode(compressorPin, OUTPUT);

   // LCD screen
@@ -131,7 +126,7 @@
     if (inGracePeriod) {
       // If the grace period is over reset boolean
       if (currentMillis - gracePeriodStart > gracePeriod) {
-	inGracePeriod = LOW;
+    	inGracePeriod = LOW;
       }
     }

@@ -139,10 +134,9 @@
     if (inCooldownPeriod) {
       // If the grace period is over reset boolean
       if (currentMillis - cooldownPeriodStart > cooldownPeriod) {
-	inCooldownPeriod = LOW;
-      }
-    }
-
+    	inCooldownPeriod = LOW;
+      }
+    }

     // Temperature measurement
     int temperature = getTemperature();
@@ -151,34 +145,34 @@
     // When a button has been pressed, go and
     // change the setpoint
     if ((digitalRead(incrSetPointPin) == LOW) || \
-	(digitalRead(decrSetPointPin) == LOW))
+    	(digitalRead(decrSetPointPin) == LOW))
       {
-	// Figure out by how much to change setpoint
-	// If buttons pressed down, then increment a lot
-	int increment;
-	if (pressCount > 10) {
-	  increment = 10;
-	}
-	else {
-	  increment = 1;
-	}
-
-	// Now increment / decrement according to
-	// which button has been pressed
-	if(digitalRead(incrSetPointPin) == LOW) {
-	  setPoint += increment;
-	}
-	if(digitalRead(decrSetPointPin) == LOW) {
-	  setPoint -= increment;
-	}
-	pressCount++;
+    	// Figure out by how much to change setpoint
+    	// If buttons pressed down, then increment a lot
+    	int increment;
+    	if (pressCount > 10) {
+    	  increment = 10;
+    	}
+    	else {
+    	  increment = 1;
+    	}
+
+    	// Now increment / decrement according to
+    	// which button has been pressed
+    	if(digitalRead(incrSetPointPin) == LOW) {
+    	  setPoint += increment;
+    	}
+    	if(digitalRead(decrSetPointPin) == LOW) {
+    	  setPoint -= increment;
+    	}
+    	pressCount++;
       }
     else {
       pressCount = 0;
     }

     // Figure out whether you need cooling or not
-    // Assume you can cool and then check whether
+    // Assume you can cool and then check whether
     // anything forbids you to cool.
     // After that check whether you really need to
     // cool
@@ -196,10 +190,10 @@
       // the temperature is not yet enough
       // below the set point, keep cooling
       if (temperature > setPoint - 10) {
-	needCooling = HIGH;
+    	needCooling = HIGH;
       }
       else {
-	needCooling = LOW;
+    	needCooling = LOW;
       }
     }
     else {
@@ -207,10 +201,10 @@
       // temperature is high enough above setpoint
       // keep cooling
       if (temperature > setPoint + 10) {
-	needCooling = HIGH;
+    	needCooling = HIGH;
       }
       else {
-	needCooling = LOW;
+    	needCooling = LOW;
       }
     }

@@ -218,15 +212,15 @@
     if (needCooling && canCool) {
       // If you just started cooling, write down time
       if (!beenCooling) {
-	coolingStarted = currentMillis;
+    	coolingStarted = currentMillis;
       }

       // Check whether you have been cooling for to long
       if (currentMillis - coolingStarted > maxCoolingPeriod) {
-	// The following will trigger to go into noon cooling state
-	// in the next iteration of the main loop
-	inCooldownPeriod = HIGH;
-	cooldownPeriodStart = currentMillis;
+    	// The following will trigger to go into noon cooling state
+    	// in the next iteration of the main loop
+    	inCooldownPeriod = HIGH;
+    	cooldownPeriodStart = currentMillis;
       }

       digitalWrite(compressorPin, HIGH);
@@ -237,14 +231,13 @@
       // If you just came here from cooling state
       // Trigger grace period or cooldown period
       if (beenCooling) {
-	if (inCooldownPeriod) {
-	  // Nothing all set in previous loop
-	}
-	else {
-	  gracePeriodStart = currentMillis;
-	  inGracePeriod = HIGH;
-	}
-	maxStarterMeasurement = 0;
+    	if (inCooldownPeriod) {
+    	  // Nothing all set in previous loop
+    	}
+    	else {
+    	  gracePeriodStart = currentMillis;
+    	  inGracePeriod = HIGH;
+    	}
       }
       digitalWrite(compressorPin, LOW);
       beenCooling = LOW;
@@ -276,37 +269,27 @@
     lcd.print("                ");
     lcd.setCursor(0,1);
     if (beenCooling) {
-      if (starting) {
-	lcd.print("Starting ");
-	lcd.print(maxStarterMeasurement);
-      }
-      else{
-	lcd.print("Cooling ah");
-	lcd.print(starterMeasurement);
-	//writeCountdown((currentMillis - coolingStarted)/1000, 5, 11, 1);
-      }
+  	lcd.print("Cooling ah");
+  	//writeCountdown((currentMillis - coolingStarted)/1000, 5, 11, 1);
     }
     else {
       if (inGracePeriod) {
-	lcd.print("Cannot cool");
-	writeCountdown((gracePeriodStart + gracePeriod - \
-			currentMillis) / 1000, 5, 11, 1);
+  	lcd.print("Cannot cool");
+  	writeCountdown((gracePeriodStart + gracePeriod - \
+  			currentMillis) / 1000, 5, 11, 1);
       }
       else if (inCooldownPeriod)
       {
-	lcd.print("Too hot ah");
-	writeCountdown((cooldownPeriodStart + cooldownPeriod - \
-			currentMillis) / 1000, 5, 11, 1);
-      }
-      else if (errorDetected) {
-	lcd.print("Retreat!Retreat!");
+  	lcd.print("Too hot ah");
+  	writeCountdown((cooldownPeriodStart + cooldownPeriod - \
+  			currentMillis) / 1000, 5, 11, 1);
       }
       else {
-	lcd.print("Cool enough alr!");
+  	lcd.print("Cool enough alr!");
       }
     }
     previousMillis = currentMillis;
-
+
   } // End main loop if
 }


fixed race condition, maybe...

fixed race condition, maybe...

--- prototype/prototype-3/prototype-3.ino
+++ prototype/prototype-3/prototype-3.ino
@@ -1,6 +1,6 @@
-//#define COMPONENT_TEST_MOTOR_COAST
+#define COMPONENT_TEST_MOTOR_COAST
 //#define COMPONENT_TEST_MOTOR_TIME
-#define COMPONENT_TEST_INTERRUPT_COST
+//#define COMPONENT_TEST_INTERRUPT_COST
 //#define API_TEST_MOTOR_TURN_DEG
 //#define KILLALL // Uncomment this to kill the system, and stop all components

@@ -20,6 +20,7 @@
 struct Motor {
   int pin = 0;
   volatile long deg = 0;
+  byte lock = 0;
   Turning_Direction dir = COUNTERCLOCKWISE;
 };

@@ -29,9 +30,6 @@

 Motor motor1, motor2, motor3;

-
-
-
 void setup() {
 #ifdef KILLALL
   exit(0);
@@ -41,7 +39,7 @@
   motor2.pin = MOTOR_2_PIN;
   //motor3.pin = MOTOR_3_PIN;

-  Serial.begin(9600);
+  Serial.begin(9200);

   pinMode(MOTOR_1_INT_PIN, INPUT_PULLUP);
   //pinMode(MOTOR_2_INT_PIN, INPUT_PULLUP);
@@ -76,6 +74,9 @@
 #endif
 }

+void loop() {
+}
+
 void motor1_interrupt() {
   motor1.deg += motor1.dir;
 }
@@ -91,25 +92,60 @@
 void motor_turn_deg(Motor* motor, int deg, Turning_Direction dir)
 {
   int goal = motor->deg + (deg * dir);
+  bool error = false;
+  bool waiting = true;

   motor_turn(motor, dir);

   switch (motor->dir) {
     case CLOCKWISE:
-      while (goal <= motor->deg) {
-        delay(1);
-      }
+      do {
+        noInterrupts();
+        waiting = goal < motor->deg;
+        interrupts();
+      } while (waiting);
+
+      error = goal < motor->deg;
       break;
     case COUNTERCLOCKWISE:
-      while (goal >= motor->deg) {
-        delay(1);
-      }
+      do {
+        noInterrupts();
+        waiting = goal > motor->deg;
+        interrupts();
+      } while (waiting);
+
+      error = goal > motor->deg;
       break;
     default:
-      Serial.println("NO ROTATION");
+      error = true;
       break;
   }
+
   motor_stop(motor);
+
+  if (error) {
+    Serial.println("ERROR: motor_turn_deg");
+    Serial.print("goal: "); Serial.println(goal);
+    Serial.print("motor->deg: "); Serial.println(motor->deg);
+    Serial.print("dir: ");
+
+    switch (motor->dir) {
+      case CLOCKWISE:
+        Serial.println("CLOCKWISE");
+        Serial.print("goal < motor->deg = "); Serial.println(error ? "true" : "false");
+        break;
+      case COUNTERCLOCKWISE:
+        Serial.println("COUNTERCLOCKWISE");
+        Serial.print("goal > motor->deg = "); Serial.println(error ? "true" : "false");
+        break;
+      default:
+        Serial.println("NOT SUPPORTED DIR");
+        break;
+    }
+
+    delay(1000);
+    exit(0);
+  }
 }

 void motor_stop(Motor* motor)
@@ -121,10 +157,6 @@
 {
   motor->dir = dir;
   digitalWrite(motor->pin, HIGH);
-}
-
-void loop() {
-  // put your main code here, to run repeatedly:
 }

 /*******************************
@@ -135,10 +167,6 @@
   for (int i = 0; i < 20; i++) {
     motor->deg = 0;
     motor_turn_deg(motor, 360, COUNTERCLOCKWISE);
-    if (motor->deg < 360) {     // In case it happens that the loop breaks out before 360 degrees
-      Serial.println("ERROR");  // thrown an error, because that is not supposed to happen.
-      exit(0);                  // The error should be fixed, but cant be sure yet.
-    }

     delay(1000);
     Serial.println(motor->deg); // Value used for component testing.


fixed bobbo regarding hours before 10am

fixed bobbo regarding hours before 10am

--- control/control.ino
+++ control/control.ino
@@ -242,7 +242,7 @@
 {
   // digital clock display of the time
   lcd.home();
-  if (hour() == 0)
+  if (hour() < 10)
     lcd.print('0');
   lcd.print(hour());
   printDigits(minute());


string table for program memory

string table for program memory


Sketchlist: fix initial invalid state

Sketchlist: fix initial invalid state

Button default was reversed earlier, forgot this bit

--- examples/SketchList/SketchList.ino
+++ examples/SketchList/SketchList.ino
@@ -417,7 +417,7 @@

   /* Set up the UI button icons and states */
   const unsigned char* button_icon[EDIT_IDX_NONE] = {
-    edit_icon_changecolor_1, edit_icon_reset,  edit_icon_cancel,
+    edit_icon_changecolor_0, edit_icon_reset,  edit_icon_cancel,
     edit_icon_delete,        edit_icon_charup, edit_icon_accept
   };
   unsigned char button_dirty[EDIT_IDX_NONE + 1];


Update Firmware.ino

Update Firmware.ino

--- src/piggy_back_loggers/SD_prototype_Firmware/Firmware/Firmware.ino
+++ src/piggy_back_loggers/SD_prototype_Firmware/Firmware/Firmware.ino
@@ -89,6 +89,8 @@

   attachInterrupt(digitalPinToInterrupt(2), INT0_ISR, FALLING);   // Setup Interrupts
   attachInterrupt(digitalPinToInterrupt(3), INT1_ISR, FALLING);
+  EIMSK &= ~(1 << INT0);        // Disable Hall Effect Sensor interrupt
+  EIMSK |= (1 << INT1);         // Enable 4-Second RTC interrupt.

   loadDateTime(&Date);            // Load Date_t with Date/Time info


uncommented examples

uncommented examples

--- examples/readsensor/readsensor.ino
+++ examples/readsensor/readsensor.ino
@@ -14,7 +14,7 @@

 void loop() {
-/*
+
     // temperature is an integer in hundredths
     int temperature = sensor.getCelsiusHundredths();
     temperature = temperature / 100;
@@ -38,7 +38,7 @@
         pulse(led1);
     }
     delay(5000);
-*/
+
     // enable internal heater for testing
     sensor.setHeater(true);
     delay(20000);
@@ -55,7 +55,6 @@
     delay(20000);

     // get humidity and temperature in one shot, saves power because sensor takes temperature when doing humidity anyway
-
     si7021_env data = sensor.getHumidityAndTemperature();
     for (int i = 0; i < data.celsiusHundredths/100; i++) {
         pulse(led1);


Replaced "if" with "#if", changed int to uint32_t

Replaced if statements with #if preprocessor macros.
Replaced one #ifdef macro with #if.
Changed `int secondTimer` to `uint32_t secondTimer` to avoid signed/unsigned integer comparison. The `millis()` function returns `uint32_t`.
Removed asterix output from FPS output.

--- arduino/ws2812_controller/ws2812_controller.ino
+++ arduino/ws2812_controller/ws2812_controller.ino
@@ -5,11 +5,11 @@
 #include <WiFiUdp.h>
 #include "ws2812_i2s.h"

-// Set this to the number of LEDs in your LED strip
-
+// Set to the number of LEDs in your LED strip
 #define NUM_LEDS 60
 // Maximum number of packets to hold in the buffer. Don't change this.
 #define BUFFER_LEN 1024
+// Toggles FPS output (1 = print FPS over serial, 0 = disable output)
 #define PRINT_FPS 1

 // Wifi and socket settings
@@ -50,9 +50,9 @@
 }

 uint8_t N = 0;
-#ifdef PRINT_FPS
-    int fpsCounter = 0;
-    int secondTimer = 0;
+#if PRINT_FPS
+    uint16_t fpsCounter = 0;
+    uint32_t secondTimer = 0;
 #endif

 void loop() {
@@ -60,29 +60,24 @@
     int packetSize = port.parsePacket();
     // If packets have been received, interpret the command
     if (packetSize) {
-      int len = port.read(packetBuffer, BUFFER_LEN);
-        for(int i = 0; i < len; i+=4){
+        int len = port.read(packetBuffer, BUFFER_LEN);
+        for(int i = 0; i < len; i+=4) {
             packetBuffer[len] = 0;
             N = packetBuffer[i];
             pixels[N].R = (uint8_t)packetBuffer[i+1];
             pixels[N].G = (uint8_t)packetBuffer[i+2];
             pixels[N].B = (uint8_t)packetBuffer[i+3];
         }
-      ledstrip.show(pixels);
-
-      if(PRINT_FPS == 1)
-      {
-        Serial.print("*");
-        fpsCounter++;
-      }
-  }
- if(PRINT_FPS == 1){
-  if(millis() - secondTimer >= 1000)
-  {
-    secondTimer = millis();
-
-    Serial.printf("FPS: %d\n", fpsCounter);
-    fpsCounter = 0;
-  }
- }
+        ledstrip.show(pixels);
+        #if PRINT_FPS
+            fpsCounter++;
+        #endif
+    }
+    #if PRINT_FPS
+        if (millis() - secondTimer >= 1000U) {
+            secondTimer = millis();
+            Serial.printf("FPS: %d\n", fpsCounter);
+            fpsCounter = 0;
+        }
+    #endif
 }


first start for havin PingPong playing support

--- Arduino/Arduino.ino
+++ Arduino/Arduino.ino
@@ -4,6 +4,9 @@
  * GitHub: https://github.com/cbries
  * License: MIT, see https://github.com/cbries
  *
+ * 2015-06-13 Christian Benjamin Ries
+ *  - add mode (i.e. 'mF') for default LED control based on direct address access
+ *
  * 2015-04-06 Christian Benjamin Ries
  *   - store recent mode in EEPROM
  *
@@ -53,7 +56,7 @@
 #define SPI_SEND(v) spi_transfer(v)
 #define SPI_STOP PORTB |= ( 1 << SPI_LATCH_PIN )

-volatile uint8_t MAX_BRIGHTNESS = 15; // 0...50 above 50 looks bad
+volatile uint8_t MAX_BRIGHTNESS = 14; // 0...50 above 50 looks bad

 #define __TIMER1_MAX 0xFFFF // 16 bit CTR
 #define __TIMER1_CNT 0x0155 // absoluter Grenzwert: 0x0150, > 0x0170 (little flicker)
@@ -177,11 +180,17 @@
 byte isr_green[DEVICES_ARRAY_SIZES] = { 0, 0, 0, 0 }; // current sinker when on (0)
 byte isr_blue [DEVICES_ARRAY_SIZES] = { 0, 0, 0, 0 }; // current sinker when on (0)

+//! used for enabling/disabling timer-based visualization
 volatile bool DoRefresh = true;

+//! true:=any LED must be controlled manually (i.e. 'mF' is set)
+//! false:=an automatically generated visualization is used
+volatile bool DoManuallyMode = false;
+
 ISR(TIMER1_OVF_vect)
 {
-  if(DoRefresh == false) { return; }
+  if(DoRefresh == false || DoManuallyMode == true)
+    return;

   TCNT1 = __TIMER1_MAX - __TIMER1_CNT;

@@ -295,11 +304,12 @@
   checkSerial();
   switch(RUNMODE)
   {
-    case 'A': runGrid(); break;
-    case 'B': for(unsigned int i=0; i < 100; ++i) { random_leds(); copyBuffer(); delayMicroseconds(10); } break;
-    case 'C': color_wave(18); copyBuffer(); delayMicroseconds(25); break;
-    case 'D': rainbow(); delayMicroseconds(25); break;
-    case 'E': ShowGoomba(); delayMicroseconds(25); break;
+    case 'A': DoManuallyMode=false; runGrid(); break;
+    case 'B': DoManuallyMode=false; for(unsigned int i=0; i < 100; ++i) { random_leds(); copyBuffer(); delayMicroseconds(10); } break;
+    case 'C': DoManuallyMode=false; color_wave(18); copyBuffer(); delayMicroseconds(25); break;
+    case 'D': DoManuallyMode=false; rainbow(); delayMicroseconds(25); break;
+    case 'E': DoManuallyMode=false; ShowGoomba(); delayMicroseconds(25); break;
+    case 'F': manuallyControl(); break;
   }
 }

@@ -343,7 +353,7 @@
 byte index = 0;

 void checkSerial()
-{
+{
   while (Serial.available() > 0)
   {
     DoRefresh = false;
@@ -376,7 +386,7 @@

     if(sbuf[0] == 'm' && index == 3)
     {
-      RUNMODE = sbuf[1];
+      RUNMODE = sbuf[1];
       EEPROM.write(RUNMODE_EEPROM_ADDR, RUNMODE);
       Serial.println(" OK ");
     }
@@ -419,7 +429,7 @@

       Serial.println(" OK ");
     }
-
+
     index = 0;
   }
 }
@@ -468,3 +478,193 @@
   set_led_rgb(0, 9, 14, 11, 8);	set_led_rgb(1, 9, 14, 11, 9);	set_led_rgb(2, 9, 14, 11, 9);	set_led_rgb(3, 9, 13, 10, 7);	set_led_rgb(4, 9, 13, 9, 6);	set_led_rgb(5, 9, 13, 11, 8);	set_led_rgb(6, 9, 13, 12, 10);	set_led_rgb(7, 9, 13, 12, 10);	set_led_rgb(8, 9, 13, 12, 10);	set_led_rgb(9, 9, 13, 12, 10);	set_led_rgb(10, 9, 13, 12, 10);	set_led_rgb(11, 9, 13, 12, 10);	set_led_rgb(12, 9, 13, 12, 10);	set_led_rgb(13, 9, 13, 11, 9);	set_led_rgb(14, 9, 13, 9, 6);	set_led_rgb(15, 9, 14, 10, 7);	set_led_rgb(16, 9, 14, 11, 9);	set_led_rgb(17, 9, 14, 11, 9);	set_led_rgb(18, 9, 14, 11, 9);	set_led_rgb(19, 9, 14, 11, 9);
 }

+// ##############################################
+//  STILL IN PROGRESSS - NOT FULLY IMPLEMENTED
+// ##############################################
+
+class Block
+{
+protected:
+  uint8_t _red, _green, _blue;
+  uint8_t _width, _height;
+  uint8_t _x, _y;
+
+public:
+  Block() { _red = 0; _green = 0; _blue = 255; _width = 1; _height = 1; _x = 0; _y = 0; }
+  Block(uint8_t r, uint8_t g, uint8_t b, uint8_t w, uint8_t h)
+    : _red(r), _green(g), _blue(b), _width(w), _height(h)
+  { }
+
+  inline void setPos(uint8_t x, uint8_t y)
+  {  _x = x; _y = y; }
+
+  inline void draw()
+  {
+    for(uint8_t xx=0; xx < _width; ++xx)
+    {
+      for(uint8_t yy=0; yy < _height; ++yy)
+      {
+        uint8_t xcoord = _x + xx;
+        uint8_t ycoord = _y + yy;
+
+        if(xcoord < 0 || xcoord > WIDTH)
+          continue;
+        if(ycoord < 0 || ycoord > HEIGHT)
+          continue;
+
+        set_led_rgb(xcoord, ycoord, _red, _green, _blue);
+      }
+    }
+  }
+
+  enum Direction { Up=0, Down=1, None=2, Left=3, Right=4 };
+
+protected:
+  Direction _directionX;
+  Direction _directionY;
+
+  virtual bool isValidMoveX(uint8_t stepx) = 0;
+  virtual bool isValidMoveY(uint8_t stepy) = 0;
+  virtual bool moveX(Direction direction) = 0;
+  virtual bool moveY(Direction direction) = 0;
+  virtual bool move() = 0;
+};
+
+class Ball : public Block
+{
+public:
+  Ball(uint8_t r, uint8_t g, uint8_t b, uint8_t w, uint8_t h) : Block(r, g, b, w, h) { }
+
+  bool isValidMoveX(uint8_t stepx) { return false; }
+  bool isValidMoveY(uint8_t stepy) { return false; }
+  bool moveX(Direction direction) { return false; }
+  bool moveY(Direction direction) { return false; }
+  bool move() { return false; }
+};
+
+class Player : public Block
+{
+public:
+  Player(uint8_t r, uint8_t g, uint8_t b, uint8_t w, uint8_t h) : Block(r, g, b, w, h) { }
+
+  bool isValidMoveX(uint8_t stepx) { return false; }
+  bool isValidMoveY(uint8_t stepy) { return false; }
+  bool moveX(Direction direction) { return false; }
+  bool moveY(Direction direction) { return false; }
+  bool move() { return false; }
+};
+
+bool PlayfieldGenerated = false;
+Block *PlayfieldPart[3] { NULL, NULL, NULL };
+uint8_t PlayfieldKeepPreviousBrightness = 15;
+unsigned long PlayfieldRecentTime;
+unsigned long PlayfieldRecentTimeNext;
+unsigned long PlayfieldRecentTimeWaitFor = 10;
+
+void PlayfieldDispose()
+{
+  MAX_BRIGHTNESS = PlayfieldKeepPreviousBrightness;
+  PlayfieldRecentTime = 0;
+  delete PlayfieldPart[0];
+  delete PlayfieldPart[1];
+  delete PlayfieldPart[2];
+  PlayfieldGenerated = false;
+}
+
+bool PlayfieldSimulate()
+{
+  if(millis() < PlayfieldRecentTimeNext)
+    return false;
+  else
+    PlayfieldRecentTimeNext = millis() + PlayfieldRecentTimeWaitFor;
+
+  // TODO
+
+  return true;
+}
+
+void PlayfieldGenerate()
+{
+  PlayfieldKeepPreviousBrightness = MAX_BRIGHTNESS;
+  MAX_BRIGHTNESS = 255;
+  PlayfieldRecentTime = millis();
+  PlayfieldRecentTimeNext = millis() + PlayfieldRecentTimeWaitFor;
+
+  PlayfieldPart[0] = new Ball(255, 0, 0, 1, 1);
+  PlayfieldPart[0]->setPos(10, 5);
+
+  PlayfieldPart[1] = new Player(0, 255, 255, 1, 4);
+  PlayfieldPart[1]->setPos(0, 3);
+
+  PlayfieldPart[2] = new Player(255, 0, 255, 1, 4);
+  PlayfieldPart[2]->setPos(19, 3);
+
+  PlayfieldGenerated = true;
+
+  Serial.println(" Playfield generated, have fun!");
+}
+
+void PlayfieldReset()
+{
+  for(uint8_t x = 0; x < WIDTH; ++x) {
+    for(uint8_t y = 0; y < HEIGHT; ++y) {
+      set_led_rgb(x, y, 0, 0, 0);
+    }
+  }
+}
+
+void PlayfieldRender()
+{
+  for(int i=0; i < 3; ++i)
+    PlayfieldPart[i]->draw();
+}
+
+void PlayfieldRefresh()
+{
+  for(byte isr_cycle = 0; isr_cycle < MAX_BRIGHTNESS; ++isr_cycle)
+  {
+    for(byte isr_row = 0; isr_row < ROWS; ++isr_row)
+    {
+      SPI_START;
+      for(byte isr_dev=0; isr_dev < DEVICES; ++isr_dev)
+      {
+        isr_red[isr_dev]   = 0x00;
+        isr_green[isr_dev] = 0x00;
+        isr_blue[isr_dev]  = 0x00;
+
+        for(byte isr_col = 0, cc=0; isr_col < NUM_CR; isr_col += COLUMNS, ++cc)
+        {
+          if(isr_cycle < BRIGHTNESS_RED2(devoffsets[isr_dev], isr_col, isr_row))   { isr_red[isr_dev]   |= (1 << cc); }
+          if(isr_cycle < BRIGHTNESS_GREEN2(devoffsets[isr_dev], isr_col, isr_row)) { isr_green[isr_dev] |= (1 << cc); }
+          if(isr_cycle < BRIGHTNESS_BLUE2(devoffsets[isr_dev], isr_col, isr_row))  { isr_blue[isr_dev]  |= (1 << cc); }
+        }
+
+        SPI_SEND(isr_blue[isr_dev]);
+        SPI_SEND(isr_green[isr_dev]);
+        SPI_SEND(isr_red[isr_dev]);
+        SPI_SEND(B00000001 << isr_row);
+      }
+      SPI_STOP;
+    }
+  }
+
+  delayMicroseconds(100);
+}
+
+void manuallyControl()
+{
+  if(!PlayfieldGenerated)
+    PlayfieldGenerate();
+
+  DoManuallyMode = true;
+  DoRefresh = false;
+
+  bool res = PlayfieldSimulate();
+  if(res)
+  {
+    PlayfieldReset();
+    PlayfieldRender();
+    PlayfieldRefresh();
+  }
+}
+


update afsk_messenger example

update afsk_messenger example

--- examples/AFSK_SerialMessenger/AFSK_SerialMessenger.ino
+++ examples/AFSK_SerialMessenger/AFSK_SerialMessenger.ino
@@ -58,8 +58,8 @@
   radio.setVolume2(0xFF);
   radio.setSQHiThresh(-100);
   radio.setSQLoThresh(-100);
-  radio.setSQOn();
-  //radio.bypassPreDeEmph();
+  //radio.setSQOn();
+  radio.bypassPreDeEmph();
   dds.start();
   afsk.start(&dds);
   delay(100);


some other interface options avialable

some other interface options avialable

--- examples/BluefruitLE_nrf51822/BluefruitLE_nrf51822.ino
+++ examples/BluefruitLE_nrf51822/BluefruitLE_nrf51822.ino
@@ -7,7 +7,7 @@
 #endif

 // Change this to whatever is the Serial console you want, either Serial or SerialUSB
-#define FIRMATADEBUG    SerialUSB
+#define FIRMATADEBUG    Serial
 // Pause for Serial console before beginning?
 #define WAITFORSERIAL   true
 // Print all BLE interactions?
@@ -24,7 +24,7 @@
 */

 /************** For Bluefruit Micro or Feather 32u4 Bluefruit ************/
-//uint8_t boards_digitaliopins[] = {0,1,2,3,5,6,9,10,11,12,13,A0,A1,A2,A3,A4,A5};
+uint8_t boards_digitaliopins[] = {0,1,2,3,5,6,9,10,11,12,13,A0,A1,A2,A3,A4,A5};

 /************** For UNO + nRF58122 SPI & shield ************/
 //uint8_t boards_digitaliopins[] = {2, 3, 5, 6, 9, 10, A0, A1, A2, A3, A4, A5};
@@ -68,12 +68,28 @@
 #include "Adafruit_BluefruitLE_UART.h"
 #include "BluefruitConfig.h"

-#define AUTO_INPUT_PULLUPS true
-
+
+// Create the bluefruit object, either software serial...uncomment these lines
+/*
+SoftwareSerial bluefruitSS = SoftwareSerial(BLUEFRUIT_SWUART_TXD_PIN, BLUEFRUIT_SWUART_RXD_PIN);
+
+Adafruit_BluefruitLE_UART bluefruit(bluefruitSS, BLUEFRUIT_UART_MODE_PIN,
+                      BLUEFRUIT_UART_CTS_PIN, BLUEFRUIT_UART_RTS_PIN);
+*/
+
+/* ...or hardware serial, which does not need the RTS/CTS pins. Uncomment this line */
+// Adafruit_BluefruitLE_UART bluefruit(BLUEFRUIT_HWSERIAL_NAME, BLUEFRUIT_UART_MODE_PIN);

 /* ...hardware SPI, using SCK/MOSI/MISO hardware SPI pins and then user selected CS/IRQ/RST */
 Adafruit_BluefruitLE_SPI bluefruit(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);

+/* ...software SPI, using SCK/MOSI/MISO user-defined SPI pins and then user selected CS/IRQ/RST */
+//Adafruit_BluefruitLE_SPI bluefruit(BLUEFRUIT_SPI_SCK, BLUEFRUIT_SPI_MISO,
+//                             BLUEFRUIT_SPI_MOSI, BLUEFRUIT_SPI_CS,
+//                             BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);
+
+
+#define AUTO_INPUT_PULLUPS true

 // our current connection status
 boolean lastBTLEstatus, BTLEstatus;
@@ -841,4 +857,3 @@
     }
   }
 }
-


ugh remove test example

ugh remove test example

--- examples/OnDemandConfigPortal/OnDemandConfigPortal.ino
+++ examples/OnDemandConfigPortal/OnDemandConfigPortal.ino
@@ -19,10 +19,6 @@
   Serial.println(modes[WiFi.getMode()]);
   WiFi.printDiag(Serial);

-  //WiFiManager
-  //Local intialization. Once its business is done, there is no need to keep it around
-  WiFiManager wifiManager;
-
   //Local intialization. Once its business is done, there is no need to keep it around
   //reset settings - for testing
   //wifiManager.resetSettings();
@@ -30,49 +26,9 @@
   //sets timeout until configuration portal gets turned off
   //useful to make it all retry or go to sleep
   //in seconds
-  wifiManager.setConfigPortalTimeout(20);
-  wifiManager.setConnectTimeout(10);
-  // wifiManager.setShowStaticFields(true);
-
+  wifiManager.setConfigPortalTimeout(180);
   // uint8_t menu[] = {wifiManager.MENU_WIFI,wifiManager.MENU_INFO,wifiManager.MENU_PARAM,wifiManager.MENU_CLOSE};
   // wifiManager.setMenu(menu);
-
-  // std::vector<WiFiManager::menu_page_t> menu = {wifiManager.MENU_WIFI,wifiManager.MENU_INFO,wifiManager.MENU_PARAM,wifiManager.MENU_CLOSE,wifiManager.MENU_SEP,wifiManager.MENU_ERASE,wifiManager.MENU_EXIT};
-  // wifiManager.setMenu(menu);
-
-// std::vector<WiFiManager::menu_page_t> menu = {wifiManager.MENU_WIFI,wifiManager.MENU_INFO,wifiManager.MENU_PARAM,wifiManager.MENU_CLOSE,wifiManager.MENU_SEP,wifiManager.MENU_ERASE,wifiManager.MENU_EXIT};
-  // wifiManager.setMenu(menu);
-
-
-  WiFiManagerParameter custom_mqtt_server("server", "mqtt server", "", 40);
-  WiFiManagerParameter custom_mqtt_port("port", "mqtt port", "", 6);
-  WiFiManagerParameter custom_blynk_token("api_token", "api token", "", 0);
-
-  //add all your parameters here
-  wifiManager.addParameter(&custom_mqtt_server);
-  wifiManager.addParameter(&custom_mqtt_port);
-  wifiManager.addParameter(&custom_blynk_token);
-
-        // MENU_WIFI       = 0,
-        // MENU_WIFINOSCAN = 1,
-        // MENU_INFO       = 2,
-        // MENU_PARAM      = 3,
-        // MENU_CLOSE      = 4,
-        // MENU_RESTART    = 5,
-        // MENU_EXIT       = 6,
-        // MENU_ERASE      = 7,
-        // MENU_SEP        = 8
-
-  // const char* menu[] = {"wifi","wifinoscan","info","param","close","sep","erase","restart","exit"};
-  // wifiManager.setMenu(menu,9);
-
-  std::vector<const char *> menu = {"wifi","wifinoscan","info","param","close","sep","erase","restart","exit"};
-  wifiManager.setMenu(menu);
-
-  //set static ip
-  wifiManager.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
-  // wifiManager.setShowStaticFields(false);
-  // wifiManager.setShowDnsFields(false);

   //fetches ssid and pass and tries to connect
   //if it does not connect it starts an access point with the specified name
@@ -120,4 +76,4 @@
   }

   // put your main code here, to run repeatedly:
-}
+}


Updated: display in use timer

Updated: display in use timer

--- meeting_room/meeting_room.ino
+++ meeting_room/meeting_room.ino
@@ -33,8 +33,9 @@
   if(MoudleState.PIR_State) {
       print_in_use();
       clear_all();
-      setNumber(1, 1);
-      setNumber(2, 0);
+      Serial.println(MoudleState.InUseTime,DEC);
+      setNumber(1, MoudleState.InUseTime/10);
+      setNumber(2, MoudleState.InUseTime%10);
       timer_pixels.show();

   } else {


Add defines for disable delay

Add defines for disable delay

Added the option to completely disable delays, instead of just having a delay
of 0, which still incurs a penalty for function calls.

--- Guzheng/Guzheng.ino
+++ Guzheng/Guzheng.ino
@@ -1,10 +1,10 @@
 /* Code for laser guzheng
  * Copyright (C) 2016 Jason Lu
- *
+ *
  * Licensed under the MIT License
  * This code has NO WARRANTY! You are
  * responsible for anything that happens
- */
+ */

 // Port I/O defines
 #define THRESHOLD 700
@@ -14,7 +14,15 @@

 // MIDI property defines
 #define VOLUME 0x7F
-#define DELAY 0
+
+/* Comment out the below to enable a slight delay between reading
+ * each note. This may be necessary because sometimes rapidly reading
+ * analog values can cause strange values. Comment out the below if
+ * you notice anything strange, because this is probably the culprit */
+#define NODELAY
+#ifndef NODELAY
+#define DELAY 10
+#endif

 // MIDI Instrument Array
 #define NUMINSTRUMENTS 6
@@ -315,7 +323,9 @@
       // Hand is gone. Stop the sound
       musicOff(i);
     }
+    #ifndef NODELAY
     // Delay 10 to prevent weird analog readings
     delay(DELAY);
+    #endif
   }
 }


Remove 8bit/12bit swith option Add new functionality for new LED fixture

--- Led_fixture_sec.ino
+++ Led_fixture_sec.ino
@@ -7,58 +7,47 @@
 // 2014.07.24 v. 2.11 - pieliku LED atslegsanu ja parkarst radiators
 // 2014.12.20 v. 2.12 - pielaboju DIMM atzimes +/- uz ekrana, pamainiju on/off/Auto secibu
 // 2014.12.27 v. 3.0 - now 12 bit !!!
+// 2014.12.28 v. 3.1 - add logarithmic values table (0-4096 to 256 steps)
+// 2015.02.08 v. 3.2 - add Neutral White (NWhite), merge Royal Blue chanel (RB.., RB.), change chanel PIN's
+// 2015.02.21 v. 3.3 - fix screen on/off in day/night mode
+// 2016.07.15 v. 3.4 - fix for new controller PCB - change some pins, remove unwanted fn
+// 2016.07.24 v. 3.5 - remove pld code for 8 bit PWM
+// 2016.08.08 v. 3.6 - remap LED color, replace moon to individual chanel, add T5 bulb 230V relays, som fixes

 // ~/Documents/Arduino/! Mani projekti/Led_fixture_12_sec/

-#define TLC       1    // set to 1 if using 12bit LED DIMMing
-#define SERIAL    0    // set to 1 if need debug data serial output
-
 #include "Arduino.h"

 /* aquacontroller PIN

-Digital PIN (8 bit/12 bit)
-1
-2 - Night LED PWM Light / PWM LCD Screen background
-3 - LED / =
-4 - LED / =
-5 - LED / =
-6 - LED / =
-7 - LED Royal Blue / =
-8 - LED Blue / PWM Encoder A
-9 - LED Royal Blue .. / Tlc5940 GSCLK
-10 - LED White / PWM Encoder B
-
-11 - PWM Encoder A / Tlc5940 XLAT
-12 - PWM Encoder B / Tlc5940 BLANC
-
-13 - PWM LCD Screen background / -
-
+Digital PIN
+ 2 - PWM LCD Screen background
+ 3 - T5 DIMM 1-10V 1
+ 4 - T5 DIMM 1-10V 2
+ 8 - PWM Encoder A
+ 9 - Tlc5940 GSCLK
+10 - PWM Encoder B
+11 - Tlc5940 XLAT
+12 - Tlc5940 BLANC
 20 - I2C SDA
 21 - I2C SCL
-
 23 - Keyboard cols 1
 25 - Keyboard cols 2
 26 - Keyboard cols 3
 27 - Keyboard rows 1
-28 - 1-Wire Datas Thermometer
-29 - Keyboard rows 2
-
-30 - Fan on/off
-
 31 - LCD SI (28)
 33 - LCD CLK (29)
 35 - LCD CSB (38)
 37 - LCD RS (39)
-
-51 - / Tlc5940 SIN
-52 - / Tlc5940 SCLK
+39 - 1-Wire Datas Thermometer
+47 - Keyboard rows 2
+48 - relay 1
+49 - FAN on/off
+50 - relay 2
+51 - Tlc5940 SIN
+52 - Tlc5940 SCLK

 Analog PIN
-3 - Current Sensor 1
-4 - Current Sensor 2
-14 - Voltage sensor 1
-15 - voltage sensor 2
 */

@@ -72,16 +61,13 @@
 // *********************************************************************************************

 // I started to add 12-bit PWM functionality
-// nothing worked properly yet
-#if TLC
   #include "Tlc5940.h"
-#endif

 // *********************************************************************************************
 //            Temperature
 // *********************************************************************************************
-#include <OneWire.h>
-OneWire ds(28);
+#include "OneWire.h"
+OneWire ds(39); //for timer

 float temp[]={0,0,0}; // max 3 temperature peobes: Heatsink, Power Supply, reserved
 int temp_counter=0;
@@ -89,48 +75,10 @@
 int temperature_mode=0; // temp screen modes 0-hide, 1-show [1] 10,2

 // *********************************************************************************************
-//            Voltage values
-// *********************************************************************************************
-// variables for input pin and control LED
-
-
-  float vout = 0.0;
-  float vin = 0.0;
-  float R1 = 1000000.0;    // !! resistance of R1 !!
-  float R2 = 100000.0;     // !! resistance of R2 !!
-
-  float volt[]={24,48}; // get nominal default
-
-  int volt_sensot_PIN[] ={15,14};
-  int volt_sensor_value = 0;
-
-// For Current sensor
-
-int A1_pin=3;
-int A2_pin=4;
-
-int currentSens1=0;
-int currentSens2=0;
-
-int CurrentValue1=0;
-int CurrentValue2=0;
-float amps1=0;
-float amps2=0;
-
-
-// *********************************************************************************************
 //            Rotary encoder
 // *********************************************************************************************
-// A -> pin 11 (need PWM)
-// B -> pin 12 (need PWM)
 #include <QuadEncoder.h>
-
-#if TLC
-  QuadEncoder qe(8,10); //11, 12
-#else
-  QuadEncoder qe(11,12);
-#endif
-
+QuadEncoder qe(8,10); //10,8
 int qe1Move=0; // rotary encoder last values

@@ -147,7 +95,7 @@
 };

 byte rowPins[ROWS] = {27, 29 };         // Connect keypad rows.
-byte colPins[COLS] = {23, 25, 26 };     // Connect keypad columns.
+byte colPins[COLS] = {23, 25, 47 };     // Connect keypad columns. //28

 // Create the Keypad
 Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
@@ -173,47 +121,47 @@

 int flash_timer=0;

-// koordinates laika un datuma iestadisanai
+// koordinates uz ekrama mainigiem iestadisanai
 int date_line[]={ 1, 1, 1, 2, 2, 2};
 int date_pos[]= { 4, 7,10, 3, 8,11};

 int timer_line[]={ 1, 1, 1, 1, 2};
 int timer_pos[]= { 5, 8,11,14, 8};

-
 int temp_line[]={ 1, 1};
 int temp_pos[]= { 4, 13};

 int overheat_line[]={ 1, 1};
 int overheat_pos[]= { 5, 13};

-
 int cursor_pos=0; // kura pozicija atrodas kursots

-// ventilatora izvads
-int pinFAN = 30;
-int fan_on=0; //ReadEEPROM(9);
-int fan_off=0; //ReadEEPROM(9);
+int pinFAN = 49; // ventilatora izvads
+int fan_on=0; // ReadEEPROM(9);
+int fan_off=0; // ReadEEPROM(9);
 int FAN_status=0; // 0-off, 1-on
 int fan_warning=0; // heatsink temperature warning, -50% light power
 int fan_alert=0; // heatsink temperature alert, power off all LEDs

+int pinRelay1 = 48; // relay for T5 electronic balast
+int pinRelay2 = 50; // relay for T5 electronic balast
+
 // koordinates screen saver rezima LED knalu statusiem,
-// kad visi uzreiz uz ekr'na
-int LED_line[]={ 1, 1, 1, 1, 2, 2, 2, 2};
-int LED_pos[]= { 1, 5, 9,13, 1, 5, 9,13};
+// kad visi uzreiz uz ekrana
+int LED_line[]={ 1, 1, 1, 1, 2, 2, 2, 2, 3, 3};
+int LED_pos[]= { 1, 5, 9,13, 1, 5, 9,13, 1, 9};
 // koordinates uz ekrana bar attelosahani
 int dimm_pos[]= {0,0,8,8};
 int dimm_line[]={1,2,1,2};
-
+int i_counter; // chanel modification counter

 // gaismas taimeri
-int on_h[]=  {15,18,15,18, 0, 1, 2, 3};
-int on_m[]=  { 0, 0, 0, 0, 0, 0, 0, 0};
-int off_h[]= {23,20,23,20, 1, 2, 3, 4};
-int off_m[]= { 0, 0, 0, 0, 0, 0, 0, 0};
+int on_h[]=  {15,18,15,18, 0, 1, 2, 3, 0, 0,0};
+int on_m[]=  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0};
+int off_h[]= {23,20,23,20, 1, 2, 3, 4, 0, 0,0};
+int off_m[]= { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0};
 // sunset taimeri
-int sunset[]={10,10,10,10,10,10,10,10};
+int sunset[]={10,10,10,10,10,10,10,10,10,10,0};

 // *********************************************************************************************
@@ -230,11 +178,12 @@
 byte     pro1[8] = {  B00000,  B11000,  B11000,  B11000,  B11000,  B11000,  B00000}; // |.
 byte     pro2[8] = {  B00011,  B00011,  B00011,  B00011,  B00011,  B00011,  B00011}; // .|
 byte    proto[8] = {  B11111,  B11111,  B11111,  B11111,  B11111,  B11111,  B11111}; //|||
+// small box with Char
 byte       l1[8] = {  B11111,  B11011,  B10101,  B10101,  B10001,  B10101,  B11111}; //A
 byte       l2[8] = {  B11111,  B10011,  B10101,  B10011,  B10101,  B10011,  B11111}; //B
 byte       l3[8] = {  B11111,  B11011,  B10101,  B10111,  B10101,  B11011,  B11111}; //C
 byte       l4[8] = {  B11111,  B10011,  B10101,  B10101,  B10101,  B10011,  B11111}; //D
-
+// small box with Char
 byte       l5[8] = {  B11111,  B10001,  B10111,  B10011,  B10111,  B10001,  B11111}; //E
 byte       l6[8] = {  B11111,  B10001,  B10111,  B10011,  B10111,  B10111,  B11111}; //F
 byte       l7[8] = {  B11111,  B11001,  B10111,  B10101,  B10101,  B11001,  B11111}; //G
@@ -246,7 +195,6 @@
 byte      pr2[8] = {  B00011,  B00011,  B11011,  B11011,  B00011,  B00011,  B00000}; // .|

-
 // *********************************************************************************************
 //            Mani mainigie
 // *********************************************************************************************
@@ -254,7 +202,7 @@
 int interval = 100;// interval at which to blink (milliseconds)
 long previousMillis = 0;        // will store last time Data was updated

-long interval2 = 1000; // intervals taimeru darbibai
+long interval2 = 900; // intervals taimeru darbibai
 long previousMillis2 = 0;
 unsigned long currentMillis=0; //timers
 int null=0;
@@ -263,25 +211,26 @@
 char* menu_text[] ={
   "LED A",         //1
   "LED B",         //2
-  "LED Moon",      //3
+  "T5 Lamp",      //3
   "Fan Control",   //4
   "LED Control",   //5
   "Date/Time",     //6
-  "Manual mode",   //7
+  "Total Power",   //7

   "White",         //8
-  "Royal Blue..", //9
-  "Blue", // 10
-  "Royal Blue.", //11
-  "Green", //12
-  "UV", //13
-  "Red", //14
-  "Royal Blue", //15
-
-  "Reserved" // 16
+  "Violet", //9
+  "Royal Blue", // 10
+  "Blue", //11
+  "Cyan", //12
+  "Red", //13
+  "Amber", //14
+  "Moon", //15
+
+  "T5 Actinic", // 16
+  "T5 Azure" // 17
 };

-int menu_id[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
+int menu_id[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};

 int menu_pos=0;
 int menu_old=-1;
@@ -301,8 +250,9 @@
 char key;

 int lcd_max=255; // max LCD bright
-int lcd_min=50;  // min (darknes) :CD bright -> go to screen slip mode
-
+int lcd_min=5;  // min (darknes) :CD bright -> go to screen slip mode
+int moon_active=0; // 1 active/0 unactive
+int moon_active_temp=-1;

 // DIMM kanalu mainigie
@@ -313,43 +263,35 @@

-#if TLC
-  int DIMM_pin[]=   {  4,  5,  7,  8, 10, 13, 14, 11, 2 };
-  const unsigned int PWMTable[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,
-17,18,19,20,21,22,23,24,25,26,27,28,29,
-30,31,32,33,34,35,36,37,38,39,40,41,42,
-43,44,45,46,47,48,49,50,51,52,53,54,55,
-56,57,58,59,60,61,62,63,64,65,66,68,70,
-72,74,76,78,80,82,84,86,88,90,92,94,96,
-98,100,102,104,106,108,111,114,117,120,
-123,126,129,132,135,138,141,144,147,150,
-153,157,161,165,169,173,177,181,185,189,
-193,197,201,206,211,216,221,226,231,237,
-243,249,255,261,267,273,279,285,292,299,
-306,313,320,327,335,343,351,359,367,375,
-384,393,402,412,422,432,442,452,462,473,
-484,495,507,519,531,543,555,567,580,593,
-606,620,634,648,663,678,693,709,725,741,
-758,775,792,810,829,848,868,888,908,929,
-950,971,993,1015,1038,1061,1085,1109,1134,
-1160,1186,1213,1240,1268,1297,1326,1356,
-1387,1418,1450,1483,1517,1551,1586,1622,
-1659,1697,1736,1775,1815,1856,1898,1941,
-1985,2030,2076,2123,2171,2220,2270,2321,
-2374,2427,2480,2533,2586,2639,2692,2745,
-2798,2851,2904,2957,3010,3063,3116,3169,
-3223,3277,3331,3385,3440,3495,3550,3605,
-3660,3716,3772,3828,3884,3937,3990,4095};
-#else
-  int DIMM_pin[]=   { 10,  9,  8,  7,  6,  5,  4,  3,  2 };
-#endif
-
-
-int DIMM_value[]=   { 76,128,220,150, 20,100,200, 36,128 };
-int DIMM_actual[]=  {  0,  0,  0,  0,  0,  0,  0,  0,128 };
-int DIMM_temp[]=    { -1, -1, -1, -1, -1, -1, -1, -1, -1 };
-int sunset_actual[]={  0,  0,  0,  0,  0,  0,  0,  0,  0 };
-int DIMM_status[]=  {  0,  0,  0,  0,  0,  0,  0,  0,  0 };
+
+
+//                    W   V  RB   B   C   R   A   M               %
+  int DIMM_pin[]=   {10, 14, 11,  7,  4,  5,  8, 13,  4,  3,  0,  0};
+                                                    // 8, 9 PWM 8bit, 10 % of light
+  const int PWMTable[] = {
+   0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,  13,  14,  15,
+  16,  17,  18,  19,  20,  21,  22,  23,  24,  25,  26,  27,  28,  29,  30,  31,
+  32,  33,  34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  46,  47,
+  48,  49,  50,  51,  52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,  63,
+  64,  65,  66,  68,  70,  72,  74,  76,  78,  80,  82,  84,  86,  88,  90,  92,
+  94,  96,  98, 100, 102, 104, 106, 108, 111, 114, 117, 120, 123, 126, 129, 132,
+ 135, 138, 141, 144, 147, 150, 153, 157, 161, 165, 169, 173, 177, 181, 185, 189,
+ 193, 197, 201, 206, 211, 216, 221, 226, 231, 237, 243, 249, 255, 261, 267, 273,
+ 279, 285, 292, 299, 306, 313, 320, 327, 335, 343, 351, 359, 367, 375, 384, 393,
+ 402, 412, 422, 432, 442, 452, 462, 473, 484, 495, 507, 519, 531, 543, 555, 567,
+ 580, 593, 606, 620, 634, 648, 663, 678, 693, 709, 725, 741, 758, 775, 792, 810,
+ 829, 848, 868, 888, 908, 929, 950, 971, 993,1015,1038,1061,1085,1109,1134,1160,
+1186,1213,1240,1268,1297,1326,1356,1387,1418,1450,1483,1517,1551,1586,1622,1659,
+1697,1736,1775,1815,1856,1898,1941,1985,2030,2076,2123,2171,2220,2270,2321,2374,
+2427,2480,2533,2586,2639,2692,2745,2798,2851,2904,2957,3010,3063,3116,3169,3223,
+3277,3331,3385,3440,3495,3550,3605,3660,3716,3772,3828,3884,3937,3990,4040,4095};
+
+int DIMM_value[]=   {  4,  4,  4,  4,  4,  4,  4,  4,  4,  4,  0, 0 };
+int DIMM_actual[]=  {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 0 };
+int DIMM_old[]=     { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0 };
+int DIMM_temp[]=    { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0 };
+int sunset_actual[]={  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 0 };
+int DIMM_status[]=  {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 0 };

@@ -357,14 +299,16 @@
 // kanalu krasas nosaukums
 char* DIMM_text[] ={
   "White",        //1
-  "RB ..", //2
-  "Blue",        //3
-  "RB .",         //4
-  "Green",    //5
-  "UV",
+  "Violet", //2
+  "Royal Blue",        //3
+  "Blue",     //4
+  "Cyan",    //5
   "Red",
-  "RB",
-  "LED Moon"
+  "Amber",
+  "Moon",
+  "RB Moon",
+  "T5 Actinic",
+  "T5 Azure"
 };

@@ -372,6 +316,7 @@
 int DIMM_active=0;
 int DIMM_increment_B=8.5;     //solis liela grafika dimmesanai
 int DIMM_increment_S=18.2;    //solis mazaa grafika dimmesanai
+int DIMM_increment_P=3.3;    //solis procentu (100) grafika dimmesanai
 int DIMM_increment=0;         // tekoshais solis
 int cha=0; // tekoshais kanaals reguleeshana

@@ -390,24 +335,20 @@

 void setup() {
   Wire.begin(); // Establece la velocidad de datos del bus I2C
-  #if SERIAL
-    Serial.begin(9600);
-    Serial.println('Serial begin');
-  #endif
-
-#if TLC
+
+    // Serial.begin(9600);
+    // Serial.println('Serial begin');
   Tlc.init();
-#endif
-
-
-

 // pin modes
   pinMode(pinLCD, OUTPUT);      // LCD screen background
   pinMode(pinFAN, OUTPUT);      // FAN on/off
+  pinMode(pinRelay1, OUTPUT);      // Relay 1 on/off
+  pinMode(pinRelay2, OUTPUT);      // Relay 2 on/off
+

   // set up the LCD
-  lcd.begin(DOG_LCD_M163, 0x28); // contrast from 0x1A to 0x28
+  lcd.begin(DOG_LCD_M163, 0x1F); // contrast from 0x1A to 0x28
   analogWrite(pinLCD, lcd_max);  // set LCD display background light to maximum

   // create custom char
@@ -431,13 +372,14 @@
   RTC.start();

   // load chanel data
-  for (int i=0; i<=8; i++){ //0-7 LED, 8 - moon led
+  for (int i=0; i<=10; i++){ //0-7 LED, 8,9 T5, 10 - percent,
     ReadEEPROM(i);
     pinMode(DIMM_pin[i], OUTPUT);
   }
-  ReadEEPROM(9); // load fan temperature data
-  ReadEEPROM(10); // load overheat temperature data
+  ReadEEPROM(11); // load fan temperature data
+  ReadEEPROM(12); // load overheat temperature data
   SetMenu();
+  i_counter=0;

 }
 // *********************************************************************************************
@@ -450,22 +392,12 @@
   // encoder
   qe1Move=qe.tick();

-   #if SERIAL
-     if (qe1Move=='<' || qe1Move=='>') {
-       Serial.println(qe1Move);
-     }
-   #endif
-
-
-  // keypad
+ // keypad
   key = kpd.getKey();
   Button = ' ';
   if(key) { // same as if (key != NO_KEY)
     Button=key;
     timeout=0;
-   #if SERIAL
-     Serial.println(Button);
-   #endif
   }
   // rotary encoder
   if (qe1Move=='>') timeout=0;
@@ -489,12 +421,10 @@
     menu_mode=0;
     flash=2;
     lcd.clear();
-   // lcd.setCursor(4, 0);
-   // lcd.print("Reef LED");
     analogWrite(pinLCD, lcd_min);
   }

-  if (Button=='2') { // manual modes
+  if (Button=='2') { // on/off/auto light
       manual_on--;
       if (manual_on<0) manual_on=2;
       manual_modes_show();
@@ -522,18 +452,17 @@
             temperature_mode=3;
             DIMM_Init();
           }
-          if (menu_mode==3) {// moon light
-            SetBar();
-            DimmingBIGStart();
+          if (menu_mode==3) {// T5
+            Set2();
+            cha_incr=8;
             temperature_mode=3;
-            cursor_pos=0;
+            DIMM_Init();
           }

           if (menu_mode==4) { // temperature settup
             lcd.setCursor(0, 0);
             lcd.print(flash_txt);
-
             temperature_mode=1;
             cursor_pos=0;
               // print mode screen
@@ -552,7 +481,6 @@
           if (menu_mode==5) { // LED overheating  settup
             lcd.setCursor(0, 0);
             lcd.print(flash_txt);
-
             temperature_mode=1;
             cursor_pos=0;
               // print mode screen
@@ -567,10 +495,6 @@
               lcd.setCursor(1, 2);
               lcd.print("Current: ");
           }
-
-
-
-
           if (menu_mode==6) { // date/time
             lcd.setCursor(0, 0);
             lcd.print(flash_txt);
@@ -578,28 +502,33 @@
             cursor_pos=0;
             printTimeOnly();
           }
-
-          if (menu_mode>=8 && menu_mode<=15) {
+          if (menu_mode==7) {// manual mode
+            SetBar();
+            DimmingBIGStartP();
+            temperature_mode=3;
+            cursor_pos=0;
+          }
+          if (menu_mode>=8 && menu_mode<=17) {
             SetBar();
             temperature_mode=3;
             DimmingBIGStart();
             cursor_pos=0;
           }
         }
-    } else if (menu_mode==-2) { // screen saver
+    } else if (menu_mode==-2) {                               // screen saver
       // nope
-    } else if (menu_mode==1 || menu_mode==2) {                 // dimming main color menu
+    } else if (menu_mode==1 || menu_mode==2 || menu_mode==3) {// dimming main color menu
       Dimming();
-    } else if (menu_mode==3) {                // LED Moon settup
-        cha=8;
-        Dimming_big();
-    } else if (menu_mode==4) {                                 // set Fan setting
+    } else if (menu_mode==4) {                                // set Fan setting
       SetTemp();
-    } else if (menu_mode==5) {                                 // set overheat temperatures
+    } else if (menu_mode==5) {                                // set overheat temperatures
       SetOverheat();
-    } else if (menu_mode==6) {                                 // set date/time mode
+    } else if (menu_mode==6) {                                // set date/time mode
       SetDateTime();
-    } else if (menu_mode>=8 || menu_mode<=15) {                // individual chanel setup
+    } else if (menu_mode==7) {                                // set manual mode
+        cha=10;
+        Dimming_big_percent();
+    } else if (menu_mode>=8 || menu_mode<=17) {               // individual chanel setup
         cha=menu_mode-8;
         Dimming_big();
     } else {
@@ -611,8 +540,24 @@
     flash=2;
     menu_mode=-2;
     lcd.clear();
-    analogWrite(pinLCD, lcd_min);
     SetBar();
+    if (moon_active==0) {
+      analogWrite(pinLCD, lcd_min);
+    } else {
+      analogWrite(pinLCD, 0);
+    }
+
+  }
+
+  if (moon_active_temp!=moon_active) {
+    if (flash==2) {
+      moon_active_temp=moon_active;
+      if (moon_active==0) {
+        analogWrite(pinLCD, lcd_min);
+      } else {
+        analogWrite(pinLCD, 0);
+      }
+    }
   }

@@ -627,14 +572,23 @@
 // the procedures to each cycle
   if(currentMillis - previousMillis2 > interval2) {
     previousMillis2 = currentMillis;
-    Watch(); // light timers
+
+      if (manual_on==2) { Watch(); }   // Auto
+      if (manual_on==0) { WatchOff(); }                // off
+      if (manual_on==1) { WatchOn(); }    // on
+
+
+
     Termo(); // temperature
-    Voltage(); // voltage + current from power suply
     PrintStatus(); // show status un screen
   }
-
-
-
+ /*
+  i_counter++;
+  if (i_counter>9) {
+    i_counter=0;
+  }
+    Watch(i_counter); // light timers
+*/

 }

@@ -680,7 +634,7 @@
   lcd.createChar(6, l3);
   lcd.createChar(7, l4);
   lcd.home();
- SetBar();
+  SetBar();

 }

@@ -712,7 +666,6 @@
 // *********************************************************************************************
 //            MENU
 // *********************************************************************************************
-

 void Menu(){ // ja menu ir 0 tad sheit parsledzam ar enkoderu menu poziciju
   if (qe1Move=='>') {
@@ -733,7 +686,6 @@
 //            Show Menu
 // *********************************************************************************************

-
 void ShowMenu(){
   if (menu_pos!=menu_old){
     flash_line=1;
@@ -746,6 +698,8 @@
     flash_pos=(16-flash_txt.length())/2;
     menu_old=menu_pos;
     flash=1;
+    // add 2015-02-13
+    temperature_mode=0;
   }
 }

@@ -756,8 +710,6 @@
   int d2=a/2;
   d=1+(16-(a/2))/2;
   d=d-1;
-
-
   for (int i=0; i<= d2; i++){
     lcd.setCursor(d+i, 2);
     lcd.write(null);
@@ -769,7 +721,7 @@
     }
     else {
       lcd.write(2);
-    } //2
+    }
   }

@@ -799,7 +751,7 @@

       if (menu_mode==1 || menu_mode==2) {
         lcd.write(cha+4);
-      } else if (menu_mode>=8 && menu_mode<=15) {
+      } else if (menu_mode>=7 && menu_mode<=15) {
         if (cursor_pos==0){
           lcd.write(3);
         } else {
@@ -814,7 +766,7 @@
       if (flash_stat>4) flash_stat=0;
     }
   }
-  if (flash==2){ // iesl'dzas screensacer
+  if (flash==2){ // iesledzas screensacer
     //printTime();
   }

@@ -856,7 +808,7 @@

 void SaveEEPROM(int a){
-  if (a<=7){ // save LED chanel data
+  if (a<=9){ // save LED chanel data + T5
     EEPROM.write((a*10), on_h[a]);
     EEPROM.write((1+a*10), on_m[a]);
     EEPROM.write((2+a*10), off_h[a]);
@@ -864,21 +816,21 @@
     EEPROM.write((4+a*10), sunset[a]);
     EEPROM.write((5+a*10), DIMM_value[a]);
   }
-  if (a==8){// save moon light data
-    EEPROM.write(80, DIMM_value[a]);
-  }
-  if (a==9){// save fan data
-    EEPROM.write(81,fan_on);
-    EEPROM.write(82,fan_off);
-  }
-  if (a==10){// save overheat data
-    EEPROM.write(83,fan_warning);
-    EEPROM.write(84,fan_alert);
+  if (a==10){// save moon light data
+    EEPROM.write(180, DIMM_value[a]);
+  }
+  if (a==11){// save fan data
+    EEPROM.write(181,fan_on);
+    EEPROM.write(182,fan_off);
+  }
+  if (a==12){// save overheat data
+    EEPROM.write(183,fan_warning);
+    EEPROM.write(184,fan_alert);
   }
 }

 void ReadEEPROM(int a){
-  if (a<=7){ // load LED chanel data
+  if (a<=9){ // load LED chanel data
     on_h[a] = EEPROM.read(a*10);
     on_m[a] = EEPROM.read(1+a*10);
     off_h[a] = EEPROM.read(2+a*10);
@@ -886,16 +838,16 @@
     sunset[a] = EEPROM.read(4+a*10);
     DIMM_value[a] = EEPROM.read(5+a*10);
   }
-  if (a==8){// load moon light data
-    DIMM_value[a] = EEPROM.read(80);
-  }
-  if (a==9){// load fan settings
-    fan_on = EEPROM.read(81);
-    fan_off = EEPROM.read(82);
-  }
-  if (a==10){// load overheat settings
-    fan_warning = EEPROM.read(83);
-    fan_alert = EEPROM.read(84);
+  if (a==10){// load moon light data
+    DIMM_value[a] = EEPROM.read(180);
+  }
+  if (a==11){// load fan settings
+    fan_on = EEPROM.read(181);
+    fan_off = EEPROM.read(182);
+  }
+  if (a==12){// load overheat settings
+    fan_warning = EEPROM.read(183);
+    fan_alert = EEPROM.read(184);
   }

 }
@@ -978,7 +930,7 @@
     break;
   case 2:
     // save "Overheat"
-    SaveEEPROM(10);
+    SaveEEPROM(12);
     menu_old=-1;
     menu_mode=0;
     lcd.clear();
@@ -1030,6 +982,7 @@
 // *********************************************************************************************
 //            SetDateTime - datuma un laika iestadisana
 // *********************************************************************************************
+
 void SetDateTime(){
   switch (cursor_pos) {
     case 0:
@@ -1061,7 +1014,6 @@
       RTC.set(DS1307_DATE,monthDay);     //set the date
       RTC.set(DS1307_MTH,month);         //set the month
       RTC.set(DS1307_YR,(year-2000));    //set the year
-
       RTC.start();
       // end
       menu_old=-1;
@@ -1150,7 +1102,7 @@
       lcd.write(4+i);
       BarS(DIMM_value[cha_incr+i],dimm_pos[i]+1,dimm_line[i]);
       DIMM_temp[cha_incr+i]=DIMM_value[cha_incr+i];
-      aWrite(DIMM_pin[cha_incr+i], DIMM_value[cha_incr+i]);
+      +(DIMM_pin[cha_incr+i], DIMM_value[cha_incr+i],cha_incr+i);
     }
   }
 }
@@ -1158,15 +1110,15 @@
 // *********************************************************************************************
 //            Zimejam LIELO BAR
 // *********************************************************************************************
-void BarL(int a) {// a cik
+void BarL(int a) {// a cik/vertiba
   int a_interpolating=a/8.5;
-  int b=1;
-  int c=1;
+  int b=1; // position on line
+  int c=1; // line on screen
   a_interpolating=a_interpolating+1;
   int d;
   d=a_interpolating/2;
   d=d-1;
-
+  float p;

   for (int i=0; i<= d-1; i++){
     lcd.setCursor(b+i, c);
@@ -1190,14 +1142,61 @@

   if (menu_mode!=3) {
+    lcd.setCursor(8, 2);
+    lcd.print("        ");
+    lcd.setCursor(8, 2);
+    //lcd.print("TLS ");
+    //lcd.print(PWMTable[a]);
+    p=(float(PWMTable[a])/4095)*100;
+    lcd.print("% ");
+    lcd.print(p);
+  }
+
+}
+
+// *********************************************************************************************
+//            Zimejam LIELO BAR 100%
+// *********************************************************************************************
+void BarP(int a) {// a cik/vertiba
+  int a_interpolating=a/3.3;
+  int b=1; // position on line
+  int c=1; // line on screen
+  a_interpolating=a_interpolating+1;
+  int d;
+  d=a_interpolating/2;
+  d=d-1;
+  float p;
+
+  for (int i=0; i<= d-1; i++){
+    lcd.setCursor(b+i, c);
+    lcd.write(null);
+  }
+  if (b+d!=b-1) {
+    lcd.setCursor(b+d, c);
+    if ( (a_interpolating % 2) == 0) {
+      lcd.write(1);
+    }
+    else {
+      lcd.write(null);
+    } //2
+  }
+
+  if (b+d+1!=b+15) { // 7 cik zimigas pozicijas aiznjem BAR
+    lcd.setCursor(b+d+1, c);
+    lcd.write(" ");
+  }
+
+
+
+  if (menu_mode!=3) {
+    lcd.setCursor(8, 2);
+    lcd.print("        ");
     lcd.setCursor(10, 2);
-    lcd.print("      ");
-    lcd.setCursor(10, 2);
-    lcd.print(a/5.6);
-    lcd.print("W");
-  }
-}
-
+    lcd.print("% ");
+    lcd.print(a);
+  }
+
+}

 // *********************************************************************************************
@@ -1234,12 +1233,10 @@
 // *********************************************************************************************
 void DIMM_Init(){
   cha=0;
-
   lcd.setCursor(0, 0);
-  lcd.print(menu_text[menu_mode-1]);
-
-  lcd.setCursor(5, 0);
-  lcd.write(":");
+//  lcd.print(menu_text[menu_mode-1]);
+//  lcd.setCursor(5, 0);
+//  lcd.write(":");
   lcd.write(DIMM_text[cha_incr+cha]);

   lcd.setCursor(12, 0);
@@ -1266,7 +1263,7 @@

   DIMM_increment=DIMM_increment_B;

-  for (int i=0; i<= 8; i++){ // clear tmporary data, 8 Moon chanel
+  for (int i=0; i<= 10; i++){ // clear tmporary data, 8,9 - T5, 10 Moon chanel
     DIMM_temp[i]=-1;
   }
   // print local menu position
@@ -1278,6 +1275,25 @@

 }

+void DimmingBIGStartP(){
+  lcd.setCursor(0, 0);
+  lcd.print(menu_text[menu_mode-1]);
+
+  lcd.setCursor(0, 2);
+  lcd.write(char_big_step);
+
+  DIMM_increment=DIMM_increment_P;
+  DIMM_temp[10]=-1;
+  // print local menu position
+  if (menu_mode!=3) {
+    lcd.setCursor(14, 0);
+    lcd.write(3);
+    lcd.print(".");
+  }
+
+}
+
+
 // *********************************************************************************************
 //            Darbs ar mazo BAR
 // *********************************************************************************************
@@ -1286,14 +1302,7 @@
   if (Button=='a') {   // ENCODER BUTTON
     lcd.setCursor(dimm_pos[cha], dimm_line[cha]);
     lcd.write(cha+4);
-    // rakstam krasas nosaukumu
-    lcd.setCursor(6, 0);
-    lcd.write("     ");
-    lcd.setCursor(6, 0);
-    lcd.write(DIMM_text[cha_incr+cha+1]);
-
     SaveEEPROM(cha_incr+cha);
-
     cha++;
     if (cha>=4) {
       menu_old=-1;
@@ -1303,7 +1312,13 @@
       SetMenu();
       lcd.clear();
       ShowMenu();
-    }
+    } else {
+      // rakstam krasas nosaukumu
+      lcd.setCursor(0, 0); // 6, 0
+      lcd.write("            ");
+      lcd.setCursor(0, 0);
+      lcd.write(DIMM_text[cha_incr+cha]);
+    }
   }

   if (Button=='3') { // fine tuning on/off
@@ -1323,12 +1338,14 @@
     if (DIMM_value[cha_incr+cha]>255) {
       DIMM_value[cha_incr+cha]=255;
     }
+    aWrite(DIMM_pin[cha_incr+cha], DIMM_value[cha_incr+cha], cha_incr+cha);
   }
   else if (qe1Move=='<') {
     DIMM_value[cha_incr+cha]=DIMM_value[cha_incr+cha]-DIMM_increment;
     if (DIMM_value[cha_incr+cha]<0) {
       DIMM_value[cha_incr+cha]=0;
-    }
+    }
+    aWrite(DIMM_pin[cha_incr+cha], DIMM_value[cha_incr+cha], cha_incr+cha);
   }

   if (cha<4) {
@@ -1354,7 +1371,7 @@

   if (Button=='a') {   // ENCODER BUTTON
     cursor_pos++;
-    if (menu_mode==3) { // it kaa prueksh moon light ieprieks atslegsana
+    if (menu_mode==7) { // it kaa prieksh moon light ieprieks atslegsana
      cursor_pos=6;
     } else {
       if (cursor_pos>0) {
@@ -1504,7 +1521,7 @@
           flash_txt=toDouble(off_m[cha]);
           break;
         case 5:
-          sunset[cha]=sunset[cha]-5;
+          sunset[cha]=sunset[cha]-1;
           if (sunset[cha]<0) sunset[cha]=60;
            flash_txt=toDouble(sunset[cha]);
           break;
@@ -1515,7 +1532,7 @@
       if (DIMM_value[cha]!=DIMM_temp[cha]){
         BarL(DIMM_value[cha]);
         DIMM_temp[cha]=DIMM_value[cha];
-        aWrite(DIMM_pin[cha], DIMM_value[cha]);
+        aWrite(DIMM_pin[cha], DIMM_value[cha],cha);
       }
       lcd.setCursor(1, 2);
       lcd.print(toTriple(DIMM_value[cha]));
@@ -1531,6 +1548,81 @@

 // *********************************************************************************************
+//            Darbs ar LIEL0 BAR 100%
+// *********************************************************************************************
+
+void Dimming_big_percent(){
+
+  if (Button=='a') {   // ENCODER BUTTON
+    cursor_pos++;
+    if (cursor_pos>=1) {
+      SaveEEPROM(cha);
+      menu_old=-1;
+      menu_mode=0;
+      lcd.clear();
+      SetMenu();
+      ShowMenu();
+    }
+  }
+
+    if (cursor_pos==0) { // set LED level with bar
+      if (Button=='3') { // fine tunning on/off
+        lcd.setCursor(0, 2);
+        if (DIMM_increment==1) {
+          DIMM_increment=DIMM_increment_P;
+          lcd.write(char_big_step);
+        }
+        else {
+          DIMM_increment=1;
+          lcd.write(char_small_step);
+        }
+      }
+    }
+    if (qe1Move=='>') {
+          DIMM_value[cha]=DIMM_value[cha]+DIMM_increment;
+          if (DIMM_value[cha]>100) {
+            DIMM_value[cha]=100;
+          }
+    }
+    else if (qe1Move=='<') {
+          DIMM_value[cha]=DIMM_value[cha]-DIMM_increment;
+          if (DIMM_value[cha]<0) {
+            DIMM_value[cha]=0;
+          }
+    }
+
+    if (cursor_pos==0) {
+      if (DIMM_value[cha]!=DIMM_temp[cha]){
+        BarP(DIMM_value[cha]);
+        DIMM_temp[cha]=DIMM_value[cha];
+        aWrite(DIMM_pin[cha], DIMM_value[cha],cha);
+      }
+      lcd.setCursor(1, 2);
+      lcd.print(toTriple(DIMM_value[cha]));
+
+// reset TLC
+DIMM_old[0]=-1;
+DIMM_old[1]=-1;
+DIMM_old[2]=-1;
+DIMM_old[3]=-1;
+DIMM_old[4]=-1;
+DIMM_old[5]=-1;
+DIMM_old[6]=-1;
+DIMM_old[7]=-1;
+
+      flash_pos=0;
+      flash_line=1;
+      flash_txt=" "; //String(cha+4);
+      flash=1;
+    }
+
+  // end void
+}
+
+
+
+
+// *********************************************************************************************
 //            LED kanalu Taimeru darbibas
 // *********************************************************************************************

@@ -1542,45 +1634,42 @@

 // for internal
   long DIMM_long;
-
   float tmp;

-  //int out;
+//int out;
   int actual_led;
-  int now_mode=0; // 0 - normal, 1 sun Up, 2 sun Down fpr indicate sunset/sundown
-
+  int now_mode=0; // 0 - normal, 1 sun Up, 2 sun Down for indicate sunset/sundown

   hour2 = RTC.get(DS1307_HR,true);
   minute2 = RTC.get(DS1307_MIN,false);
   second2 = RTC.get(DS1307_SEC,false);
-  now_sec=((long(hour2)*3600)+(long(minute2)*60))+long(second2); // cout seconds
-
+  now_sec=((long(hour2)*3600)+(long(minute2)*60))+long(second2); // count seconds
+
+// Serial.print("> ");
+
   // for all defined timer
-  for (int i=0; i<=7; i++){
-    // init for calcultion
+  for (int i=0; i<=9; i++){
+
+    // init for calculation
     on_sec=(long(on_h[i])*3600)+(long(on_m[i])*60);
     off_sec=(long(off_h[i])*3600)+(long(off_m[i])*60);
     tmp_sunset=long(sunset[i])*60;
     DIMM_long=long(DIMM_value[i]);
-
-
-// normal situation - time_on < to time_off
+//**********************************************************************************************
+// normal situation - time_on < time_off
       if (on_sec<off_sec) {
-
-// light on
+          // light on
           if (now_sec>=on_sec && now_sec<=off_sec){
             DIMM_actual[i]=(int) DIMM_long;
             now_mode=0;
-
-// normals sunset +
+          // normals sunset +
             if (now_sec<=(on_sec+tmp_sunset)){
                 tmp=(((float)DIMM_long/(float)tmp_sunset)*(float)((on_sec+tmp_sunset)-now_sec));
                 DIMM_long = DIMM_long -tmp;
                 DIMM_actual[i]=(int) DIMM_long;
                 now_mode=1;
             }
-
- // normals sundown -
+         // normals sundown -
             if (now_sec>=off_sec-tmp_sunset){
                 tmp=((float)DIMM_long/(float)tmp_sunset)*(float)((off_sec-tmp_sunset)-now_sec);
                 tmp=abs(tmp);
@@ -1588,44 +1677,37 @@
                 DIMM_actual[i]=(int) DIMM_long;
                 now_mode=2;
             }
-
-// light off
+        // light off
           } else {
             DIMM_actual[i]=0;
             now_mode=0;
           }
       }
-
 //**********************************************************************************************
 // extra situation - time_on > to time_off
       if (on_sec>off_sec) {
-
-// light off
+          // light off
          if (now_sec>=off_sec && now_sec<on_sec){
-	    DIMM_actual[i]=0;
+	          DIMM_actual[i]=0;
             now_mode=0;
-
-// light on
+          // light on
          } else {
-  	    DIMM_actual[i]=(int) DIMM_long;
-
-// normals sunset
+  	        DIMM_actual[i]=(int) DIMM_long;
+          // normals sunset
             if (now_sec<on_sec+tmp_sunset && now_sec>off_sec){
                  tmp=(((float)DIMM_long/(float)tmp_sunset)*(float)((on_sec+tmp_sunset)-now_sec));
       	         DIMM_long = DIMM_long -(long) tmp;
                  DIMM_actual[i]=(int) DIMM_long;
                  now_mode=1;
               }
-
-// sunsets, kas turpinas pec pusnakts (iesledz 23.55, izsledz 02.00, sunrise 20)
+          // sunsets, kas turpinas pec pusnakts (iesledz 23.55, izsledz 02.00, sunrise 20)
 	      if ((on_sec+tmp_sunset)>86400 && (now_sec-on_sec)<0 && now_sec<(tmp_sunset-(86400-on_sec))){
                   tmp=(((float)DIMM_long/(float)tmp_sunset)*(float)(((on_sec+tmp_sunset)-86400)-now_sec));
       	          DIMM_long = DIMM_long -(long) tmp;
                   DIMM_actual[i]=(int) DIMM_long;
                   now_mode=1;
               }
-
-// normals sundown
+        // normals sundown
 	      if (now_sec>=off_sec-tmp_sunset && now_sec<off_sec){
                   tmp=((float)DIMM_long/(float)tmp_sunset)*(float)((off_sec-tmp_sunset)-now_sec);
                   tmp=abs(tmp);
@@ -1633,8 +1715,7 @@
                   DIMM_actual[i]=(int) DIMM_long;
                   now_mode=2;
               }
-
-// sundowns, kas jasak rekinat pirms pusnakts (iesledz 20.00 , izsledz 00.10 un sunrise 15)
+        // sundowns, kas jasak rekinat pirms pusnakts (iesledz 20.00 , izsledz 00.10 un sunrise 15)
   	      if ((tmp_sunset-off_sec)>0 && (86400-now_sec)<=(tmp_sunset-off_sec)){
                   tmp=((float)DIMM_long/(float)tmp_sunset)*(float)(((off_sec-tmp_sunset)-now_sec)+86400);
                   tmp=abs(tmp);
@@ -1642,60 +1723,149 @@
                   DIMM_actual[i]=(int) DIMM_long;
                   now_mode=2;
               }
-        }
+          }
       }

-      if (manual_on==2) { aWrite(DIMM_pin[i], DIMM_actual[i]); }
-      if (manual_on==0) { aWrite(DIMM_pin[i], 0); }
-      if (manual_on==1) { aWrite(DIMM_pin[i], DIMM_value[i]); }
+      if (manual_on==2) { aWrite(DIMM_pin[i], DIMM_actual[i], i); }   // Auto
+      if (manual_on==0) { aWrite(DIMM_pin[i], 0, i); }                // off
+      if (manual_on==1) { aWrite(DIMM_pin[i], (int) DIMM_value[i], i); }    // on

       if (menu_mode==-2) {
-        lcd.setCursor(LED_pos[i], LED_line[i]);
-        lcd.print(toTriple(DIMM_actual[i]));
+        if (i<8){
+          lcd.setCursor(LED_pos[i], LED_line[i]);
+          lcd.print(toTriple(DIMM_actual[i]));

-        lcd.setCursor(LED_pos[i]-1, LED_line[i]);
-        if (now_mode==0) {
-          lcd.print(" ");
+          lcd.setCursor(LED_pos[i]-1, LED_line[i]);
+
+//          if (now_mode==0) {
+//            if (i==7 && DIMM_actual[i]==0) { // set moon  on chanel 7
+//              lcd.print("m");
+//            } else {
+//              lcd.print(" ");
+//            }
+//          }
+          if (now_mode==1) {
+            lcd.print("+");
+          }
+          if (now_mode==2) {
+            lcd.print("-");
+          }
+        }
+      }
+  } // for
+  // Tlc.update();
+}
+
+// *********************************************************************************************
+//            LED kanalu Izlegsana
+// *********************************************************************************************
+
+void WatchOff(){
+      for (int i=0; i<=7; i++){
+          Tlc.set(DIMM_pin[i], 0);
+          DIMM_old[i]=0;
+      }
+      Tlc.update();
+      analogWrite(DIMM_pin[8],0);
+      digitalWrite(pinRelay1, LOW);
+      analogWrite(DIMM_pin[9],0);
+      digitalWrite(pinRelay2, LOW);
+      DIMM_old[8]=0;
+      DIMM_old[9]=0;
+}
+
+// *********************************************************************************************
+//            LED kanalu Ieslēgsana
+// *********************************************************************************************
+
+void WatchOn(){
+      for (int i=0; i<=7; i++){
+          Tlc.set(DIMM_pin[i], DIMM_value[i]);
+          DIMM_old[i]=DIMM_value[i];
+      }
+      Tlc.update();
+      analogWrite(DIMM_pin[8],DIMM_value[8]);
+      if (DIMM_value[8]==0){
+        digitalWrite(pinRelay1, LOW);
+      } else {
+        digitalWrite(pinRelay1, HIGH);
+      }
+      analogWrite(DIMM_pin[9],DIMM_value[9]);
+      if (DIMM_value[9]==0){
+        digitalWrite(pinRelay2, LOW);
+      } else {
+        digitalWrite(pinRelay2, HIGH);
+      }
+      DIMM_old[8]=DIMM_value[8];
+      DIMM_old[9]=DIMM_value[9];
+}
+
+
+// *********************************************************************************************
+//            LED light analogWrite emulate
+// *********************************************************************************************
+void aWrite (int pin, int value, int chanel){
+  float tmp_value=0;
+  int tmp_percent=DIMM_value[10];
+
+// clear alert status
+lcd.setCursor(11, 0);
+lcd.print(' ');
+
+  if (temp[0]>=fan_warning){ // 50% of LED's power
+    value=value/2;
+lcd.setCursor(11, 0);
+lcd.print('!');
+  }
+
+  if (temp[0]>=fan_alert){ // turn off all LED's
+    value=0;
+lcd.setCursor(11, 0);
+lcd.print('?');
+  }
+
+tmp_value=((float)PWMTable[value]/(float)100)*(float)tmp_percent;
+/*
+if (chanel==0) {
+  lcd.setCursor(0, 0);
+//lcd.print(tmp_value);
+  lcd.print(DIMM_value[chanel]);
+  lcd.setCursor(8, 0);
+  lcd.print(DIMM_actual[chanel]);
+  //tmp_value=(PWMTable[value]/100)*tmp_percent;
+  // tmp_value=PWMTable[value];
+}
+  */
+   //if (DIMM_old[chanel]!=value) {
+      if (chanel<8) {
+          Tlc.set(pin, (int)tmp_value);
+          Tlc.update();
+      }
+   //}
+   DIMM_old[chanel]=value;
+
+    // for T5
+    if (chanel>7) {
+        analogWrite(pin,value);
+
+        if (chanel==8) {
+          analogWrite(pin,value);
+          if (value==0){
+            digitalWrite(pinRelay1, LOW);
+          } else {
+            digitalWrite(pinRelay1, HIGH);
+          }
         }
-        if (now_mode==1) {
-          lcd.print("+");
+        if (chanel==9) {
+          analogWrite(pin,value);
+          if (value==0){
+            digitalWrite(pinRelay2, LOW);
+          } else {
+            digitalWrite(pinRelay2, HIGH);
+          }
         }
-        if (now_mode==2) {
-          lcd.print("-");
-        }
-      }
-
-
-
-  } // for
-
-  #if TLC
-    Tlc.update();
-  #endif
-
-}
-
-
-
-// *********************************************************************************************
-//            LED light analogWrite emulate
-// *********************************************************************************************
-void aWrite (int pin, int value){
- if (temp[0]>=fan_warning){ // 50% of LED's power
-   value=value/2;
- }
-
- if (temp[0]>=fan_alert){ // turn off all LED's
-   value=0;
- }
-
-  #if TLC
-    Tlc.set(pin, PWMTable[value]); //*16);
-    //Tlc.update();
-  #else
-    analogWrite(pin, value);
-  #endif
-
+
+    }
 }

@@ -1766,40 +1936,6 @@

 }

-
-// *********************************************************************************************
-//            Voltage
-// *********************************************************************************************
-
-void Voltage(){
-  // read the value on analog input
-  //for ( int i = 0; i < 2; i++) {
-    /*
-    volt_sensor_value = analogRead(volt_sensot_PIN[0]);
-    vout = (volt_sensor_value * 5.0) / 1024.0;
-    vin = vout / (R2/(R1+R2));
-    volt[0]=(volt[0]+vin)/2;
-    */
-    //volt[0]=volt_sensor_value;
- // }
- /*
-  Serial.print("Vin=");
-  Serial.print(vin);
-  Serial.print("V");
-
-  Serial.print("  V=");
-  Serial.print(volt[0]);
-  Serial.print("V");
-
-
-  Serial.print("  value=");
-  Serial.print(volt_sensor_value);
-
-
-  Serial.println();
- */
-
-}

 // *********************************************************************************************
@@ -1846,10 +1982,7 @@
         lcd.write(238);
      }

-manual_modes_show();
-
-
-
+    manual_modes_show();
    }

    if (temperature_mode==1) {
@@ -1861,25 +1994,6 @@
    }
 }

-void ScreenSaver(){ //zerro
-
-  currentSens1 = analogRead(A1_pin);
-  // convert to milli amps
-  CurrentValue1 = (((long)currentSens1 * 5000 / 1024) - 500 ) * 1000 / 100;
-  amps1 = (float) CurrentValue1 / 1000;
- // lcd.setCursor(8, 1);
-
- // lcd.print(amps1);
- // lcd.print("mA");
-  //lcd.print(currentSens1);
-  float watts = (amps1 * volt[0])/100;
-  //lcd.setCursor(8, 2);
-
- // lcd.print(watts);
- // lcd.print("W");
-
-}
-
 void manual_modes_show(){
        if (manual_on==2) {
         lcd.setCursor(9, 0);
@@ -1888,11 +2002,13 @@
       if (manual_on==0) {
         lcd.setCursor(9, 0);
         //lcd.write(245);
-       lcd.print("_");
+       lcd.print("_");
+
       }
       if (manual_on==1) {
         lcd.setCursor(9, 0);
         lcd.write(255);
+
       }
 }


Logic for increment/decrement spin offset via buttons

--- NeoPixelSwitchBox/NeoPixelSwitchBox.ino
+++ NeoPixelSwitchBox/NeoPixelSwitchBox.ino
@@ -11,8 +11,12 @@
     BUG (believe I fixed it): when calling stopBlinking, if the light is off, won't turn on because it won't be queried during updateBlinkingLights.
     Or, something else may be going on. Seems like it sometimes gets one more update.

-  TODO:
+   Functionality test:
     increment/decrement buttons
+    rainbow
+    random
+
+    Concerned that I may have now run it out of memory again...
   */

   // have to include libraries referenced within libraries in the sketch as well!
@@ -59,6 +63,10 @@
   /* has the random number generator been seeded? Set true the first time random is used */
   bool seededRand = false;

+  /* Increment/decrement spin buttons on pins 0/1 - need to disable if want serial communication */
+  Switch incrementSpinButton(0, DEBOUNCE_TIME);
+  Switch decrementSpinButton(1, DEBOUNCE_TIME);
+
    /* Place light switches on 2 - 9, because pins 0 and 1 are used for serial communication */
   const int FIRST_LIGHT_SWITCH_PIN = 2;

@@ -75,7 +83,7 @@
   //button on pin 11, debounce for DEBOUNCE_TIME
   Switch rainbowButton(11, DEBOUNCE_TIME);

-  /* Buttons */
+  // button on pin 12 - toggle spin on/off
   Switch toggleSpinButton(12, DEBOUNCE_TIME);

   /* Potentiometers on analog inupts*/
@@ -93,7 +101,7 @@

   void setup() {
-     Serial.begin(9600);
+    Serial.begin(9600);
     logger.log("--- Start Serial Monitor ");

     /*
@@ -130,6 +138,9 @@
     // update the spin knob before the spin toggle, just in case they both change on the same update. Want the button to override */
     updateSpinKnob();
     updateToggleSpinButton();
+
+    // update the increment/decrement buttons
+    updateIncrementButtons();

     // update the other pots
     updateBlinkKnob();
@@ -253,6 +264,21 @@
      }
   }

+  void updateIncrementButtons() {
+
+    // spin increment button adjusts the spin clockwise by NUM_LIGHTS_PER_SWITCH
+    incrementSpinButton.update();
+    if (incrementSpinButton.closedThisUpdate()) {
+      ring.adjustSpinOffset(NUM_LIGHTS_PER_SWITCH);
+    }
+
+    // spin decrement button adjusts the spin counter-clockwise by NUM_LIGHTS_PER_SWITCH
+    decrementSpinButton.update();
+    if (incrementSpinButton.closedThisUpdate()) {
+      ring.adjustSpinOffset(-NUM_LIGHTS_PER_SWITCH);
+    }
+  }
+
   void updateRainbowButton() {
      rainbowButton.update();
      if (rainbowButton.closedThisUpdate()) {


Fix ghost press at launch

Fix ghost press at launch

--- Proto-1/Proto-1.ino
+++ Proto-1/Proto-1.ino
@@ -16,7 +16,7 @@
 	delay(10);

 	endTime = millis() + 10000 * TimeChunk;
-	previousPressed = false;
+	previousPressed = HIGH;
 }

 void loop()


working on alarm implementation

working on alarm implementation

--- display/display.ino
+++ display/display.ino
@@ -37,6 +37,10 @@
 int biasSP02Max = 0;
 int biasSP02Min = 0;
 int i = 0;
+
+// Keep track of screen inversion and alarm state
+int inverted = 0;
+int activeAlarm = 0;

 Adafruit_ILI9341 tft = Adafruit_ILI9341(CS_SCREEN, DC);
 Adafruit_STMPE610 ts = Adafruit_STMPE610(CS_TOUCH);
@@ -335,25 +339,55 @@
    return p;
 }

-IntervalTimer myTimer;
+void toggleInvert(void) {
+    if (inverted) {
+        tft.invertDisplay(0);
+        inverted = 0;
+    } else {
+        tft.invertDisplay(1);
+        inverted = 1;
+    }
+    return;
+}
+
+// Interrupts for sampling and alarm system
+IntervalTimer sample_timer;
+//IntervalTimer alarm_timer;
+
+void throwAlarm(void) {
+    //alarm_timer.begin(alarm_isr, 10000);
+    //alarm_timer.priority(130);
+    activeAlarm = 1;
+}
+
+void stopAlarm(void) {
+    //alarm_timer.end();
+    activeAlarm = 0;
+}
+

 void setup(void){
+  tft.invertDisplay(0);
+  inverted = 0;
   gui_setup();
   product_title();
   ECG_setup();
   //sp02_setup();
   //temperature_setup();
-  //settings_setup();
   alarm_button_setup();
   ecg.read();
-  myTimer.begin(isr, 150);
-  myTimer.priority(128);
-}
-
-void isr(void) {
-	//clearScreen(ILI9341_BLUE);
+  sample_timer.begin(sampling_isr, 150);
+  sample_timer.priority(128);
+}
+
+void sampling_isr(void) {
     ecg.read();
 	return;
+}
+
+void alarm_isr(void) {
+    //toggleInvert();
+    return;
 }

 int display_count = 0;
@@ -375,11 +409,22 @@
 				tft.setTextColor(ILI9341_GREENYELLOW);
   				tft.setTextSize(2);
   				tft.println(s_hr);
-    		} else { hr_counter += 1; }
+                /*
+                if ((hr < DEFAULT_ECG_MIN + biasECGMin) || (hr > DEFAULT_ECG_MAX + biasSP02Max)){
+                    if (!activeAlarm) {
+                        throwAlarm();
+                    }
+                }
+                else {
+                    if (activeAlarm) {
+                        stopAlarm();
+                    }
+    		    } */
   		}
-  		else {
-    		display_count += 1;
-  		}
+        else { hr_counter += 1; }
+        }
+  		else { display_count += 1;}
+
 	  if (ts.bufferEmpty()) {
 		continue;
 	  }


made ws2812 work

made ws2812 work

--- handlers/ESPHandler/ESPHandler.ino
+++ handlers/ESPHandler/ESPHandler.ino
@@ -1,5 +1,5 @@
-#define APA102
-//#define WS2812
+//#define APA102
+#define WS2812
 //#define WS2801

 #include <ESP8266WiFi.h>
@@ -9,6 +9,18 @@
 #include <ArduinoJson.h>
 #include <WiFiManager.h>

+#define D0   16
+#define D1   5
+#define D2   4
+#define D3   0
+#define D4   2
+#define D5   14
+#define D6   12
+#define D7   13
+#define D8   15
+#define D9   3
+#define D10  1
+
 #ifdef APA102
 #include <Adafruit_DotStar.h>
 #include <SPI.h>
@@ -29,10 +41,10 @@
 }

-#define NUMPIXELS 60
-
-#define DATAPIN    13 // GPIO15 - MISO
-#define CLOCKPIN   9 // GPIO14 - CLK
+#define NUMPIXELS 30
+
+#define DATAPIN    D2
+#define CLOCKPIN   D5

 // ========== HANDLER INFO ==========
 const char* AUTOCONFIG_ACCESSPOINT_NAME = "LightHandlerConfigAP";
@@ -61,7 +73,7 @@

 ESP8266WebServer server(80);

-//TODO use fastled?
+//TODO use fastled

 #ifdef APA102
 Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DATAPIN, CLOCKPIN);
@@ -106,7 +118,7 @@
   String apName = String(AUTOCONFIG_ACCESSPOINT_NAME) + String("_") + String(ESP.getChipId());
   char apNameBuffer[apName.length()];
   apName.toCharArray(apNameBuffer, apName.length());
-
+
   if(!wifiManager.autoConnect(apNameBuffer)) {
     Serial.println("failed to connect to WiFi and hit timeout");

@@ -119,9 +131,9 @@

 void startMulticastServer() {
   Serial.println("> startMulticastServer()");
-
+
   printWifiStatus();
-
+
   if (!Udp.beginMulticast(WiFi.localIP(), ipMulti, portMulti)) {
     Serial.print("failed to start UDP Server at port ");
     delay(500);
@@ -138,7 +150,7 @@
   int addressLength = serverAddress.length()+1;
   char address[addressLength];
   serverAddress.toCharArray(address, addressLength);
-
+
   IPAddress remote_addr;
   int error = WiFi.hostByName(address, remote_addr);
   if (error) {
@@ -147,8 +159,8 @@
     error = 0;
     Serial.print("Unable to resolve hostname. ERR: ");
     Serial.println(error);
-  }
-
+  }
+
   if (!error) {
     Serial.print("failed to connect to the LightNet Server (");
     Serial.print(address);
@@ -167,7 +179,7 @@
   client.println("Connection: close");
 }

-int registerHandler() {
+int registerHandler() {
   Serial.println("> registerHandler();");

   int error = 0;
@@ -192,7 +204,7 @@
     root["handlerGeometryHeight"] = GEOMETRY_HEIGHT;
     root["handlerGeometryLength"] = GEOMETRY_LENGTH;
     root["lightSize"] = LIGHT_SIZE;
-
+
     client.println("POST /api/handlers HTTP/1.1");
     sendHTTPHeader();
     client.println("Content-Type: application/json; charset=utf-8");
@@ -221,7 +233,7 @@
     client.stop();

   }
-
+
   Serial.print("< ");
   Serial.println(error);

@@ -230,9 +242,9 @@

 bool handlerIsRegistered() {
   Serial.println("> handlerIsRegistered()");
-
+
   bool result = false;
-
+
   Serial.println("trying to determine whether the handler is already registered");

   if (connectToAPI()) {
@@ -256,7 +268,7 @@
       result = false;
     } else if (line.startsWith("HTTP/1.1 200 OK")) {
       // TODO check if light count has changed and delete existing and reregister if changed
-
+
       Serial.println("handler already registered");
       result = true;
     } else {
@@ -266,17 +278,17 @@
     client.stop();

   }
-
+
   Serial.print("< ");
   Serial.println(result);
-
+
   return result;
 }

 void listenForServer()
 {
   Serial.println("> listenForServer()");
-
+
   int noBytes = Udp.parsePacket();
   String received_command = "";

@@ -297,7 +309,7 @@

     StaticJsonBuffer<256> jsonBuffer;
     JsonObject& root = jsonBuffer.parseObject(received_command);
-
+
     const char* hostname = root["hostname"];
     const char* ip = root["ip"];
     const char* port = root["port"];
@@ -325,13 +337,13 @@

 void handleServerRequest() {
   Serial.println("> handleServerRequest()");
-
+
   if(server.args() == 0) {
     Serial.println("< failed -> no arguments");
-
+
     server.send(500, "text/plain", "BAD ARGS\r\n");
   }
-
+
   String index = server.arg(0);
   String color_r = server.arg(1);
   String color_g = server.arg(2);
@@ -350,14 +362,14 @@
   //TODO control lights
   strip.setPixelColor(index.toInt(), strip.Color(color_r.toInt(), color_g.toInt(), color_b.toInt()));
   strip.show();
-
+
   server.send(200, "text/plain", "done.");
   Serial.println("< done");
 }

 void handleNotFound() {
   Serial.println("> handleNotFound()");
-
+
   String message = "File Not Found\n\n";
   message += "URI: ";
   message += server.uri();
@@ -380,15 +392,15 @@
     Serial.print("MDNS responder started. Hostname: ");
     Serial.println(hostnameBuffer);
   }
-
-  server.on("/", HTTP_POST, handleServerRequest);
+
+  server.on("/", HTTP_POST, handleServerRequest);
    server.on("/info", [](){
     Serial.println("> http request /info");
     server.send(200, "text/plain", String("ESPHandler v") + String(VERSION) + String(" Info: ") + String(HANDLER_INFO));
   });

   server.onNotFound(handleNotFound);
-
+
   server.begin();
   Serial.println("HTTP server started");


Adjusted Arduino to new frequencies

Adjusted Arduino to new frequencies

--- arduino/fasnacht/fasnacht.ino
+++ arduino/fasnacht/fasnacht.ino
@@ -104,20 +104,20 @@
     Serial.print(" ");
     Serial.print(ChannelFrq);
     Serial.println(" ");
-    if( (ValueFrq > 140) && (ValueFrq <= 160) ) {
+    if( (ValueFrq >= 100) && (ValueFrq <= 199) ) {
+      digitalWrite(3, 1); //B
+      digitalWrite(5, 0); //D
+      //Serial.println("B OFF D OFF ");
+    } else if( (ValueFrq >= 200) && (ValueFrq <= 299) ) {
       digitalWrite(3, 0); //B
       digitalWrite(5, 0); //D
-      //Serial.println("B OFF D OFF ");
-    } else if( (ValueFrq > 240) && (ValueFrq <= 260) ) {
+      //Serial.println("B ON  D OFF ");
+    } else if( (ValueFrq >= 300) && (ValueFrq <= 399) ) {
       digitalWrite(3, 1); //B
-      digitalWrite(5, 0); //D
-      //Serial.println("B ON  D OFF ");
-    } else if( (ValueFrq > 340) && (ValueFrq <= 360) ) {
-      digitalWrite(3, 0); //B
       digitalWrite(5, 1); //D
       //Serial.println("B OFF D ON  ");
-    } else if( (ValueFrq > 440) && (ValueFrq <= 460) ) {
-      digitalWrite(3, 1); //B
+    } else if( (ValueFrq >= 400) && (ValueFrq <= 499) ) {
+      digitalWrite(3, 0); //B
       digitalWrite(5, 1); //D
       //Serial.println("B ON  D ON  ");
     } else {
@@ -125,20 +125,20 @@
     }

     //get channel data and write output RIGHT AUIO CHANNEL
-    if( (ChannelFrq > 140) && (ChannelFrq <= 160) ) {
+    if( (ChannelFrq >= 100) && (ChannelFrq <= 199) ) {
+      digitalWrite(6, 1); //E
+      digitalWrite(9, 0); //H
+      //Serial.println("E OFF H OFF ");
+    } else if( (ChannelFrq >= 240) && (ChannelFrq <= 299) ) {
       digitalWrite(6, 0); //E
       digitalWrite(9, 0); //H
-      //Serial.println("E OFF H OFF ");
-    } else if( (ChannelFrq > 240) && (ChannelFrq <= 260) ) {
+      //Serial.println("E ON  H OFF ");
+    } else if( (ChannelFrq >= 300) && (ChannelFrq <= 399) ) {
       digitalWrite(6, 1); //E
-      digitalWrite(9, 0); //H
-      //Serial.println("E ON  H OFF ");
-    } else if( (ChannelFrq > 340) && (ChannelFrq <= 360) ) {
-      digitalWrite(6, 0); //E
       digitalWrite(9, 1); //H
       //Serial.println("E OFF H ON  ");
-    } else if( (ChannelFrq > 440) && (ChannelFrq <= 460) ) {
-      digitalWrite(6, 1); //E
+    } else if( (ChannelFrq >= 400) && (ChannelFrq <= 499) ) {
+      digitalWrite(6, 0); //E
       digitalWrite(9, 1); //H
       //Serial.println("E ON  H ON  ");
     } else {