Moving LCD updates from interrupt to loop

--- jemmaclock/jemmaclock.ino
+++ jemmaclock/jemmaclock.ino
@@ -20,7 +20,7 @@
 #include <LiquidCrystal.h>
 #include <TinyGPS++.h>
 #include <avr/wdt.h> // watchdog timer
-#include "freeram.h"
+//#include "freeram.h"

 #endif

@@ -300,6 +300,7 @@
 int photoTransistor = A4;      // phototransistor. 4.7K
 byte photoTransistorValue = 0 ;
 byte lastPhotoTransistorValue;
+byte lastPulseValue = 0;
 volatile int valueLightLevel = 0;
 // A4 and A5 for i2c
 byte potentiometerTimezone = 0;     //  input pin for the TimeZone potentiometer // was 6 pre 010
@@ -330,17 +331,26 @@
 // likely to occur is in sections of code associated with interrupts, called
 // an interrupt service routine."

+volatile time_t currentEpoch;
 volatile byte pps_loop = 0;
 void pps_interrupt(){
   // if we're not in the configuration menu and we have a good fix,
   if ( (!statConfMenu) && (gps.time.isValid()) )   {
-    time_t currentEpoch;
+//    time_t currentEpoch;
+/*
     //convert GPS time to Epoch time
     currentEpoch =  epochConverter(gps.date, gps.time);
     // and display it on the LCD
     printTime(currentEpoch);
+
+    */
+
     // this counter is for information on the second line of the LCD.
     pps_loop++;
+    if ( pps_loop > 12) {
+        pps_loop = 1;
+    }
+    /*
     if (pps_loop < 8) {
       // update the LCD with "Sats in View: 06" or similar
       printSats(satellitesInView);
@@ -364,6 +374,7 @@
     } else  {
       pps_loop = 0;
     }
+    */
   } else  {
     // silently pass if we're in configuration mode or have no nmea data
     true;
@@ -704,10 +715,11 @@
 }

 void clearScreen() {
-  lcd.setCursor(0, 0);
-  lcd.print(F("                "));
-  lcd.setCursor(0, 1);
-  lcd.print(F("                "));
+  lcd.clear();
+//  lcd.setCursor(0, 0);
+//  lcd.print(F("                "));
+//  lcd.setCursor(0, 1);
+//  lcd.print(F("                "));
 }

 void displayBootScreen() {
@@ -890,6 +902,8 @@
       // finally reset what brought us here
       inConfMode = 0;
     }
+
+
     // first set the backlight color based on number of satellites
     if (gps.satellites.isValid()) { // true even with zero satellites, as in, true with NMEA sentences coming in
       satellitesInView = gps.satellites.value();
@@ -909,6 +923,41 @@
       // save the current count so we can skip the loop next time
       lastLoopSatsInView = satellitesInView;

+//if (pps_loop > 0) {
+if (pps_loop != lastPulseValue) {
+    //convert GPS time to Epoch time
+    currentEpoch =  epochConverter(gps.date, gps.time);
+    // and display it on the LCD
+    printTime(currentEpoch);
+
+
+  // moving from interrupt to loop
+    if (pps_loop < 8) {
+      // update the LCD with "Sats in View: 06" or similar
+      printSats(satellitesInView);
+    } else if ( (pps_loop == 8) || (pps_loop == 9) ) {
+      // updated LCD with year/month/day
+      printDate(currentEpoch);
+    } else if ( (pps_loop == 10) || (pps_loop == 11) ) {
+      if (DEBUG) {
+       // displayUptime();
+               lcd.setCursor(0, 1);
+        lcd.print(F("................"));
+       valueLightLevel = analogRead(photoTransistor);
+        updateLcdInt(1, valueLightLevel);
+      }
+    } else if ( pps_loop == 13) { // 13 is impossible, delete me.
+      clearScreen();
+      if (DEBUG) {
+        lcd.setCursor(0, 1);
+        lcd.print(F("................"));
+        //updateLcdInt(1, freeRam());
+      }
+    }
+        lastPulseValue = pps_loop;
+
+}
+
       // this section updates the LCD if there isn't PPS.
       // otherwise, LCD updates happen from PPS so there aren't locking problems.
       if ( (satellitesInView == 2) || (satellitesInView == 3) ) {
@@ -965,8 +1014,8 @@
         digitalWrite(LED_BUILTIN, noFix);
      }

-    // pause main loop for a fifth of a second
-    TinyGpsPlusPlus::smartDelay(199);
+    // pause main loop for a 20th of a second
+    TinyGpsPlusPlus::smartDelay(49);

     // update LED. Off with connected antenna, 3
     if (antennaStatus == 3) {


Moved sleep-loop into libs

Moved sleep-loop into libs

--- Arduino/hardware/V0p2_Main_PCB_REV7_DORM1_and_REV8/REV7RadValve/REV7RadValve.ino
+++ Arduino/hardware/V0p2_Main_PCB_REV7_DORM1_and_REV8/REV7RadValve/REV7RadValve.ino
@@ -757,20 +757,10 @@
     // Try if very near to end of cycle and thus causing an overrun.
     // Conversely, if not true, should have time to safely log outputs, etc.
     const uint8_t nearOverrunThreshold = OTV0P2BASE::GSCT_MAX - 8; // ~64ms/~32 serial TX chars of grace time...
-    // Sleep in low-power mode (waiting for interrupts) until seconds roll.
-    // NOTE: sleep at the top of the loop to minimise timing jitter/delay from Arduino background activity after loop() returns.
-    // DHD20130425: waking up from sleep and getting to start processing below this block may take >10ms.
-    // Ensure that serial I/O is off while sleeping.
-    OTV0P2BASE::powerDownSerial();
-    // Power down most stuff (except radio for hub RX).
-    OTV0P2BASE::minimisePowerWithoutSleep();
-    uint_fast8_t newTLSD;
-    while(TIME_LSD == (newTLSD = OTV0P2BASE::getSecondsLT())) {
-        // Normal long minimal-power sleep until wake-up interrupt.
-        // Rely on interrupt to force quick loop round to I/O poll.
-        OTV0P2BASE::sleepUntilInt();
-    }
-    TIME_LSD = newTLSD;
+
+    // Go to sleep until the start of the next cycle.
+    TIME_LSD = OTV0P2BASE::sleepUntilNewCycle<>(TIME_LSD);
+
     // Reset and immediately re-prime the RTC-based watchdog.
     OTV0P2BASE::resetRTCWatchDog();
     OTV0P2BASE::enableRTCWatchdog(false);


added macro for fps enabling

added macro for fps enabling

--- arduino/ws2812_controller/ws2812_controller.ino
+++ arduino/ws2812_controller/ws2812_controller.ino
@@ -8,6 +8,7 @@
 // Set this to the number of LEDs in your LED strip
 #define NUM_LEDS 260
 #define BUFFER_LEN 1024
+#define PRINT_FPS 1

 // Wifi and socket settings
 const char* ssid     = "YOUR_WIFI_SSID";
@@ -44,13 +45,13 @@
     Serial.println(WiFi.localIP());
     port.begin(localPort);
     ledstrip.init(NUM_LEDS);
-    pinMode(0, OUTPUT);
 }

 uint8_t N = 0;
+#ifdef PRINT_FPS
 int fpsCounter = 0;
 int secondTimer = 0;
-int redLedTimer = 0;
+#endif
 void loop() {
     // Read data over socket
     int packetSize = port.parsePacket();
@@ -67,10 +68,11 @@
         }
       ledstrip.show(pixels);
       Serial.print("*");
-      fpsCounter++;
-      digitalWrite(0, 0);
+      #ifdef PRINT_FPS
+        fpsCounter++;
+      #endif
   }
-
+  #ifdef PRINT_FPS
   if(millis() - secondTimer >= 1000)
   {
     secondTimer = millis();
@@ -78,4 +80,5 @@
     Serial.printf("FPS: %d\n", fpsCounter);
     fpsCounter = 0;
   }
+  #endif
 }


SensorBoard: filling some packet fields

SensorBoard: filling some packet fields

--- SensorBoard.ino
+++ SensorBoard.ino
@@ -12,7 +12,6 @@
   Serial.begin(57600);

   radio.begin();
-  //radio.setChannel(0x4b);
   radio.setAutoAck(false);
   radio.setRetries(15,15);
   radio.setPALevel(RF24_PA_MAX);
@@ -30,8 +29,8 @@

 void loop(void)
 {
-  byte command[32] ;
-  byte *ptr;
+  char command[32] ;
+  char *ptr;
   ptr = &command[0];
   if ( radio.available() )
     {
@@ -39,37 +38,32 @@
       bool done = false;
       while (!done)
       {
-        done = radio.read( ptr, sizeof(byte[32]) );
-        Serial.println(ptr[1]);
-	// Delay just a little bit to let the other unit
-	// make the transition to receiver
-	delay(20);
+        done = radio.read( ptr, sizeof(char[32]) );
+        delay(20);
       }
       runCommand(ptr);
-      Serial.println(ptr[3]);
+      Serial.println(ptr[12]);
+
       radio.stopListening();
       radio.write(ptr, sizeof(byte[32]));
       radio.startListening();
     }

 }
-bool runCommand(byte *ptr)
+void runCommand(char *ptr)
 {
-  Serial.println(ptr[1]);
-  Serial.println(ptr[2]);
-  Serial.println(ptr[3]);
-  switch (ptr[1])
+  Serial.println(ptr[10]);
+  switch (ptr[10])
   {
     case 0:
       break;
     case 1:
-      if (ptr[3]== 0x00)
-      {
+      if (ptr[12]== 0x00){
         switchOnLight(ptr);
       }
       break;
     case 2:
-      if (ptr[3]== 0x00)
+      if (ptr[12]== 0x00)
       {
         switchOffLight(ptr);
       }
@@ -77,16 +71,33 @@
   }

 }
+void readAllSensors(char* ptr){
+  readTemp(ptr);
+  readHum(ptr);
+  readLum(ptr);
+
+}
+void readTemp(char* ptr){
+  ptr[12] = 0xFF;
+  ptr[13] = 0x02;
+}
+void readHum(char* ptr){
+  ptr[12] = 0xFF;
+  ptr[14] = 0x03;
+}
+void readLum(char* ptr){
+  ptr[12] = 0xFF;
+  ptr[15] = 0xFF;

-byte readTemp(void){}
-byte readHum(void){}
-byte readLight(void){}
-bool switchOnLight(byte* ptr)
+}
+void switchOnLight(char* ptr)
 {
   digitalWrite(led, HIGH);
-  ptr[3] = 0xFF;
+  ptr[12] = 0xFF;
+  ptr[16] = 0xFF;
 }
-bool switchOffLight(byte* ptr){
+bool switchOffLight(char* ptr){
   digitalWrite(led, LOW);
-  ptr[3] = 0xFF;
+  ptr[12] = 0xFF;
+  ptr[16] = 0xFF;
 }


Fix typo

Fix typo

--- libraries/ESP8266WebServer/examples/SDWebServer/SDWebServer.ino
+++ libraries/ESP8266WebServer/examples/SDWebServer/SDWebServer.ino
@@ -180,7 +180,7 @@
     return returnFail("NOT DIR");
   }
   dir.rewindDirectory();
-  server.setContentSize(CONTENT_SIZE_UNKNOWN);
+  server.setContentLength(CONTENT_LENGTH_UNKNOWN);
   server.send(200, "text/json", "");
   WiFiClient client = server.client();


Changed back to QoS 1 for message due to QoS 2 refusing to work Set client timeout to 5 seconds to reduce waiting time before sensor shifts to error state Keep Alive Interval set to 10 seconds to reduce time before web client shifts to error state Changed loop so that it won't read the button state until it is definitely connected Added yield to ensure that the sensor responds to PingResponse from the broker to keep the connection open

--- sensor/ZoneControlSensor.ino
+++ sensor/ZoneControlSensor.ino
@@ -3,8 +3,6 @@
 Copyright (c) Nicholas Tyrrell, Bournemouth University
 Code inspired by http://www.eclipse.org/paho/clients/c/embedded/
 */
-
-#define MQTTCLIENT_QOS2 1

 #include <SPI.h>
 #include <Ethernet2.h>
@@ -19,14 +17,15 @@
 //IP constants
 byte mac[] = { 0x90, 0xA2, 0xDA, 0x10, 0x39, 0x37 }; //MAC address for sensor device

-//MQTT variables
-MQTT::Client<IPStack, Countdown, 50, 1> mqttClient = MQTT::Client<IPStack, Countdown, 50, 1>(ipstack);
-char room[21] = "roman"; //name of room within building
-
 //MQTT constants
 const char* mainTopic = "londonbridge";
-MQTT::QoS qos = MQTT::QOS2;
+MQTT::QoS qos = MQTT::QOS1;
 bool retained = true;
+int timeout = 5000; //5 seconds for client to publish before timing out
+
+//MQTT variables
+MQTT::Client<IPStack, Countdown> mqttClient = MQTT::Client<IPStack, Countdown>(ipstack, timeout);
+char room[21] = "roman"; //name of room within building

 //Room State
 enum RoomState
@@ -77,6 +76,8 @@
 		MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
 		data.willFlag = 1;
 		data.MQTTVersion = 4;
+		data.cleansession = 1;
+		data.keepAliveInterval = 10;
 		data.clientID.cstring = (char*)"sensor-1";
 		data.will.topicName.cstring = (char*)willTopicBuffer;
 		data.will.qos = 2;
@@ -273,9 +274,9 @@
 }

 void loop() {
-	if (!mqttClient.isConnected()) {
+	while (!mqttClient.isConnected()) {
 		connect();
-	} else {
-		checkSwitches();
-	}
+	}
+	checkSwitches();
+	mqttClient.yield(10);
 }


Updated tests

Updated tests

--- test/testValue/testValue.ino
+++ test/testValue/testValue.ino
@@ -4,6 +4,76 @@

 char outBuf[80];

+test(bool_default_is_false)
+{
+  Value<bool> boolVal1;
+
+  assertEqual(boolVal1.getValue(), false);
+
+  boolVal1.getValueString(outBuf);
+  assertEqual(strcmp (outBuf, "Off"), 0);
+}
+
+test(bool_setValue_true_default_format)
+{
+  Value<bool> boolVal1;
+  boolVal1.setValue(true);
+
+  assertEqual(boolVal1.getValue(), true);
+
+  boolVal1.getValueString(outBuf);
+  assertEqual(strcmp (outBuf, "On"), 0);
+}
+
+test(bool_comparisons)
+{
+  Value<bool> boolVal1;
+  Value<bool> boolVal2;
+
+  assertTrue(boolVal1 == boolVal2);
+
+  boolVal1.setValue(true);
+  assertTrue( boolVal1 != boolVal2);
+
+  boolVal2.setValue(true);
+  assertTrue(boolVal1 == boolVal2);
+}
+
+
+test(bool_has_changed)
+{
+  Value<bool> boolVal1;
+  assertFalse(boolVal1.hasChanged());
+
+  boolVal1.setValue(true);
+  assertTrue(boolVal1.hasChanged());
+}
+
+
+test(bool_persist)
+{
+  Value<bool> boolVal1;
+  assertFalse(boolVal1.hasChanged());
+
+  boolVal1.setValue(true);
+  assertTrue(boolVal1.hasChanged());
+
+  boolVal1.persistValue();
+  assertFalse(boolVal1.hasChanged());
+
+  boolVal1.setValue(false);
+  assertTrue(boolVal1.hasChanged());
+
+  boolVal1.revertValue();
+  assertTrue(boolVal1.getValue());
+  assertFalse(boolVal1.hasChanged());
+
+  boolVal1.initValue(false);
+  assertFalse(boolVal1.getValue());
+  assertFalse(boolVal1.hasChanged());
+}
+
+

 test(float_default_is_0_0)
 {
@@ -71,6 +141,82 @@
   assertEqual(strcmp (outBuf, "1.01"), 0);
 }

+test(float_comparisons)
+{
+  Value<float> floatVal1;
+  Value<float> floatVal2;
+
+  assertTrue(floatVal1 == floatVal2);
+
+  floatVal1.setValue(10.0);
+  assertTrue( floatVal1 != floatVal2);
+  assertTrue( floatVal1 > floatVal2);
+  assertTrue( floatVal1 >= floatVal2);
+  assertFalse( floatVal1 < floatVal2);
+  assertFalse( floatVal1 <= floatVal2);
+
+  floatVal2.setValue(10.0);
+  assertTrue(floatVal1 == floatVal2);
+  assertFalse( floatVal1 > floatVal2);
+  assertTrue( floatVal1 >= floatVal2);
+  assertFalse( floatVal1 < floatVal2);
+  assertTrue( floatVal1 <= floatVal2);
+
+}
+
+test(float_math)
+{
+  Value<float> floatVal1;
+  Value<float> floatVal2;
+  Value<float> floatVal3;
+
+  floatVal1.setValue(10.0);
+  assertEqual(floatVal1.getValue(), 10.0);
+
+  assertFalse(floatVal1 == floatVal2);
+
+  floatVal3.setValue(10.0);
+  assertTrue(floatVal1 == floatVal3);
+
+
+  floatVal2 = floatVal1;
+  assertTrue(floatVal1 == floatVal2);
+
+  floatVal1.setValue(20.0);
+  assertEqual(floatVal1.getValue(), 20.0);
+  assertFalse(floatVal1 == floatVal2);
+
+  assertEqual(floatVal1 + floatVal2, 30.0);
+
+  assertEqual(floatVal1 - floatVal2, 10.0);
+
+  assertEqual(floatVal1 * floatVal2, 200.0);
+
+  assertEqual(floatVal1 / floatVal2, 2.0);
+}
+
+test(float_persist)
+{
+  Value<float> floatVal1;
+  assertFalse(floatVal1.hasChanged());
+
+  floatVal1.setValue(10.0);
+  assertTrue(floatVal1.hasChanged());
+
+  floatVal1.persistValue();
+  assertFalse(floatVal1.hasChanged());
+
+  floatVal1.setValue(0.0);
+  assertTrue(floatVal1.hasChanged());
+
+  floatVal1.revertValue();
+  assertEqual(floatVal1.getValue(), 10.0);
+  assertFalse(floatVal1.hasChanged());
+
+  floatVal1.initValue(20.0);
+  assertEqual(floatVal1.getValue(), 20.0);
+  assertFalse(floatVal1.hasChanged());
+}

 test(int_default_is_0)
 {
@@ -126,9 +272,175 @@
   assertEqual(intVal1.getValue(), -1001);

   intVal1.getValueString(outBuf);
-
   assertEqual(strcmp (outBuf, "-10.01"), 0);
 }
+
+test(int_comparisons)
+{
+  Value<int> intVal1;
+  Value<int> intVal2;
+
+  assertTrue(intVal1 == intVal2);
+
+  intVal1.setValue(10);
+  assertTrue( intVal1 != intVal2);
+  assertTrue( intVal1 > intVal2);
+  assertTrue( intVal1 >= intVal2);
+  assertFalse( intVal1 < intVal2);
+  assertFalse( intVal1 <= intVal2);
+
+  intVal2.setValue(10);
+  assertTrue(intVal1 == intVal2);
+  assertFalse( intVal1 > intVal2);
+  assertTrue( intVal1 >= intVal2);
+  assertFalse( intVal1 < intVal2);
+  assertTrue( intVal1 <= intVal2);
+}
+
+test(int_math)
+{
+  Value<int> intVal1;
+  Value<int> intVal2;
+  Value<int> intVal3;
+
+  intVal1.setValue(10);
+  assertEqual(intVal1.getValue(), 10);
+
+  assertFalse(intVal1 == intVal2);
+
+  intVal3.setValue(10);
+  assertTrue(intVal1 == intVal3);
+
+
+  intVal2 = intVal1;
+  assertTrue(intVal1 == intVal2);
+
+  intVal1.setValue(20);
+  assertEqual(intVal1.getValue(), 20);
+  assertFalse(intVal1 == intVal2);
+
+  assertEqual(intVal1 + intVal2, 30);
+
+  assertEqual(intVal1 - intVal2, 10);
+
+  assertEqual(intVal1 * intVal2, 200);
+
+  assertEqual(intVal1 / intVal2, 2);
+}
+
+test(int_persist)
+{
+  Value<int> intVal1;
+  assertFalse(intVal1.hasChanged());
+
+  intVal1.setValue(10);
+  assertTrue(intVal1.hasChanged());
+
+  intVal1.persistValue();
+  assertFalse(intVal1.hasChanged());
+
+  intVal1.setValue(0);
+  assertTrue(intVal1.hasChanged());
+
+  intVal1.revertValue();
+  assertEqual(intVal1.getValue(), 10);
+  assertFalse(intVal1.hasChanged());
+
+  intVal1.initValue(20);
+  assertEqual(intVal1.getValue(), 20);
+  assertFalse(intVal1.hasChanged());
+}
+
+test(uint_default_is_0)
+{
+  Value<unsigned int> uintVal1;
+
+  assertEqual(uintVal1.getValue(), 0);
+
+  uintVal1.getValueString(outBuf);
+  assertEqual(strcmp (outBuf, "0"), 0);
+
+}
+
+test(uint_setValue_1_default_format)
+{
+  Value<unsigned int> uintVal1;
+  uintVal1.setValue(1);
+
+  assertEqual(uintVal1.getValue(), 1);
+
+  uintVal1.getValueString(outBuf);
+  assertEqual(strcmp (outBuf, "1"), 0);
+}
+
+
+test(uint_setValue_1_01_fixed_pouint_2_decimals)
+{
+  Value<unsigned int> uintVal1(1,2);
+  uintVal1.setValue(101);
+
+  assertEqual(uintVal1.getValue(), 101);
+
+  uintVal1.getValueString(outBuf);
+  assertEqual(strcmp (outBuf, "1.01"), 0);
+}
+
+test(uint_setValue_1_01_fixed_pouint_scaled_by_10)
+{
+  Value<unsigned int> uintVal1(1,2,10);
+  uintVal1.setValue(1010);
+
+  assertEqual(uintVal1.getValue(), 1010);
+
+  uintVal1.getValueString(outBuf);
+  assertEqual(strcmp (outBuf, "1.01"), 0);
+}
+
+test(ulong_default_is_0)
+{
+  Value<unsigned long> uintVal1;
+
+  assertEqual(uintVal1.getValue(), 0);
+
+  uintVal1.getValueString(outBuf);
+  assertEqual(strcmp (outBuf, "0"), 0);
+
+}
+
+test(ulong_setValue_1_default_format)
+{
+  Value<unsigned long> uintVal1;
+  uintVal1.setValue(1);
+
+  assertEqual(uintVal1.getValue(), 1);
+
+  uintVal1.getValueString(outBuf);
+  assertEqual(strcmp (outBuf, "1"), 0);
+}
+
+
+test(ulong_setValue_1_01_fixed_point_2_decimals)
+{
+  Value<unsigned long> uintVal1(1,2);
+  uintVal1.setValue(101);
+
+  assertEqual(uintVal1.getValue(), 101);
+
+  uintVal1.getValueString(outBuf);
+  assertEqual(strcmp (outBuf, "1.01"), 0);
+}
+
+test(ulong_setValue_1_01_fixed_point_scaled_by_10)
+{
+  Value<unsigned long> uintVal1(1,2,10);
+  uintVal1.setValue(1010);
+
+  assertEqual(uintVal1.getValue(), 1010);
+
+  uintVal1.getValueString(outBuf);
+  assertEqual(strcmp (outBuf, "1.01"), 0);
+}
+

@@ -141,4 +453,4 @@
 void loop()
 {
   Test::run();
-}+}


Calibrated controller

Calibrated controller

--- transmitter/TX/TX.ino
+++ transmitter/TX/TX.ino
@@ -26,8 +26,8 @@

 #define PIN_THROTTLE A0
 #define PIN_YAW      A1
-#define PIN_PITCH    A2
-#define PIN_ROLL     A3
+#define PIN_ROLL     A2
+#define PIN_PITCH    A3

 #define PIN_SWITCH_A 2 // (PD2 - PCINT18)
 #define PIN_SWITCH_B 3 // (PD3 - PCINT19)
@@ -135,13 +135,19 @@
 // Returns a corrected value for a joystick position that takes into account
 // the values of the outer extents and the middle of the joystick range
 // and maps it to the range the RX expects.
-int joystickMapValues(int val, int lower, int middle, int upper)
+int joystickMapValues(int val, int lower, int middle, int upper, byte invert)
 {
   val = constrain(val, lower, upper);
-  if ( val < middle )
+
+  if ( val < middle ) {
     val = map(val, lower, middle, 0, 499);
-  else
+  } else {
     val = map(val, middle, upper, 500, 1000);
+  }
+
+  if (invert) {
+    val = 1000 - val;
+  }

   // RX expects values between 1000 & 2000
   return val + 1000;
@@ -157,10 +163,10 @@
   static unsigned long debounce_sample_last = 0;

-  throttle = joystickMapValues(analogRead(PIN_THROTTLE), 125, 515, 1000);
-  yaw      = joystickMapValues(analogRead(PIN_YAW), 10, 521, 1000);
-  pitch    = joystickMapValues(analogRead(PIN_PITCH), 0, 511, 1023);
-  roll     = joystickMapValues(analogRead(PIN_ROLL), 0, 511, 1023);
+  throttle = joystickMapValues(analogRead(PIN_THROTTLE), 125, 515, 1000, 0);
+  yaw      = joystickMapValues(analogRead(PIN_YAW), 10, 517, 1000, 0);
+  pitch    = joystickMapValues(analogRead(PIN_PITCH), 0, 513, 1023, 1);
+  roll     = joystickMapValues(analogRead(PIN_ROLL), 0, 507, 1023, 1);

   if (DEBUG) {


Fix bug in arcTo()

Fix bug in arcTo()

Fixed bug in arcTo within the rotate vector stage (lines 444-448)

--- software/firmware/LogoBotWifiScribbler/LogoBotWifiScribbler.ino
+++ software/firmware/LogoBotWifiScribbler/LogoBotWifiScribbler.ino
@@ -1,8 +1,11 @@
 #include <AccelStepper.h>
 #include <Servo.h>

+// Maths stuff
+#define DEGTORAD  PI/180
+#define RADTODEG  180/PI
+
 // Pin definitions
-
 // Left motor driver
 #define motorLPin1  2     // IN1 on the ULN2003 driver 1
 #define motorLPin2  3     // IN2 on the ULN2003 driver 1
@@ -385,7 +388,7 @@

 static void driveTo(float x, float y) {
   // calc angle
-  float ang = atan2(y-state.y, x-state.x) * 180 / PI;
+  float ang = atan2(y-state.y, x-state.x) * RADTODEG;
   // now angle delta
   ang = ang - state.ang;
   if (ang > 180)
@@ -405,8 +408,8 @@
 void drive(float distance)
 {
   // update state
-  state.x += distance * cos(state.ang * PI / 180);
-  state.y += distance * sin(state.ang * PI / 180);
+  state.x += distance * cos(state.ang * DEGTORAD);
+  state.y += distance * sin(state.ang * DEGTORAD);

   // prime the move
   int steps = distance * STEPS_PER_MM;
@@ -420,8 +423,8 @@
   state.ang += ang;

   // correct wrap around
-  if (state.ang > 360) state.ang -= 360;
-  if (state.ang < -360) state.ang += 360;
+  if (state.ang > 180) state.ang -= 360;
+  if (state.ang < -180) state.ang += 360;

   // prime the move
   int steps = ang * STEPS_PER_DEG;
@@ -434,13 +437,15 @@

     if (y == 0) return;

-    float cx = x - state.x;
-    float cy = y - state.y;
+    float cx1 = x - state.x;
+    float cy1 = y - state.y;

     //v.rotate(degToRad(-this.state.angle));
-    float ang = -state.ang * PI / 180;
-    cx = cx * cos(ang) - cy * sin(ang);
-    cy = cx * sin(ang) + cy * cos(ang);
+    float ang = -state.ang * DEGTORAD;
+    float ca = cos(ang);
+    float sa = sin(ang);
+    float cx = cx1 * ca - cy1 * sa;
+    float cy = cx1 * sa + cy1 * ca;

     float m = -cx / cy;

@@ -456,7 +461,7 @@
     float cl, cr;

     if (x1 < 0) {
-        targetAng = atan2(cy, -x1 + cx) * 180/PI;
+        targetAng = atan2(cy, -x1 + cx) * RADTODEG;

         cl = 2 * PI * (-WHEELSPACING/2 - x1);
         dl = cl * targetAng/360;
@@ -465,7 +470,7 @@
         dr = cr * targetAng/360;

     } else {
-        targetAng = atan2(cy, x1 - cx) * 180/PI;
+        targetAng = atan2(cy, x1 - cx) * RADTODEG;

         cl = 2 * PI * (x1 + WHEELSPACING/2 );
         dl = cl * targetAng/360;


put all includes in .ino file, so the gui can compile it

--- firmware/Nanpy.ino
+++ firmware/Nanpy.ino
@@ -1,3 +1,11 @@
+#include <EEPROM.h>
+#include <Servo.h>
+#include <LiquidCrystal.h>
+#include <Stepper.h>
+#include <OneWire.h>
+#include <DallasTemperature.h>
+#include <CapacitiveSensor.h>
+
 #include "BaseClass.h"
 #include "ArduinoClass.h"
 #include "OneWireClass.h"
@@ -17,7 +25,7 @@

 void setup() {

-    REGISTER_CLASS(EEPROMClass);
+    REGISTER_CLASS(nanpy::EEPROMClass);
     REGISTER_CLASS(ArduinoClass);
     REGISTER_CLASS(LiquidCrystalClass);
     REGISTER_CLASS(OneWireClass);


Prints and Includes Edited

Prints and Includes Edited

Changed Chassis_Control.ino to remove prints that were apparently
causing some weird buffer filling issue that stopped the Arduino.
Also took out some unnecessary includes.

Signed-off-by: cramertj <3dfc0cba061557d19bed96d5219d693d7696b3d8@gmail.com>

--- tests/drive-test/Chassis_Control/Chassis_Control.ino
+++ tests/drive-test/Chassis_Control/Chassis_Control.ino
@@ -1,6 +1,4 @@
 #include <Servo.h>
-#include <map>
-#include <string>
 #include <Wire.h>

 // Insert own filepath here
@@ -70,7 +68,7 @@
   Serial.begin(115200);
   timeLastPacket = 0;

-  Serial.println("Initialization complete.");
+  //Serial.println("Initialization complete.");
 }

 void loop()
@@ -97,7 +95,7 @@
     rightMotor.writeMicroseconds(NEUTRAL_FREQUENCY);
     if(!timedOut) {
       timedOut = true;
-      Serial.println("TIMEOUT REACHED");
+      //Serial.println("TIMEOUT REACHED");
     }
   }
   delay(3);


Update enom_Client.ino

Update enom_Client.ino

--- examples/enom_Client/enom_Client.ino
+++ examples/enom_Client/enom_Client.ino
@@ -1,5 +1,5 @@
 /*
-######### Noip Update Client for ESP8266 ##########
+######### ENom Update Client for ESP8266 ##########
 This Example Explains the Use of EasyDDNS Library with No-ip Service
 and Checks for New Public IP Every 10 Seconds.


tweak pin numbers

tweak pin numbers

--- ardesp/waterelf_Spiffs_MQTT_level_MOSFETS/waterelf_Spiffs_MQTT_level_MOSFETS.ino
+++ ardesp/waterelf_Spiffs_MQTT_level_MOSFETS/waterelf_Spiffs_MQTT_level_MOSFETS.ino
@@ -240,9 +240,8 @@

 /////////////////////////////////////////////////////////////////////////////
 // level sensing stuff //////////////////////////////////////////////////////
-//const int levelTriggerPin=15;
-const int levelTriggerPin=2;
-const int levelEchoPin=14;
+const int levelTriggerPin=12;
+const int levelEchoPin=13;
 boolean GOT_LEVEL_SENSOR = false;  // we'll change later if we detect sensor

 /////////////////////////////////////////////////////////////////////////////
@@ -255,7 +254,7 @@

 /////////////////////////////////////////////////////////////////////////////
 // humidity sensor stuff ////////////////////////////////////////////////////
-DHT dht(12, DHT22); // what digital pin we're on, plus type DHT22 aka AM2302
+DHT dht(0, DHT22); // what digital pin we're on, plus type DHT22 aka AM2302
 boolean GOT_HUMID_SENSOR = false;  // we'll change later if we detect sensor

 /////////////////////////////////////////////////////////////////////////////
@@ -328,8 +327,8 @@
 //  TelnetServer.setNoDelay(true);
   mcp.begin();      // use default address 0 for mcp23008
   mcp.pinMode(0, OUTPUT);
-  mcp.pinMode(5, OUTPUT);
-  mcp.pinMode(6, OUTPUT);
+  mcp.pinMode(3, OUTPUT);
+  mcp.pinMode(7, OUTPUT);
   if(WiFi.hostname("waterelf"))
     Serial.println("set hostname succeeded");
   else
@@ -794,10 +793,10 @@

   // now we trigger the mcp23008 to turn MOSFETs off or on
   if(newState == true){
-    mcp.digitalWrite(5, HIGH);
+    mcp.digitalWrite(3, HIGH);
     Serial.println("Right Water Pump on");
   } else {
-    mcp.digitalWrite(5, LOW);
+    mcp.digitalWrite(3, LOW);
     Serial.println("Right Water Pump off");
   }

@@ -818,7 +817,7 @@
   pinMode(levelEchoPin, INPUT);
   GOT_LEVEL_SENSOR = true;

-  mySwitch.enableTransmit(13);   // RC transmitter is connected to Pin 12
+  mySwitch.enableTransmit(15);   // RC transmitter is connected to Pin 12
   tempSensor.begin();     // start the onewire temperature sensor
   if(tempSensor.getDeviceCount()==1) {
     GOT_TEMP_SENSOR = true;


correct default blynk token value

correct default blynk token value

--- Device_LinkItOne/LASS/LASS.ino
+++ Device_LinkItOne/LASS/LASS.ino
@@ -292,7 +292,7 @@
 char msg[MSG_BUFFER_MAX]; //buffer

 // Blynk
-char blynk_auth[] = "5cb1d7f458c041b0a195cf2515ef2d96"; //"YourAuthToken"; // REPLACE: your Blynk auto id
+char blynk_auth[] = "YourAuthToken"; // REPLACE: your Blynk auto id

 //----- Storage -----
 #include <LTask.h>


Changes to finewire twister sketch.

Changes to finewire twister sketch.

--- finewire-twister/twister/twister.ino
+++ finewire-twister/twister/twister.ino
@@ -11,11 +11,11 @@
 #define TRIG 2

 // Hardcoded number of steps in the motor I'm using
-#define STEPS_PER_REV 24
+#define STEPS_PER_REV 200

 AccelStepper stepper(1, STEP, DIR);
 long num_turns = 100;
-long usteps = 8;
+long usteps = 0;
 volatile bool moving = false;
 volatile bool state_change = false;
 const int led = LED_BUILTIN;
@@ -77,7 +77,7 @@
       usteps = setUStep(usteps);

       // Set max stepper speed in turns/sec
-      double max_speed = 10000;
+      double max_speed = 500;
       stepper.setMaxSpeed(max_speed);
       stepper.setAcceleration(max_speed/5);
   }
@@ -86,6 +86,13 @@
 int setUStep(int us) {

   switch (us) {
+  case 0: {
+    digitalWrite(M0, LOW);
+    digitalWrite(M1, LOW);
+    digitalWrite(M2, LOW);
+    Serial.println("Set to no microsteps");
+    return 1;
+  }
   case 8: {
     digitalWrite(M0, HIGH);
     digitalWrite(M1, HIGH);


Update Stroboscope.ino

Update Stroboscope.ino

--- examples/More/Stroboscope/Stroboscope.ino
+++ examples/More/Stroboscope/Stroboscope.ino
@@ -58,7 +58,7 @@
 // Enable/disable blinking using virt pin 1
 BLYNK_WRITE(1)
 {
-  if (param[0].asInt()) {
+  if (param.asInt()) {
     timer.enable(t1);
   } else {
     timer.disable(t1);
@@ -69,7 +69,7 @@
 // Change blink interval using virtual pin 2
 BLYNK_WRITE(2)
 {
-  int interval = param[0].asInt();
+  int interval = param.asInt();
   boolean wasEnabled = timer.isEnabled(t1);
   timer.deleteTimer(t1);
   t1 = timer.setInterval(interval, ledBlynk);


Teensy MIDI fix

Teensy MIDI fix

This fixes issues with the reuse of OPL2 channels in the TeensyMidi
sketch. Issues in the function to get a free OPL2 channel would return
the wrong channel causing clicks and pops. This fix eliminates this
issue mostly, though not fully as it also depends on the instrument
being used.

This fix is in reference to #44

--- examples/Teensy/TeensyMidi/TeensyMidi.ino
+++ examples/Teensy/TeensyMidi/TeensyMidi.ino
@@ -17,9 +17,6 @@

 #include <SPI.h>
 #include <OPL2.h>
-
-// For better results with midi files created for Window exchange midi_instruments.h for midi_instruments_win31.h
-// #include <midi_instruments_win31.h>
 #include <midi_instruments.h>
 #include <midi_drums.h>

@@ -77,11 +74,13 @@
  */
 byte getFreeChannel(byte midiChannel) {
 	byte opl2Channel = 255;
-
-	// Look for a free OPL2 channel.
+	byte oldestIndex = 0;
+
+	// Look for a free OPL2 channel starting with the oldest.
 	for (byte i = 0; i < OPL2_NUM_CHANNELS; i ++) {
-		if (!opl2.getKeyOn(i)) {
-			opl2Channel = i;
+		if (!opl2.getKeyOn(oldestChannel[i])) {
+			opl2Channel = oldestChannel[i];
+			oldestIndex = i;
 			break;
 		}
 	}
@@ -93,21 +92,19 @@
 		for (byte i = 0; i < OPL2_NUM_CHANNELS; i ++) {
 			if (channelMap[oldestChannel[i]].midiChannel == MIDI_DRUM_CHANNEL) {
 				opl2Channel = oldestChannel[i];
-			}
-		}
+				oldestIndex = i;
+				break;
+			}
+		}
+		opl2.setKeyOn(opl2Channel, false);
 	}

 	// Update the list of last used channels by moving the current channel to the bottom so the last updated channel
 	// will move to the front of the list. If no more OPL2 channels are free then the last updated one will be recycled.
-	byte i;
-	for (i = 0; i < OPL2_NUM_CHANNELS && oldestChannel[i] != opl2Channel; i ++) {}
-
-	while (i < OPL2_NUM_CHANNELS - 1) {
-		byte temp = oldestChannel[i + 1];
-		oldestChannel[i + 1] = oldestChannel[i];
-		oldestChannel[i] = temp;
-		i ++;
-	}
+	for (byte i = oldestIndex; i < OPL2_NUM_CHANNELS - 1; i ++) {
+		oldestChannel[i] = oldestChannel[i + 1];
+	}
+	oldestChannel[OPL2_NUM_CHANNELS - 1] = opl2Channel;

 	return opl2Channel;
 }
@@ -138,26 +135,26 @@
 	}

 	// Get an available OPL2 channel and setup instrument parameters.
-	byte i = getFreeChannel(channel);
+	byte opl2Channel = getFreeChannel(channel);
 	if (channel != MIDI_DRUM_CHANNEL) {
-		opl2.setInstrument(i, midiInstruments[programMap[channel]]);
+		opl2.setInstrument(opl2Channel, midiInstruments[programMap[channel]]);
 	} else {
 		if (note >= DRUM_NOTE_BASE && note < DRUM_NOTE_BASE + NUM_MIDI_DRUMS) {
-			opl2.setInstrument(i, midiDrums[note - DRUM_NOTE_BASE]);
+			opl2.setInstrument(opl2Channel, midiDrums[note - DRUM_NOTE_BASE]);
 		} else {
 			return;
 		}
 	}

 	// Register channel mapping.
-	channelMap[i].midiChannel  = channel;
-	channelMap[i].midiNote     = note;
-	channelMap[i].midiVelocity = round(velocity / 127.0);
-	channelMap[i].op1Level     = round((63 - opl2.getVolume(i, OPERATOR1)) / 63.0);
-	channelMap[i].op2Level     = round((63 - opl2.getVolume(i, OPERATOR2)) / 63.0);
+	channelMap[opl2Channel].midiChannel  = channel;
+	channelMap[opl2Channel].midiNote     = note;
+	channelMap[opl2Channel].midiVelocity = min((float)velocity / 64.0, 1.0);
+	channelMap[opl2Channel].op1Level     = (float)(63 - opl2.getVolume(opl2Channel, OPERATOR1)) / 63.0;
+	channelMap[opl2Channel].op2Level     = (float)(63 - opl2.getVolume(opl2Channel, OPERATOR2)) / 63.0;

 	// Set operator output levels based on note velocity.
-	setOpl2ChannelVolume(i, channel);
+	setOpl2ChannelVolume(opl2Channel, channel);

 	// Calculate octave and note number and play note!
 	byte opl2Octave = 4;
@@ -167,7 +164,7 @@
 		opl2Octave = 1 + (note - 24) / 12;
 		opl2Note   = note % 12;
 	}
-	opl2.playNote(i, opl2Octave, opl2Note);
+	opl2.playNote(opl2Channel, opl2Octave, opl2Note);
 }

@@ -179,6 +176,23 @@
 	for (byte i = 0; i < OPL2_NUM_CHANNELS; i ++) {
 		if (channelMap[i].midiChannel == channel && channelMap[i].midiNote == note) {
 			opl2.setKeyOn(i, false);
+			channelMap[i].midiChannel = 0xFF;
+			channelMap[i].midiNote = 0x00;
+
+			// Move channel to the back of recently used channels list to prevent it from
+			// being reused immediately and the release portion of the note being clubbored.
+			byte oldestIndex = 0;
+			for (byte j = 0; j < OPL2_NUM_CHANNELS; j ++) {
+				if (oldestChannel[j] == i) {
+					oldestIndex = j;
+					break;
+				}
+			}
+			for (byte j = oldestIndex; j < OPL2_NUM_CHANNELS - 1; j ++) {
+				oldestChannel[j] = oldestChannel[j + 1];
+			}
+			oldestChannel[OPL2_NUM_CHANNELS - 1] = i;
+
 			break;
 		}
 	}


Refactoring Nucleo examples.

Refactoring Nucleo examples.

--- examples/Nucleo/CosaNucleoBenchmark/CosaNucleoBenchmarkThread.ino
+++ examples/Nucleo/CosaNucleoBenchmark/CosaNucleoBenchmarkThread.ino
@@ -1,72 +0,0 @@
-/**
- * @file CosaNucleoBenchmark.ino
- * @version 1.0
- *
- * @section License
- * Copyright (C) 2014, Mikael Patel
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA  02111-1307  USA
- *
- * @section Description
- * Cosa Nucleo Thread benchmarks
- * 1) Run 1,000,000 context switches (12-13 us)
- *
- * This file is part of the Arduino Che Cosa project.
- */
-
-#include "Cosa/RTC.hh"
-#include "Cosa/Trace.hh"
-#include "Cosa/Watchdog.hh"
-#include "Cosa/Nucleo/Thread.hh"
-#include "Cosa/IOStream/Driver/UART.hh"
-
-class Benchmark : public Nucleo::Thread {
-public:
-  virtual void run();
-};
-
-void
-Benchmark::run()
-{
-  // This will force 1,000,000 context switches as the Nucleo main thread
-  // will context switch back for each loop; 2*500*1000 in total
-  // The loop handling and RTC access are included but very small values.
-  while (1) {
-    uint32_t start = RTC::micros();
-    for (uint16_t i = 0; i < 500; i++)
-      for (uint16_t j = 0; j < 1000; j++)
-	yield();
-    uint32_t stop = RTC::micros();
-    trace << PSTR("yield: ") << (stop - start) / 1000000 << PSTR(" us") << endl;
-  }
-}
-
-Benchmark bench;
-
-void setup()
-{
-  uart.begin(9600);
-  trace.begin(&uart, PSTR("CosaNucleoBenchmark: started"));
-  Watchdog::begin();
-  RTC::begin();
-  Nucleo::Thread::begin(&bench, 128);
-}
-
-void loop()
-{
-  Nucleo::Thread::begin();
-  ASSERT(true == false);
-}


COH-71: WIP

COH-71: WIP

--- COHEAT2015/20160316-COHEAT-M1/COHEAT-M1/COHEAT-M1.ino
+++ COHEAT2015/20160316-COHEAT-M1/COHEAT-M1/COHEAT-M1.ino
@@ -1280,7 +1280,6 @@
       }
 #endif

-
 #if defined(ENABLE_FHT8VSIMPLE)
   // Try for double TX for more robust conversation with valve?
   const bool doubleTXForFTH8V = false;
@@ -1289,17 +1288,19 @@
   bool useExtraFHT8VTXSlots = localFHT8VTRVEnabled() && FHT8VPollSyncAndTX_First(doubleTXForFTH8V); // Time for extra TX before UI.
   if(useExtraFHT8VTXSlots)
     {
-    // Time for extra TX before other actions, but don't bother if minimising power in frost mode.
+    handleQueuedMessages(&Serial, true, &PrimaryRadio);
     // ---------- HALF SECOND #1 -----------
     useExtraFHT8VTXSlots = localFHT8VTRVEnabled() && FHT8VPollSyncAndTX_Next(doubleTXForFTH8V);
     }
   if(useExtraFHT8VTXSlots)
     {
+    handleQueuedMessages(&Serial, true, &PrimaryRadio);
     // ---------- HALF SECOND #2 -----------
     useExtraFHT8VTXSlots = localFHT8VTRVEnabled() && FHT8VPollSyncAndTX_Next(doubleTXForFTH8V);
     }
   if(useExtraFHT8VTXSlots)
     {
+    handleQueuedMessages(&Serial, true, &PrimaryRadio);
     // ---------- HALF SECOND #3 -----------
     useExtraFHT8VTXSlots = localFHT8VTRVEnabled() && FHT8VPollSyncAndTX_Next(doubleTXForFTH8V);
     }


arduino output added

arduino output added

--- StuntCarRacer/Arduino_Code/HapkitController/HapkitController.ino
+++ StuntCarRacer/Arduino_Code/HapkitController/HapkitController.ino
@@ -192,7 +192,7 @@
 void calPosMeter()
 {
   double rh = 65.659;   //[mm]
-  double ts = -.0107 * updatedPos + 4.9513; // Compute the angle of the sector pulley (ts) in degrees based on updatedPos
+  double ts = -.0107 * updatedPos + 7.9513; // Compute the angle of the sector pulley (ts) in degrees based on updatedPos
   xh = rh * (ts * 3.14159 / 180); // Compute the position of the handle based on ts
   vh = -(.95 * .95) * lastLastVh + 2 * .95 * lastVh + (1 - .95) * (1 - .95) * (xh - lastXh) / .0001; // filtered velocity (2nd-order filter)
   lastXh = xh;
@@ -207,9 +207,9 @@
 	byte result = 0;
 	digitalRead(joyFwdPin) == LOW ? result += 1 : 0;
 	digitalRead(joyBackPin) == LOW ? result += 2 : 0;
-	digitalRead(joyLeftPin) == LOW ? result += 4 : 0;
-	digitalRead(joyRightPin) == LOW ? result += 8 : 0;
-	digitalRead(joyFirePin) == LOW ? result += 16 : 0;
+	(xh>2.0f) == LOW ? result += 4 : 0;
+	(xh<-2.0f) == LOW ? result += 8 : 0;
+	//digitalRead(joyFirePin) == LOW ? result += 16 : 0;
 	return result;
 }

@@ -256,7 +256,8 @@
 */
 bool dir;
 uint32_t nextcall = 1000;
-uint32_t nextcall2 = 2000;
+const uint16_t intervalperiod = 50*64; // 100 milliseconds
+uint32_t nextcall2 = 1000;
 bool on_off = true;
 void loop() {
   // read the position in count
@@ -266,7 +267,12 @@
   if(millis()>nextcall)
     on_off = false;
   forceRendering();
-
+
+
+  if(millis() > nextcall2){
+    nextcall2 += intervalperiod;
+    Serial.println(readJoystick());
+  }
   on_off ? set_position = xh + sin(10.0f*2.0f*M_PI*millis()/64000.0f) : force = 0;
   motorControl();


Add watchdog support to indoor slave.

Add watchdog support to indoor slave.

--- SensorSeed/Arduino/ArduinoIndoorReceiverI2cSlave/ArduinoIndoorReceiverI2cSlave.ino
+++ SensorSeed/Arduino/ArduinoIndoorReceiverI2cSlave/ArduinoIndoorReceiverI2cSlave.ino
@@ -1,9 +1,11 @@
+#include <Adafruit_SleepyDog.h>
 #include <TinyWireM.h>
 #include <USI_TWI_Master.h>
 #include <Wire.h>
 #include <RFM69.h>
 #include <SPI.h>
 #include <stdlib.h>
+#include <avr/wdt.h>

 volatile byte* Float1ArrayPtr;
 double dataToSend;
@@ -79,13 +81,16 @@
 digitalWrite(8, LOW);
  Wire.begin(7);
  Wire.onRequest(requestEvent);
- Wire.onReceive(receiveEvent);
+ Wire.onReceive(receiveEvent);
+  int countdownMS = Watchdog.enable();
   Serial.println("Setup complete");
 }
 void loop() {
+  Watchdog.reset();
   //check if something was received (could be an interrupt from the radio)
   if (radio.receiveDone())
   {
+  Watchdog.reset();
   int sensorIndex = 1;
   int sensorCharIndex = 0;
   int charIndex = 0;
@@ -242,7 +247,7 @@
 void requestEvent(){
   // char frame[30];
  //sprintf(frame, "%8.2", dataToSend);
-
+    Watchdog.reset();
    //String data = String(dataToSend, DEC);
    //dataToSend = 123456.78;
   if(dataToSend == 0 || dataToSend == 1) { // isDataNew
@@ -252,6 +257,15 @@
    Wire.write(temp1);

   } else {
+
+    if((millis() - lastSentMillis) < 10000) { // if  data was sent less than ten seconds ago then restart the arduiono
+      Serial.println("Sending bad data, restarting in 8 seconds...");
+      while(1) {
+        int isCrashed = 1;
+        delay(1000);
+        }
+    }
+
     Serial.print("Index: ");
     //String data = String("error");
     int sensorIndex = dataToSend - 10;
@@ -324,6 +338,7 @@
       // 13: humidityDHT22 6

 void receiveEvent(int howMany){
+  Watchdog.reset();
   int c;
   c = Wire.read(); // receive byte as a character
   //Serial.print("Got: ");


Update PulseSensorAmped_Arduino_1dot4.ino

--- PulseSensorAmped_Arduino_1dot4/PulseSensorAmped_Arduino_1dot4.ino
+++ PulseSensorAmped_Arduino_1dot4/PulseSensorAmped_Arduino_1dot4.ino
@@ -35,8 +35,8 @@
   pinMode(fadePin,OUTPUT);          // pin that will fade to your heartbeat!
   Serial.begin(115200);             // we agree to talk fast!
   interruptSetup();                 // sets up to read Pulse Sensor signal every 2mS
-   // UN-COMMENT THE NEXT LINE IF YOU ARE POWERING The Pulse Sensor AT LOW VOLTAGE,
-   // AND APPLY THAT VOLTAGE TO THE A-REF PIN
+   // IF YOU ARE POWERING The Pulse Sensor AT VOLTAGE LESS THAN THE BOARD VOLTAGE,
+   // UN-COMMENT THE NEXT LINE AND APPLY THAT VOLTAGE TO THE A-REF PIN
 //   analogReference(EXTERNAL);
 }


Master example running

Master example running

--- examples/BulliBusMaster/BulliBusMaster.ino
+++ examples/BulliBusMaster/BulliBusMaster.ino
@@ -7,32 +7,32 @@

 void onTmp( Cargo &cargo ) {

-	if( (cargo.addr & 0x000f) == '1' ) {
-
-		Serial.print( "Got temp: " );
-		Serial.println( cargo.argv[ 0 ] );
-	}
+	Serial.print( "Got temp: " );
+	Serial.println( cargo.argv );
 }

-setup() {
+void setup() {

-	Serial.begin( 115200 );
-	Serial.print( "Hello World\n" );
-
-	bus.begin( 115200 );
+	bus.begin( 19200 );

 	pinMode( LED, OUTPUT );

 }

-loop() {
+void blink() {

-	/*
+	static bool on;
+
+	on = !on;
+
+	digitalWrite( LED, on );
+}
+
+void loop() {
+
 	driver.request( "tmp1", "get", onTmp );

-	bus.delay( 100 );
-	*/
-	delay( 100 );
+	bus.delay( 250 );

-	digitalWrite( LED, !digitalRead( LED ) );
+	blink();
 }


Update stale comments in WiFi connection code.

The comments were confusing and wrong.

--- aquacontrol.ino
+++ aquacontrol.ino
@@ -213,7 +213,7 @@
   //thisFile will be re-used throughout the whole setup() routine
   File thisFile;

-  //check if we have WiFi credentials on disk --  if commented out, hardwired credentials will be used
+  //check if we have WiFi credentials on disk
   thisFile = SPIFFS.open( wifiDataFile , "r");
   if ( thisFile ) {
     while (thisFile.available()) {
@@ -226,7 +226,7 @@
     }
     thisFile.close();
   } else {
-    //WiFi.mode(WIFI_AP);
+    //no WiFi credentials found, start an accesspoint to setup WiFi
     startAP();
   }


Microview speech

Microview speech

--- arduino/microview_laserscan_speech/microview_laserscan_speech.ino
+++ arduino/microview_laserscan_speech/microview_laserscan_speech.ino
@@ -23,7 +23,7 @@
   uView.print("speech\n");
   uView.print(cmd_msg.data);
   uView.display();
-  delay(1500);
+  delay(3000);
   speaking = false;
 }


Fade working properly now, but might need brighter turn-on (low-pass effect in ON transition causes very dim and short tail)

--- MatrixEffect/MatrixEffect.ino
+++ MatrixEffect/MatrixEffect.ino
@@ -37,6 +37,7 @@
     colors[i_led].h = new_colors[i_led].h;
     colors[i_led].s = new_colors[i_led].s;
     colors[i_led].v = (uint8_t) (((uint16_t) colors[i_led].v*19 + new_colors[i_led].v)/20);
+    // colors[i_led].v = new_colors[i_led].v;

     // Then copy the current HSV value to the current RGB value
     leds[i_led] = colors[i_led];
@@ -78,7 +79,8 @@
         new_colors[xy2i(x,y)] = new_colors[xy2i(x,y-1)];
       } else {
         // If off, turn the pixel off (the actual pixel colour has a FO low-pass filter)
-        new_colors[xy2i(x,y)].setHSV(0,0,0);
+        // Leave the hue and saturation intact
+        new_colors[xy2i(x,y)].v = 0;
       }
     }

@@ -87,7 +89,7 @@
   for(uint8_t x=0; x<COLS; ++x){
     //first row -> turn off the off pixels after propagation of colour
     if(!onPixels[0][x]){
-      new_colors[xy2i(x,0)].setHSV(0,0,0);
+      new_colors[xy2i(x,0)].v = 0; //leave H and S value
     }
   }
 }
@@ -98,7 +100,7 @@
   // Let the controller know we're using WS2801 leds, and give a pointer to the current colour array
   LEDS.addLeds<WS2801, RGB>(leds, NUM_LEDS);
   // Limit the brightness somewhat (scale is 0-255)
-  LEDS.setBrightness(127);
+  LEDS.setBrightness(200);

   // Initialise the leds to black (off)
   for(uint8_t i=0; i<NUM_LEDS; ++i){


Set micro step pins more elegantly.

Set micro step pins more elegantly.

--- OpenStage/d_setupFunction.ino
+++ OpenStage/d_setupFunction.ino
@@ -46,14 +46,6 @@
   #endif

-
-
-
-
-  //Set the micro-step pins as outputs
-  pinMode(MS1,OUTPUT);
-  pinMode(MS2,OUTPUT);
-  pinMode(MS3,OUTPUT);

   if (verbose){
@@ -74,6 +66,12 @@

     pinMode(stageLEDs[ii],OUTPUT);
     digitalWrite(stageLEDs[ii],LOW);
+
+    //Set microstep pins
+    for (byte jj=0; jj<3; jj++){
+        pinMode(MS[ii][jj],OUTPUT);
+    }
+

     if (verbose){
       Serial.print(ii);


Delete newTest.ino

Delete newTest.ino

--- newTest.ino
+++ newTest.ino
@@ -1,51 +0,0 @@
-TCPClient client;
-
-
-
-char server[] = "my-node-url.com";
-
-
-
-
-
-int connectToMyServer(String nothing) {
-
-  digitalWrite(D7, HIGH);
-  if (client.connect(server, 80)) {
-      client.write("GET / HTTP/1.1\r\n");
-      client.write("Host: my-node-url.com\r\n");
-      client.write("\r\n");
-    digitalWrite(D7, LOW);
-    return 1; // successfully connected
-  } else {
-    digitalWrite(D7, LOW);
-    return -1; // failed to connect
-  }
-
-}
-
-void setup() {
-
-      pinMode(D7, OUTPUT);
-
-      Spark.function("connect", connectToMyServer);
-      digitalWrite(D7, HIGH);
-      delay(25000);
-      digitalWrite(D7, LOW);
-
-
-}
-
-void loop() {
-  if (client.connected()) {
-    if (client.available()) {
-    // char pin = client.read() - '0' + D0;
-      //char level = client.read();
-      if (client.read()) {
-        digitalWrite(D7, HIGH);
-      } else {
-        digitalWrite(D7, LOW);
-      }
-    }
-  }
-}


added sd card modified sketch

added sd card modified sketch

--- code/arduino/sample/sketch_sd_card/sketch_sd_card.ino
+++ code/arduino/sample/sketch_sd_card/sketch_sd_card.ino
@@ -27,17 +27,16 @@
 // used as the CS pin, the hardware CS pin (10 on most Arduino boards,
 // 53 on the Mega) must be left as an output or the SD library
 // functions will not work.
-const int chipSelect = 10;
+const int chipSelect = 9;

 File dataFile;
+volatile int counter ;

 void setup()
 {
  // Open serial communications and wait for port to open:
   Serial.begin(9600);
-   while (!Serial) {
-    ; // wait for serial port to connect. Needed for Leonardo only
-  }
+

   Serial.print("Initializing SD card...");
@@ -53,33 +52,23 @@
   }
   Serial.println("card initialized.");

+
+
+  counter = 1001 ;
+}
+
+void log_data() {
+
   // Open up the file we're going to log to!
-  dataFile = SD.open("yuktix.dat", FILE_WRITE);
+  dataFile = SD.open("test2.dat", O_CREAT | O_WRITE | O_APPEND);
   if (! dataFile) {
     Serial.println("error opening yuktix.dat");
     // Wait forever since we cant write data
     while (1) ;
   }
-}
-
-void loop()
-{
-  // make a string for assembling the data to log:
-  String dataString = "";
-
-  // read three sensors and append to the string:
-  for (int analogPin = 0; analogPin < 3; analogPin++) {
-    int sensor = analogRead(analogPin);
-    dataString += String(sensor);
-    if (analogPin < 2) {
-      dataString += ",";
-    }
-  }
-
-  dataFile.println(dataString);
-
-  // print to the serial port too:
-  Serial.println(dataString);
+
+  counter += 1 ;
+  dataFile.println(counter);

   // The following line will 'save' the file to the SD card after every
   // line of data - this will use more power and slow down how much data
@@ -87,10 +76,17 @@
   // If you want to speed up the system, remove the call to flush() and it
   // will save the file only every 512 bytes - every time a sector on the
   // SD card is filled with data.
-  dataFile.flush();
+  dataFile.close();

+}
+
+
+void loop()
+{
+
+  log_data();
   // Take 1 measurement every 500 milliseconds
-  delay(500);
+  delay(1000);
 }


horloge_cycles_ultradiens

--- files/horloge_cycles_ultradiens/horloge_cycles_ultradiens.ino
+++ files/horloge_cycles_ultradiens/horloge_cycles_ultradiens.ino
@@ -110,7 +110,7 @@
   // Cette procédure permet de régler l’heure de l’horloge
   // via le bus RS232.
   // Exemple de commande à envoyer :
-  // 2016,6,6,16,24,50
+  // 2016,6,7,21,00,30

   const byte nbCharMax = 19;
   char str[ nbCharMax ] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
@@ -178,22 +178,26 @@
 {

   // ****
-  // Calculs du pourcentage du cycle d’attention
-  // et du temps équivalent en 16e de jour exprimé en pixels
+  // Calculs du pourcentage du cycle d’attention (cycle)
+  // et du temps équivalent en 1/16e de jour exprimé en pixels (frac16eJourPx)
   // **

   // lecture de l’heure actuelle
   DateTime now = RTC.now();

-  // Calcul du temps équivalent en 16e de jour
+  // Calcul du temps équivalent en 1/16e de jour
   // NB : - Il y a 16 cycles d’1 h 30 dans 24 h
   //      - 1 h 30 = 5400 s
   long frac16eJour = ( now.secondstime() - heureAttentionMax ) % 5400;

+  // Calcul du pourcentage du cycle d’attention
+  // 2 * π * 16 / 86400 = 0.0011635528
+  double cycle = 100.0 * 0.5 * ( 1.0 + cos( ( double )( frac16eJour ) * 0.0011635528 ) );
+
   // Conversion de “frac16eJour” en pixels
-  // Les valeurs de la 1ère moitié du cycle sont affichées à droite de l’écran.
-  // Les valeurs de la 2e moitié du cycle sont affichées à gauche de l’écran.
-  // Le code ci-dessous permute les deux moitiés pour qu’elles s’affichent au bon endroit.
+  // Les valeurs de la 1ère moitié du cycle correspondent à la partie droite du cosinus.
+  // Les valeurs de la 2e moitié du cycle correspondent à la partie gauche du cosinus.
+  // Le code ci-dessous permute les deux moitiés pour qu’elles s’affichent du bon côté.
   int16_t frac16eJourPx;
   if( frac16eJour < 5400/2 )
     { frac16eJourPx = map( frac16eJour,
@@ -204,19 +208,15 @@
                               5400/2,         5400-1,
                               0,              displayWidth/2-1 ); }

-  // Calcul du pourcentage du cycle d’attention
-  // 2 * π * 16 / 86400 = 0.0011635528
-  double cycle = 50.0 * ( 1.0 + cos( ( double )( frac16eJour ) * 0.0011635528 ) );
-

   // ****
   //  Affichage des résultats
   // **

-  // Efface l’écran
+  // Effacement de l’écran
   display.clearDisplay();

-  // Prépare l’affichage de la date
+  // Préparation de l’affichage de la date
   display.setTextSize( 1 );
   display.setCursor( 0, 0 );
   display.print( now.day() );
@@ -239,32 +239,29 @@
   display.setCursor( 0, 9 );
   display.print( now.year() );

-  // Prépare l’affichage de l’heure et des minutes
+  // Préparation de l’affichage de l’heure et des minutes
   char texteAffichage[ 5 ];
   sprintf( texteAffichage, "%2d:%02d", now.hour(), now.minute() );
   display.setTextSize( 2 );
   display.setCursor( 49, 0 );
   display.print( texteAffichage );

-  // Prépare l’affichage des secondes
+  // Préparation de l’affichage des secondes
   sprintf( texteAffichage, ":%02d", now.second() );
   display.setTextSize( 1 );
   display.print( texteAffichage );

-  // Prépare l’affichage du pourcentage du cycle
+  // Préparation de l’affichage du pourcentage du cycle
   display.setTextSize( 2 );
-  // cycle = 0..9.9
-  if( cycle < 10 )       { display.setCursor( 46, 21 );
-                           display.print( cycle, 1 );  }
-  // cycle = 10..99.4999
-  else if( cycle < 99.5 ){ display.setCursor( 34, 21 );
-                          display.print( cycle, 1 );  }
-  // cycle >= 99.5
-  else                   { display.setCursor( 42, 21 );
-                           display.print( cycle, 0 );  }
+  if( cycle < 10 )
+    { display.setCursor( 34, 21 ); display.print( cycle, 2 ); }
+  else if( cycle < 99.5 )
+    { display.setCursor( 34, 21 ); display.print( cycle, 1 ); }
+  else
+    { display.setCursor( 42, 21 ); display.print( cycle, 0 ); }
   display.print( char( 37 ) ); // signe %

-  // Prépare l’affichage de la courbe du cycle
+  // Préparation de l’affichage de la courbe du cycle
   prepareCourbeCycle( frac16eJourPx );

   // Met à jour l’affichage


testing

testing

--- drive.ino
+++ drive.ino
@@ -52,8 +52,8 @@
 	else if (l == 1) driveForwardL(driveSpeed);
 	//else if (l == 2) driveReverseR(driveSpeed);

-	if (r == 0)	stopMotorR();
-	else if (r == 1) driveForwardR(driveSpeed);
+	//if (r == 0)	stopMotorR();
+	//else if (r == 1) driveForwardR(driveSpeed);
 	//else if (r == 2) driveReverseR(driveSpeed);


up brightness a bit

up brightness a bit

--- src/blinky.ino
+++ src/blinky.ino
@@ -32,7 +32,7 @@
 NSFastLED::CRGB leds[PIXEL_COUNT];
 uint8_t base_hue = 0;
 uint8_t pattern = 0;
-unsigned long gBrightness = 5;
+unsigned long gBrightness = 17;
 // this is ghetto debouncing, and will ignore input to the pattern button
 // for X cycles of LOOP_DELAY_MS once triggered
 uint8_t ignore_button_cycles = 0;


match FONA example pins to FONA test sketch

--- arduino-fona/button/button.ino
+++ arduino-fona/button/button.ino
@@ -1,10 +1,10 @@
 #include <SoftwareSerial.h>
 #include <Adafruit_FONA.h>

-#define FONA_RX 5
-#define FONA_TX 4
-#define FONA_RST 3
-#define BUTTON 2
+#define FONA_RX 2
+#define FONA_TX 3
+#define FONA_RST 4
+#define BUTTON 8

 // replace xxxxxxxxx with your Adafruit IO key
 #define AIO_KEY "xxxxxxxxx"
@@ -20,7 +20,7 @@
 void setup() {

   // set button pin as an input
-  pinMode(BUTTON, INPUT);
+  pinMode(BUTTON, INPUT_PULLUP);

   // wait until Serial is available
   while (!Serial);
@@ -37,6 +37,9 @@
     Serial.println(F("Couldn't find FONA"));
     while(1);
   }
+
+  // turn on GPRS
+  fona.enableGPRS(true);

 }

@@ -50,11 +53,11 @@
     return;

   // send the proper value to AIO depending on button state
-  if(current == HIGH)
+  if(current == LOW)
     sendData("button", "1");
   else
     sendData("button", "0");
-
+
   // save the button state
   last = current;

@@ -84,7 +87,7 @@
     return false;

   fona.HTTP_POST_end();
-
+
   // should return a HTTP 201
   return statuscode == 201;


updated debug test

updated debug test

--- installation/examples/Debug_uSpeech/Debug_uSpeech.ino
+++ installation/examples/Debug_uSpeech/Debug_uSpeech.ino
@@ -13,6 +13,8 @@
     Serial.println(" Press 'a' if you wish to calibrate/check the f algorithm");
     Serial.println(" Press 'b' if you wish to calibrate/check the getPhoneme");
     Serial.println(" Press 'c' if you wish to calibrate/check the volume of your microphone");
+    Serial.println(" Press 'd' if you wish to calibrate/check the coeff");
+    Serial.println(" Press 'e' if you wish to calibrate/check the vowel detector");
     option = 1;
   }
   if(option==1){
@@ -30,4 +32,11 @@
   if(option=='c'){
     Serial.println(voice.power());
   }
-}
+  if(option=='d'){
+  	Serial.println(voice.testCoeff);
+  }
+  if(option=='e'){
+
+    Serial.println(voice.vowelRatio);
+  }
+}


Updated write

Updated write

--- arduino/arduino.ino
+++ arduino/arduino.ino
@@ -13,6 +13,16 @@

 // the loop routine runs over and over again forever:
 void loop() {
-  Serial.write("Hello Matthew" + char(255));
+  char end_stop = char(255);
+  String message = "Hello Matthew";
+  String send_message = String(message + end_stop);
+
+  int send_length = send_message.length()+1;
+
+  char charBuf[send_length];
+  send_message.toCharArray(charBuf, send_length);
+
+  Serial.write(charBuf);
   delay(1000);
 }
+


Delete dragino.ino

Delete dragino.ino

--- arduino/dragino.ino
+++ arduino/dragino.ino
@@ -1 +0,0 @@
-


clientId is required

clientId is required

--- examples/microblu_eth/microblu_eth.ino
+++ examples/microblu_eth/microblu_eth.ino
@@ -706,8 +706,12 @@
     //oops we're not connected yet or we lost connection
     Serial.println(F("connecting..."));

-    // Octoblu doesnt use client so send empty client string and YOUR UUID and token
-    if (microblu.connect("", UUID, TOKEN)){
+    String clientIdStr = "microblu_" + String(random(500000)) + "_" + String(random(500000));
+    int clientId_len = clientIdStr.length() + 1;
+    char clientId[clientId_len];
+    clientIdStr.toCharArray(clientId, clientId_len);
+
+    if (microblu.connect(clientId, UUID, TOKEN)){

       //success!
       Serial.println(F("connected"));
@@ -717,4 +721,4 @@

     }
   }
-}+}


Added offset for encoders so that left wheels have correct rotation

--- src/SabertoothDriverROS/SabertoothDriverROS.ino
+++ src/SabertoothDriverROS/SabertoothDriverROS.ino
@@ -279,21 +279,21 @@
   }
   currentWheelStatus[REAR_LEFT_DRIVE_MOTOR_ID].orientation = (int)((temp * 9L) / 10L);

-  temp = EncoderFR::getPosition();
+  temp = EncoderFR::getPosition() - 200;
   if (temp < 0)
   {
     temp += 400;
   }
   currentWheelStatus[FRONT_RIGHT_DRIVE_MOTOR_ID].orientation = (int)((temp * 9L) / 10L);

-  temp = EncoderMR::getPosition();
+  temp = EncoderMR::getPosition() - 200;
   if (temp < 0)
   {
     temp += 400;
   }
   currentWheelStatus[MIDDLE_RIGHT_DRIVE_MOTOR_ID].orientation = (int)((temp * 9L) / 10L);

-  temp = EncoderRR::getPosition();
+  temp = EncoderRR::getPosition() - 200;
   if (temp < 0)
   {
     temp += 400;
@@ -305,11 +305,11 @@

   // Communicate with the computer
   EncoderFL::setupEncoderFL();
-  EncoderML::setupEncoderFL();
-  EncoderRL::setupEncoderFL();
-  EncoderFR::setupEncoderFL();
-  EncoderMR::setupEncoderFL();
-  EncoderRR::setupEncoderFL();
+  EncoderML::setupEncoderML();
+  EncoderRL::setupEncoderRL();
+  EncoderFR::setupEncoderFR();
+  EncoderMR::setupEncoderMR();
+  EncoderRR::setupEncoderRR();

   sabertoothDriverNode.initNode();
   sabertoothDriverNode.subscribe(mcSUB);


Moved command to different line

Moved command to different line

--- arduino/arduino.ino
+++ arduino/arduino.ino
@@ -11,19 +11,24 @@
   Serial.begin(9600);
 }

-// the loop routine runs over and over again forever:
-void loop() {
+
+void send_log(String message) {
   char command = char(0);
   char end_stop = char(255);
-  String message = "Hello Matthew";
-  String send_message = String(command + message + end_stop);
+  String send_message = String(message + end_stop);
+  send_message = String(command + message);

   int send_length = send_message.length()+1;

   char charBuf[send_length];
   send_message.toCharArray(charBuf, send_length);
-
   Serial.write(charBuf);
+}
+
+
+// the loop routine runs over and over again forever:
+void loop() {
+  send_log("Hello Matthew");
   delay(1000);
 }


Somewhat working arduino controller sketch

--- arduino/arduino.ino
+++ arduino/arduino.ino
@@ -1,48 +1,77 @@
 #include <AccelStepper.h>

-
-AccelStepper stepper(AccelStepper::DRIVER, 2, 5); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
-
-AccelStepper stepper2(AccelStepper::DRIVER, 3, 6);
+//(type, step pin, direction pin)
+AccelStepper stepperX(AccelStepper::DRIVER, 2, 5);
+AccelStepper stepperY(AccelStepper::DRIVER, 3, 6);

 unsigned long nextUpdate = 0;

 void setup()
 {
-    Serial.begin(9600);
+    Serial.begin(115200);
+    Serial.setTimeout(10);
+    stepperX.setMaxSpeed(750);
+    stepperX.setAcceleration(100);
+
+    stepperY.setMaxSpeed(750);
+    stepperY.setAcceleration(100);
+
 }

 void loop()
 {
-    if (stepper.distanceToGo() == 0)
-    {

-        stepper.moveTo(rand() % 200);
-        stepper.setMaxSpeed((rand() % 200) + 1);
-        stepper.setAcceleration((rand() % 200) + 1);
-    }
+    stepperX.run();
+    stepperY.run();
+
+
+    handleInput();
+    update();

-    stepper.run();
-
-    if (stepper2.distanceToGo() == 0)
-    {
-
-        stepper2.moveTo(rand() % 200);
-        stepper2.setMaxSpeed((rand() % 200) + 1);
-        stepper2.setAcceleration((rand() % 200) + 1);
-    }
+}

-    stepper2.run();
-
-    //this should be every second to so...
-    //it will overflow at some point...
+
+void update() {
+
+    //this should be every second or so
+    //it will overflow and stop working at some point :P
     if (millis() >= nextUpdate) {
+
+        Serial.print(stepperX.currentPosition());
+        Serial.print(" ");
+        Serial.print(stepperY.currentPosition());
+        Serial.print(" ");
+        Serial.print(stepperX.targetPosition());
+        Serial.print(" ");
+        Serial.print(stepperY.targetPosition());
+        Serial.print(" ");
+        Serial.print(stepperX.distanceToGo());
+        Serial.print(" ");
+        Serial.print(stepperY.distanceToGo());
+        Serial.print("\r\n");

-        Serial.print("Value is:");
-        Serial.print(stepper.currentPosition());
-        Serial.print(" ");
-        Serial.print(stepper2.currentPosition());
-        Serial.print("\r\n");
-        nextUpdate = millis() + 1000;
+        nextUpdate = millis() + 250;
     }
 }
+void handleInput() {
+      if (Serial.available() > 0) {
+
+          char command = Serial.read();
+
+          if (command == 'j') { //j as in jog
+              long jogX = Serial.parseInt();
+              long jogY = Serial.parseInt();
+              //we are jogging
+              stepperX.move(jogX);
+              stepperY.move(jogY);
+          }
+
+          if (command == 'g') {
+              long absoluteX = Serial.parseInt();
+              long absoluteY = Serial.parseInt();
+              stepperX.moveTo(absoluteX);
+              stepperY.moveTo(absoluteY);
+          }
+
+      }
+}


Added more microcontrollers to the list

Added more microcontrollers to the list

--- examples/IRremoteInfo/IRremoteInfo.ino
+++ examples/IRremoteInfo/IRremoteInfo.ino
@@ -107,8 +107,24 @@
   Serial.println(F("Teensy++ 1.0 / AT90USB646"));
 #elif defined(__AVR_AT90USB1286__)
   Serial.println(F("Teensy++ 2.0 / AT90USB1286"));
-#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__)
-  Serial.println(F("Sanguino / ATmega644(P)"));
+#elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)
+  Serial.println(F("ATmega1284"));
+#elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__)
+  Serial.println(F("ATmega644"));
+#elif defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324A__) || defined(__AVR_ATmega324PA__)
+  Serial.println(F("ATmega324"));
+#elif defined(__AVR_ATmega164A__) || defined(__AVR_ATmega164P__)
+  Serial.println(F("ATmega164"));
+#elif defined(__AVR_ATmega128__)
+  Serial.println(F("ATmega128"));
+#elif defined(__AVR_ATmega64__)
+  Serial.println(F("ATmega64"));
+#elif defined(__AVR_ATmega32__)
+  Serial.println(F("ATmega32"));
+#elif defined(__AVR_ATmega16__)
+  Serial.println(F("ATmega16"));
+#elif defined(__AVR_ATmega8535__)
+  Serial.println(F("ATmega8535"));
 #elif defined(__AVR_ATmega8P__) || defined(__AVR_ATmega8__)
   Serial.println(F("Atmega8 / ATmega8(P)"));
 #elif defined(__AVR_ATtiny84__)


Fixed hang on credit request

Fixed hang on credit request

--- VendingMachineRFID.ino
+++ VendingMachineRFID.ino
@@ -84,9 +84,16 @@
     }
     // Request and read data from other party
     Serial.write(command);
-    while (!Serial.available()); // Wait till other side transmits a C
-    if (Serial.read() != command)
-      return;
+    uint32_t now = millis();
+    while (!Serial.available() && (millis() - now < 1000)); // Wait till we recieve something or timeout
+    if (!Serial.available()){ // check if we recieved, or timed out
+      recieve_error = 1; // Nothing revieced - abort
+      return 0;
+    }
+    if (Serial.read() != command){
+      recieve_error = 1; // ACK not revieced - abort
+      return 0;
+    }
     number = rfid_raw_read();
     if (recieve_error == 0) { // Received correctly, return value
       return number;


Added new features to WEMOS D1

Added new features to WEMOS D1

--- WEMOS_D1/ServerDHT.ino
+++ WEMOS_D1/ServerDHT.ino
@@ -13,30 +13,56 @@
 DHT dht(DHTPIN, DHTTYPE);
 ESP8266WebServer server(80);

-float setTeperature = 0;
-float setHumidity = 0;
+int AIRING_PIN = 4;
+int FURNACE_PIN = 3;
+
+float temperatureToLaunch = 0;
+float humidityToLaunch = 0;
+boolean autoMode = false;
+boolean airing = false;
+boolean furnace = false;

 void handleRoot() {
   server.send(200, "text/plain", "hello from esp8266!");
 }

-void handleNotFound(){
+void handleNotFound() {
   String message = "File Not Found\n\n";
   message += "URI: ";
   message += server.uri();
   message += "\nMethod: ";
-  message += (server.method() == HTTP_GET)?"GET":"POST";
+  message += (server.method() == HTTP_GET) ? "GET" : "POST";
   message += "\nArguments: ";
   message += server.args();
   message += "\n";
-  for (uint8_t i=0; i<server.args(); i++){
+  for (uint8_t i = 0; i < server.args(); i++) {
     message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
   }
   server.send(404, "text/plain", message);
 }

-void setup(void){
+void handlePutCurrentSet() {
+
+  if (server.hasArg("plain") == false) {
+
+    server.send(200, "text/plain", "Body not received");
+    return;
+
+  }
+
+  autoMode = true;
+
+  String message = "Body received:\n";
+  message += server.arg("plain");
+  message += "\n";
+
+  server.send(200, "text/plain", message + " autoMode: " + String(autoMode));
+}
+
+void setup(void) {
   Serial.begin(9600);
+  pinMode(AIRING_PIN, OUTPUT);
+  pinMode(FURNACE_PIN, OUTPUT);
   WiFi.begin(ssid, password);
   Serial.println("");
   dht.begin();
@@ -58,19 +84,50 @@

   server.on("/", handleRoot);

-  server.on("/getCurrentWeather", [](){
-    float h = dht.readHumidity();
-    float t = dht.readTemperature();
-    server.send(200, "text/plain", "{temperature: " + String(t) + ", humidity: " + String(h) + "}");
+  server.on("/getCurrentWeather", []() {
+    float currentHumidity = dht.readHumidity();
+    float currentTemperature = dht.readTemperature();
+    server.send(200, "text/plain", "{temperature: " + String(currentTemperature) + ", humidity: " + String(currentHumidity) + "}");
   });

-  server.on("/getCurrentSet", [](){
-    server.send(200, "text/plain", "{temperature: " + String(setTeperature) + ", humidity: " + String(setHumidity) + "}");
+  server.on("/putCurrentSet", handlePutCurrentSet);
+
+  server.on("/getCurrentSet", []() {
+    server.send(200, "text/plain", "{temperature: " + String(temperatureToLaunch) + ", humidity: " + String(humidityToLaunch) + "}");
   });

-  server.on("/setTemperature/", [](){
-    setTeperature = temperature;
-    server.send(200, "text/plain", "{temperature: " + String(setTeperature) + ", humidity: " + String(setHumidity) + "}");
+  server.on("/getAiring", []() {
+    server.send(200, "text/plain", "{furnace: " + String(airing) + "}" );
+  });
+
+  server.on("/putAiring", []() {
+    autoMode = false;
+    airing = !airing;
+
+    if (airing) {
+      digitalWrite(AIRING_PIN, HIGH);
+    } else {
+      digitalWrite(AIRING_PIN, LOW);
+    }
+
+    server.send(200, "text/plain", "{furnace: " + String(airing) + "}");
+  });
+
+  server.on("/getFurnace", []() {
+    server.send(200, "text/plain", "{furnace: " + String(furnace) + "}" );
+  });
+
+  server.on("/putFurnace", []() {
+    autoMode = false;
+    furnace = !furnace;
+
+    if (furnace) {
+      digitalWrite(FURNACE_PIN, HIGH);
+    } else {
+      digitalWrite(FURNACE_PIN, LOW);
+    }
+
+    server.send(200, "text/plain", "{furnace: " + String(furnace) + "}");
   });

   server.onNotFound(handleNotFound);
@@ -79,7 +136,29 @@
   Serial.println("HTTP server started");
 }

-void loop(void){
+void loop(void) {
   server.handleClient();
+
+  float currentHumidity = dht.readHumidity();
+  float currentTemperature = dht.readTemperature();
+
+  if (autoMode) {
+    if (currentTemperature < temperatureToLaunch) {
+      furnace = true;
+      digitalWrite(FURNACE_PIN, HIGH);
+    } else {
+      furnace = false;
+      digitalWrite(FURNACE_PIN, LOW);
+    }
+
+    if (currentHumidity > humidityToLaunch) {
+      airing = true;
+      digitalWrite(AIRING_PIN, HIGH);
+    } else {
+      airing = false;
+      digitalWrite(AIRING_PIN, LOW);
+    }
+  }
+
 }


Do not hardcode netmask and gateway

Do not hardcode netmask and gateway

--- ESP8266HueEmulator/ESP8266HueEmulator.ino
+++ ESP8266HueEmulator/ESP8266HueEmulator.ino
@@ -44,6 +44,8 @@
 byte mac[6]; // MAC address
 String macString;
 String ipString;
+String netmaskString;
+String gatewayString;

 ESP8266WebServer HTTP(80);

@@ -128,27 +130,20 @@
     aJsonObject* onState = aJson.getObjectItem(parsedRoot, "on");
     bool onValue = onState->valuebool;

+    // Default values in case the request does not send new ones; TODO: Read from pixel instead!
+    int hue = 1;
+    int sat = 1;
+    int bri = 255;
+
+    if (aJsonObject* hueState = aJson.getObjectItem(parsedRoot, "hue"))
+      hue = hueState->valueint;
+    if (aJsonObject* satState = aJson.getObjectItem(parsedRoot, "sat"))
+      sat = satState->valueint;
+    if (aJsonObject* briState = aJson.getObjectItem(parsedRoot, "bri"))
+      bri = briState->valueint;
+
     RgbColor rgb;
-
-    // FIXME: Right now this code crashes the ESP when the hue app is used to change the brightness.
-    // FIXME: The hue app sends only bri and on when one changes the brightness; so we cannot assume there is hue in the request and need to get the hue from somewhere else!
-    if (HTTP.arg("plain").length() > 30 )  // FIXME: Find a cleaner way to do this, can't aJson determine whether a key is present?
-    {
-      Serial.println("REQUEST CONTAINS HUE");
-      aJsonObject* hueState = aJson.getObjectItem(parsedRoot, "hue");
-      int hue = hueState->valueint;
-      aJsonObject* satState = aJson.getObjectItem(parsedRoot, "sat");
-      int sat = satState->valueint;
-      aJsonObject* briState = aJson.getObjectItem(parsedRoot, "bri");
-      int bri = briState->valueint;
-      RgbColor rgb;
-      rgb = hsb2rgb(hue, sat, bri);
-    }
-    else
-    {
-      Serial.println("REQUEST DOES NOT CONTAIN HUE AND WE MIGHT NOT HAVE IT");
-      rgb = white; // FIXME: Where should I get the RGB from in this case? From the pixel... But if it was off then the pixel doesn't know it. Need to maintain a state in the sketch?
-    }
+    rgb = hsb2rgb(hue, sat, bri);

     aJson.deleteItem(parsedRoot);
     Serial.print("I should --> ");
@@ -225,8 +220,10 @@
   }

   macString = String(WiFi.macAddress());
-  ipString = StringIPaddress();
-
+  ipString = StringIPaddress(WiFi.localIP());
+  netmaskString = StringIPaddress(WiFi.subnetMask());
+  gatewayString = StringIPaddress(WiFi.gatewayIP());
+
   Serial.print("Starting HTTP at ");
   Serial.print(WiFi.localIP());
   Serial.print(":");
@@ -302,10 +299,9 @@
   return sub;
 }

-String StringIPaddress()
+String StringIPaddress(IPAddress myaddr)
 {
   String LocalIP = "";
-  IPAddress myaddr = WiFi.localIP();
   for (int i = 0; i < 4; i++)
   {
     LocalIP += String(myaddr[i]);
@@ -318,15 +314,15 @@
 {
   aJson.addStringToObject(root, "name", "Philips hue");
   aJson.addStringToObject(root, "swversion", "01005215");
-  aJson.addBooleanToObject(root, "portalservices", false);
-  aJson.addStringToObject(root, "zigbeechannel", "0"); // As per spec, 0 is allowed
+  // aJson.addBooleanToObject(root, "portalservices", false);
+  // aJson.addStringToObject(root, "zigbeechannel", "0"); // As per spec, 0 is allowed
   aJson.addStringToObject(root, "mac", macString.c_str());
   aJson.addBooleanToObject(root, "dhcp", true);
   aJson.addStringToObject(root, "ipaddress", ipString.c_str());
-  aJson.addStringToObject(root, "netmask", "255.255.255.0"); // TODO: FIXME
-  aJson.addStringToObject(root, "gateway", "192.168.0.1"); // TODO: FIXME
-  aJson.addStringToObject(root, "proxyaddress", "");
-  aJson.addNumberToObject(root, "proxyport", 0);
+  aJson.addStringToObject(root, "netmask", netmaskString.c_str());
+  aJson.addStringToObject(root, "gateway", gatewayString.c_str());
+  // aJson.addStringToObject(root, "proxyaddress", ""); // Seems not required by client app
+  // aJson.addNumberToObject(root, "proxyport", 0); // Seems not required by client app
   aJson.addStringToObject(root, "UTC", "2012-10-29T12:05:00");
   aJsonObject *whitelist;
   aJson.addItemToObject(root, "whitelist", whitelist = aJson.createObject());
@@ -338,7 +334,7 @@
   aJsonObject *swupdate;
   aJson.addItemToObject(root, "swupdate", swupdate = aJson.createObject());
   aJson.addStringToObject(swupdate, "text", "");
-  aJson.addBooleanToObject(swupdate, "notify", false);
+  aJson.addBooleanToObject(swupdate, "notify", false); // Otherwise client app shows update notice
   aJson.addNumberToObject(swupdate, "updatestate", 0);
   aJson.addStringToObject(swupdate, "url", "");
 }


add vector to compassReading on line 505

--- Flora_NeoGeo_Watch/Flora_NeoGeo_Watch.ino
+++ Flora_NeoGeo_Watch/Flora_NeoGeo_Watch.ino
@@ -502,7 +502,7 @@
   if (millis() - compassTimer > 50) {
     compassTimer = millis(); // reset the timer
     compass.read();
-    compassReading = compass.heading((LSM303::vector){0,-1,0});
+    compassReading = compass.heading((LSM303::vector<int>){0,-1,0});
     }
 }


updated readout on server side

updated readout on server side

--- software/RF/server_w_address/RF_comms.ino
+++ software/RF/server_w_address/RF_comms.ino
@@ -14,10 +14,10 @@
     uint8_t from;
     if (manager.recvfromAck(buf, &len, &from))
     {
-      Serial.print("got request from : 0x");
-      Serial.print(from,HEX);
+  //    Serial.print("got request from : 0x");
+      Serial.print(from,DEC);
       Serial.print(": ");
-      Serial.println((char*)buf);
+ //     Serial.println((char*)buf);
       for (int i=0; i<sizeof(buf); i++){Serial.print(buf[i],DEC);Serial.print(",");}
       Serial.print("\r\n");
       String message="Hello back client " + String(from);


Optimization and C-like syntax

Optimization and C-like syntax

--- src/sketch.ino
+++ src/sketch.ino
@@ -15,291 +15,247 @@
 #include <Adafruit_NeoPixel.h>

 // Pin definitions
-const int		pixelPin = 2;
-const int		sw1Pin = 8;
-const int		sw2Pin = 11;
+#define		pixpin 2
+#define		sw1pin 8
+#define		sw2pin 11

 // Global constants
-const int		modes = 4;					// Number of modes - static
-const int		numPixels = 13;				// Number of pixels - static
-const int		maxBrightness = 255;
-const int		minBrightness = 0;
-const int		minColorIntensity = 150;	// When randomly selecting color
-
-const bool		moreRandom = true;			// Set to true for more color change
-
-// 'Worm' mode constants
-const int		wormInterval = 300;			// Worm speed
-const int		wormLength = 4;				// Worm length in pixels
-
-// 'Flame' mode constants
-const int		flameIntervalMin = 60;		// Maximal flame speed
-const int		flameIntervalMax = 130;		// Minimal flame speed
-
-// 'Glow' mode constants
-const int		glowInterval = 50;			// Glow speed
-const int		glowDivMin = 2;				// Lowest glow level
-const int		glowDivMax = 50;			// Highest glow level
-const int		glowDivDiff = 2;			// Difference per pixel and cycle
-const int		glowMultiplier = 100;		// Avoid floating point calculations
-
-// 'Increase' mode constants
-const int		increaseInterval = 200;		// Increase / decrease speed
-
-// 'Twinkle' mode constants
-const int		twinkleInterval = 10;		// Twinkle speed
-const int		twinklePauseInterval = 100;	// Time to pause at max and min
-
-// Switch states
-bool			sw1Read, sw2Read;
-
-// Variable declarations
-int				currentMode = 1, previousMode = 2;
-int				currentBrightness = maxBrightness;
-int				color1, color2, color3;
-int				wormStartPixel = 0;
-int				ledNumber;
-int				increaseLength;
-int				twinkleCurrentPixel;
-int				flameInterval;
-int				glowDiv[numPixels];
-
-bool			glowIncrease, glowDoChange;
-bool			increaseDirection = true;
-bool			twinkleIncrease = true;
-bool			twinklePause = true;
+#define		numpx 13
+#define		maxbr 255
+#define		minbr 0
+#define		mincolorint 150
+#define		mrand true
+
+// Global variables
+int			cmode, pmode = 0;
+int			curbr = maxbr;
+int			r, g, b;
+int			wspix = 0;
+int			inclen;
+int			cpix;
+int			finterval;
+int			gdiv[numpx];
+
+bool		incdir = true;
+bool		twincr = true;
+bool		twpause = true;

 // Color schemes
-enum			color {
-					rnd, off, white,
-					warmwhite, red, green,
-					blue, yellow, orange
-				};
+enum		color {
+				rnd, off, white,
+				warmwhite, red, green,
+				blue, yellow, orange
+			};

 // Timers
 unsigned long	timer;

-Adafruit_NeoPixel strip = Adafruit_NeoPixel(numPixels, pixelPin, NEO_GRB + NEO_KHZ800);
-
-int readSensors() {
+Adafruit_NeoPixel strip = Adafruit_NeoPixel(numpx, pixpin, NEO_GRB + NEO_KHZ800);
+
+int getmode() {

 	int mode = 0;

-	sw1Read = digitalRead(sw1Pin);
-	sw2Read = digitalRead(sw2Pin);
-
-	if(!sw1Read && !sw2Read) mode = 1;
-	if(sw1Read && !sw2Read) mode = 2;
-	if(!sw1Read && sw2Read) mode = 3;
-	if(sw1Read && sw2Read) mode = 4;
+	bool sw1 = digitalRead(sw1pin);
+	bool sw2 = digitalRead(sw2pin);
+
+	if(!sw1 && !sw2) mode = 1;
+	else if(sw1 && !sw2) mode = 2;
+	else if(!sw1 && sw2) mode = 3;
+	else if(sw1 && sw2) mode = 4;

 	return mode;
 }

-void setColor(int color) {
+// TODO: Convert to switch
+void setcol(int color) {

 	if(color == rnd) {
-		color1 = random(1,255);
-		color2 = random(1,255);
-		color3 = random(1,255);
-
-		if((color1 + color2 + color3) < minColorIntensity) setColor(rnd);
-	}
-
-	else if(color == white) { color1 = 255; color2 = 255; color3 = 255; }
-	else if(color == warmwhite) { color1 = 255; color2 = 147; color3 = 41; }
-	else if(color == red) { color1 = 255; color2 = 0; color3 = 0; }
-	else if(color == green) { color1 = 0; color2 = 255; color3 = 0; }
-	else if(color == blue) { color1 = 0; color2 = 0; color3 = 255; }
-	else if(color == yellow) { color1 = 255; color2 = 255; color3 = 0; }
-	else if(color == orange) { color1 = 255; color2 = 128; color3 = 0; }
-	else { color1 = 0; color2 = 0; color3 = 0; }
-}
-
-void setAll(int color, int brightness) {
-
-	if(currentMode != previousMode) {
-		setColor(color);
-		for(int a = 0; a < numPixels; a++) {
-			strip.setPixelColor(a, color1, color2, color3);
-		}
+		r = random(1,255);
+		g = random(1,255);
+		b = random(1,255);
+
+		if((r + g + b) < mincolorint) setcol(rnd);
+	}
+	else if(color == white) { r = 255; g = 255; b = 255; }
+	else if(color == warmwhite) { r = 255; g = 147; b = 41; }
+	else if(color == red) { r = 255; g = 0; b = 0; }
+	else if(color == green) { r = 0; g = 255; b = 0; }
+	else if(color == blue) { r = 0; g = 0; b = 255; }
+	else if(color == yellow) { r = 255; g = 255; b = 0; }
+	else if(color == orange) { r = 255; g = 128; b = 0; }
+	else { r = 0; g = 0; b = 0; }
+}
+
+void setall(int color, int brightness) {
+
+	if(cmode != pmode) {
+		setcol(color);
+		for(int a = 0; a < numpx; a++) strip.setPixelColor(a, r, g, b);
 		strip.setBrightness(brightness);
 		strip.show();
-		previousMode = currentMode;
-	}
-}
-
-void worm(int color) {
-
-	if(currentMode != previousMode) { setColor(color); previousMode = currentMode; }
-
-	if(millis() > timer + wormInterval) {
-
-		for(int a=0; a < numPixels; a++) { strip.setPixelColor(a,0,0,0); }
-		for(int b=wormStartPixel; b < wormStartPixel + wormLength; b++) {
-			if(b >= numPixels) ledNumber = b - numPixels;
-			else ledNumber = b;
-
-			strip.setPixelColor(ledNumber, color1, color2, color3);
-		}
-
-		strip.setBrightness(maxBrightness);
-		strip.show();
-
-		wormStartPixel++;
-		if(wormStartPixel >= numPixels) wormStartPixel = 0;
-		timer = millis();
-	}
-}
-
-void flame(int color) {
-
-	if(currentMode != previousMode) {
-		setColor(color);
-		previousMode = currentMode;
-		flameInterval = random(flameIntervalMin, flameIntervalMax);
-	}
-
-	if(millis() > timer + flameInterval) {
-		for(int a=0; a < numPixels; a++) {
-			strip.setPixelColor(a, color1, color2, color3);
-		}
-		strip.setBrightness(random(minBrightness,maxBrightness));
-		strip.show();
-		flameInterval = random(flameIntervalMin, flameIntervalMax);
-		timer = millis();
-	}
-}
-
-void increase(int color) {
-
-	if(currentMode != previousMode) {
-		setColor(color);
-		currentBrightness = maxBrightness;
-		increaseLength = 1;
-		previousMode = currentMode;
-	}
-
-	if(millis() > timer + increaseInterval && increaseDirection) {
-		for(int a=0; a < numPixels; a++) { strip.setPixelColor(a, 0, 0, 0); }
-
-		for(int a=0; a < increaseLength; a++) {
-			strip.setPixelColor(a, color1, color2, color3);
-		}
-
-		increaseLength++;
-		if(increaseLength >= numPixels) {
-			increaseLength = 1;
-			increaseDirection = !increaseDirection;
-		}
-
-		strip.setBrightness(currentBrightness);
-		strip.show();
-		timer = millis();
-	}
-
-	if(millis() > timer + increaseInterval && !increaseDirection) {
-
-		for(int a=0; a < numPixels; a++) {
-			strip.setPixelColor(a, color1, color2, color3);
-		}
-
-		for(int a=0; a < increaseLength; a++) { strip.setPixelColor(a, 0, 0, 0); }
-
-		increaseLength++;
-
-		if(increaseLength >= numPixels) {
-			increaseLength = 1;
-			increaseDirection = !increaseDirection;
-			if(color == rnd && moreRandom) setColor(color);
-		}
-
-		strip.setBrightness(currentBrightness);
-		strip.show();
-		timer = millis();
-	}
-}
-
-void twinkle(int color) {
-
-	if(currentMode != previousMode) {
-		setColor(color);
-		twinkleCurrentPixel = random(0, numPixels);
-		currentBrightness = minBrightness;
-		for(int a=0; a < numPixels; a++) { strip.setPixelColor(a, 0, 0, 0); }
-		strip.setBrightness(currentBrightness);
-		strip.show();
-		previousMode = currentMode;
-	}
-
-	if(millis() > timer + twinkleInterval && twinkleIncrease && !twinklePause) {
-		currentBrightness++;
-
-		strip.setPixelColor(twinkleCurrentPixel, color1, color2, color3);
-		strip.setBrightness(currentBrightness);
-		strip.show();
-
-		if(currentBrightness >= maxBrightness) { twinklePause = true; }
-		timer = millis();
-	}
-
-	if(millis() > timer + twinklePauseInterval && twinkleIncrease && twinklePause) {
-		twinklePause = false;
-		twinkleIncrease = false;
-		timer = millis();
-	}
-
-	if(millis() > timer + twinkleInterval && !twinkleIncrease && !twinklePause) {
-		currentBrightness--;
-
-		strip.setPixelColor(twinkleCurrentPixel, color1, color2, color3);
-		strip.setBrightness(currentBrightness);
-		strip.show();
-
-		if(currentBrightness <= minBrightness) { twinklePause = true; }
-		timer = millis();
-	}
-
-	if(millis() > timer + twinklePauseInterval && !twinkleIncrease && twinklePause) {
-		twinklePause = false;
-		twinkleIncrease = true;
-		twinkleCurrentPixel = random(0,numPixels);
-		if(color == rnd && moreRandom) setColor(color);
-		timer = millis();
-	}
-}
-
-void glow(int color) {
-
-	if(millis() > timer + glowInterval) {
-
-		if(currentMode != previousMode) {
-			setColor(color);
-			previousMode = currentMode;
-		}
-
-		for(int a=0; a < numPixels; a++) {
-
-			glowIncrease = random(2);
-			glowDoChange = random(2);
-
-			if(glowIncrease && glowDoChange) {
-				glowDiv[a] = glowDiv[a] + glowDivDiff;
-				if(glowDiv[a] > glowDivMax) glowDiv[a] = glowDivMax;
+		pmode = cmode;
+	}
+}
+
+// Default: (col), 4, 300
+void worm(int color, int len, int interval) {
+
+	if(cmode != pmode) setcol(color); pmode = cmode;
+
+	if(millis() > timer + interval) {
+
+		for(int a = 0; a < numpx; a++) strip.setPixelColor(a, 0, 0, 0);
+
+		for(int b = wspix; b < wspix + len; b++) {
+			if(b >= numpx) strip.setPixelColor(b - numpx, r, g, b);
+			else strip.setPixelColor(b, r, g, b);
+		}
+
+		strip.setBrightness(maxbr);
+		strip.show();
+
+		if(++wspix >= numpx) wspix = 0;
+		timer = millis();
+	}
+}
+
+// Default: (col), 60, 130
+void flame(int color, int minint, int maxint) {
+
+	if(cmode != pmode) {
+		setcol(color);
+		pmode = cmode;
+		finterval = random(minint, maxint);
+	}
+
+	if(millis() > timer + finterval) {
+		for(int a = 0; a < numpx; a++) strip.setPixelColor(a, r, g, b);
+		strip.setBrightness(random(minbr, maxbr));
+		strip.show();
+		finterval = random(minint, maxint);
+		timer = millis();
+	}
+}
+
+// Default: (col), 200
+void increase(int color, int interval) {
+
+	if(cmode != pmode) {
+		setcol(color);
+		curbr = maxbr;
+		inclen = 1;
+		pmode = cmode;
+	}
+
+	if(millis() > timer + interval && incdir) {
+		for(int a = 0; a < numpx; a++) strip.setPixelColor(a, 0, 0, 0);
+		for(int a = 0; a < inclen; a++) strip.setPixelColor(a, r, g, b);
+
+		if(++inclen >= numpx) {
+			inclen = 1;
+			incdir = !incdir;
+		}
+
+		strip.setBrightness(curbr);
+		strip.show();
+		timer = millis();
+	}
+
+	if(millis() > timer + interval && !incdir) {
+		for(int a = 0; a < numpx; a++) strip.setPixelColor(a, r, g, b);
+		for(int a = 0; a < inclen; a++) strip.setPixelColor(a, 0, 0, 0);
+
+		if(++inclen >= numpx) {
+			inclen = 1;
+			incdir = !incdir;
+			if(color == rnd && mrand) setcol(color);
+		}
+
+		strip.setBrightness(curbr);
+		strip.show();
+		timer = millis();
+	}
+}
+
+// Default: (col), 10, 100
+void twinkle(int color, int interval, int pinterval) {
+
+	if(cmode != pmode) {
+		setcol(color);
+		cpix = random(0, numpx);
+		curbr = minbr;
+		for(int a = 0; a < numpx; a++) strip.setPixelColor(a, 0, 0, 0);
+		strip.setBrightness(curbr);
+		strip.show();
+		pmode = cmode;
+	}
+
+	if(millis() > timer + interval && twincr && !twpause) {
+		strip.setPixelColor(cpix, r, g, b);
+		strip.setBrightness(++curbr);
+		strip.show();
+
+		if(curbr >= maxbr) twpause = true;
+		timer = millis();
+	}
+
+	if(millis() > timer + pinterval && twincr && twpause) {
+		twpause = false;
+		twincr = false;
+		timer = millis();
+	}
+
+	if(millis() > timer + interval && !twincr && !twpause) {
+		strip.setPixelColor(cpix, r, g, b);
+		strip.setBrightness(--curbr);
+		strip.show();
+
+		if(curbr <= minbr) twpause = true;
+		timer = millis();
+	}
+
+	if(millis() > timer + pinterval && !twincr && twpause) {
+		twpause = false;
+		twincr = true;
+		cpix = random(0, numpx);
+		if(color == rnd && mrand) setcol(color);
+		timer = millis();
+	}
+}
+
+// Default: (col), 50, 2, 2, 50
+void glow(int color, int interval, int change, int mindiv, int maxdiv) {
+
+	if(millis() > timer + interval) {
+
+		if(cmode != pmode) {
+			setcol(color);
+			pmode = cmode;
+		}
+
+		for(int a = 0; a < numpx; a++) {
+
+			bool incr = random(2);
+			bool dochng = random(2);
+
+			if(incr && dochng) {
+				gdiv[a] = gdiv[a] + change;
+				if(gdiv[a] > maxdiv) gdiv[a] = maxdiv;
 			}

-			else if (!glowIncrease && glowDoChange) {
-				glowDiv[a] = glowDiv[a] - glowDivDiff;
-				if(glowDiv[a] < glowDivMin) glowDiv[a] = glowDivMin;
+			else if(!incr && dochng) {
+				gdiv[a] = gdiv[a] - change;
+				if(gdiv[a] < mindiv) gdiv[a] = mindiv;
 			}

 			strip.setPixelColor(a,
-			(color1 * glowDiv[a]) / glowMultiplier,
-			(color2 * glowDiv[a]) / glowMultiplier,
-			(color3 * glowDiv[a]) / glowMultiplier);
-		}
-
-		strip.setBrightness(maxBrightness);
+			(r * gdiv[a]) / 100,
+			(g * gdiv[a]) / 100,
+			(b * gdiv[a]) / 100);
+		}
+
+		strip.setBrightness(maxbr);
 		strip.show();
 		timer = millis();
 	}
@@ -312,17 +268,17 @@
 	strip.begin();
 	strip.show();

-	pinMode(pixelPin, OUTPUT);
-	pinMode(sw1Pin, INPUT_PULLUP);
-	pinMode(sw2Pin, INPUT_PULLUP);
+	pinMode(pixpin, OUTPUT);
+	pinMode(sw1pin, INPUT_PULLUP);
+	pinMode(sw2pin, INPUT_PULLUP);
 }

 void loop() {

-	currentMode = readSensors();
-
-	if(currentMode == 1) setAll(warmwhite, 255);
-	if(currentMode == 2) setAll(rnd, 150);
-	if(currentMode == 3) glow(red);
-	if(currentMode == 4) twinkle(rnd);
-}
+	cmode = getmode();
+
+	if(cmode == 1) setall(warmwhite, 255);
+	if(cmode == 2) setall(rnd, 150);
+	if(cmode == 3) glow(red, 50, 2, 2, 50);
+	if(cmode == 4) twinkle(rnd, 10, 100);
+}


I added a new Interruption_Mode

I added a new Interruption_Mode

We have now two Interrupts, the "bite_int" (INT1 -> Pin3)that it call to
"AlarmMode" function, and "menu_int" (INT0 ->Pin2) that it call to
"MenuToggle" function.

--- code/bite_alarm/bite_alarm.ino
+++ code/bite_alarm/bite_alarm.ino
@@ -16,7 +16,8 @@
 //
 #define increasePin  0 // pin in which + button will be connected
 #define decreasePin  0 // pin in which - button will be connected
-#define menuPin      0 // pin in which menu button will be connected
+#define menu_int     2 // pin in which menu button will be connected (INT0)
+#define bite_int   3 // pin in which the encoder will be connected (INT1)

 bool menuStatus; // this bool stores the menu toggle status 1 stands for Volume and 0 for Sensitivity

@@ -33,7 +34,8 @@
 void setup() {
   pinMode(increasePin, INPUT_PULLUP);
   pinMode(decreasePin, INPUT_PULLUP);
-  pinMode(menuPin, INPUT_PULLUP);
+  pinMode(menu_int, INPUT_PULLUP);
+  pinMode(bite_int, INPUT_PULLUP);
   pinMode(volLedP,OUTPUT);
   pinMode(sensLedP,OUTPUT);
   pinMode(eventLedP,OUTPUT);
@@ -45,9 +47,9 @@
   volume.value      = EEPROM.read(volume.address);
   sensitivity.value = EEPROM.read(sensitivity.address);

-  attachInterrupt(digitalPinToInterrupt(increasePin), increase, FALLING);  //when an interruption occurs on falling edge (it's pulled up) system calls increase
-  attachInterrupt(digitalPinToInterrupt(increasePin), decrease, FALLING);  //when an interruption occurs on falling edge (it's pulled up) system calls decrease
-  attachInterrupt(digitalPinToInterrupt(increasePin), toggleMenu, FALLING);  //when an interruption occurs on falling edge (it's pulled up) system calls toggleMenu
+
+  attachInterrupt(digitalPinToInterrupt(menu_int), toggleMenu, FALLING);  //when an interruption occurs on falling edge (it's pulled up) system calls toggleMenu
+  attachInterrupt(digitalPinToInterrupt(bite_int), alarmMode, RISING); // when an interruption occurs on RISING edge system calls alarmMode function.

 }

@@ -100,6 +102,9 @@
   }
 }

+void alarmMode(){
+
+
+}

-


added grafic for thermometer, waitingsymbol

--- arduino/slavenode_Innenthermometer/slavenode_Innenthermometer.ino
+++ arduino/slavenode_Innenthermometer/slavenode_Innenthermometer.ino
@@ -6,7 +6,7 @@
 // Define a valid radiochannel here
 #define RADIOCHANNEL 90
 // This node: Use octal numbers starting with "0": "041" is child 4 of node 1
-#define NODE 03
+#define NODE 04
 // The CE Pin of the Radio module
 #define RADIO_CE_PIN 10
 // The CS Pin of the Radio module
@@ -30,6 +30,18 @@
 #define U4 3.9
 // How many cycles do we stay awake on network activity
 #define STAYAWAKEDEFAULT 20
+// set X0 and Y0 of battery symbol ( is 10 * 5 pixel )
+#define BATT_X0 74
+#define BATT_Y0 0
+// set X0 and Y0 of antenna symbol ( is 10 * 10 pixel )
+#define ANT_X0 74
+#define ANT_Y0 6
+// set X0 and Y0 of thermometer symbol ( is 3 * 6 pixel )
+#define THERM_X0 74
+#define THERM_Y0 17
+// set X0 and Y0 of waiting symbol ( is 6 * 6 pixel )
+#define WAIT_X0 78
+#define WAIT_Y0 17

 // ------ End of configuration part ------------

@@ -78,6 +90,7 @@

 unsigned int sleeptime = 0;
 int init_loop_counter = 0;
+int free_loop_counter = 0;
 boolean init_finished = false;
 boolean init_transmit = true;
 boolean network_busy = false;
@@ -96,10 +109,9 @@
       case 1: {
         // Temperature
         txheader.type=1;
-        sensors.requestTemperatures(); // Send the command to get temperatures
-        temp=sensors.getTempCByIndex(0);
-        payload.value=temp;
-        network.write(txheader,&payload,sizeof(payload));
+        payload.value=get_temp();
+        network.write(txheader,&payload,sizeof(payload));
+        free_loop_counter = 0;
        break; }
       case 21:
         // Set field 1
@@ -138,7 +150,7 @@
       case 101:
       // battery voltage
         payload.value=read_battery_voltage();
-        draw_battery(74,1,payload.value);
+        draw_battery(BATT_X0,BATT_Y0,payload.value);
         txheader.type=101;
         network.write(txheader,&payload,sizeof(payload));
         break;
@@ -183,10 +195,8 @@
   myGLCD.setContrast(65);
   myGLCD.clrScr();
   sensors.begin();
-  sensors.requestTemperatures();
-  float temp=sensors.getTempCByIndex(0);
-  draw_temp(temp);
-  draw_battery(74,1,read_battery_voltage());
+  get_temp();
+  draw_battery(BATT_X0, BATT_Y0,read_battery_voltage());
   //####
   // end aditional init
   //####
@@ -216,7 +226,20 @@
   }
   digitalWrite(STATUSLED,STATUSLED_OFF);
   network_busy=true;
-  draw_antenna(74,10);
+  draw_antenna(ANT_X0, ANT_Y0);
+}
+
+void draw_therm(byte x, byte y) {
+  myGLCD.drawRect(x+1,y,x+1,y+3);
+  myGLCD.drawRect(x,y+4,x+2,y+5);
+}
+
+void wipe_therm(byte x, byte y) {
+  for (byte i=x; i<x+3; i++) {
+    for (byte j=y; j<y+6; j++) {
+      myGLCD.clrPixel(i,j);
+    }
+  }
 }

 void draw_temp(float t) {
@@ -261,20 +284,30 @@
   return vmess / VOLTAGEDIVIDER;
 }

+float get_temp(void) {
+  float temp;
+  draw_therm(THERM_X0, THERM_Y0);
+  sensors.requestTemperatures(); // Send the command to get temperatures
+  temp=sensors.getTempCByIndex(0);
+  draw_temp(temp);
+  wipe_therm(THERM_X0, THERM_Y0);
+  return temp;
+}
+
 void print_field(float val, int field) {
   int x0, y0;
   switch (field) {
     case 1: x0=0; y0=25; break;
-    case 2: x0=41; y0=25; break;
+    case 2: x0=42; y0=25; break;
     case 3: x0=0; y0=36; break;
-    case 4: x0=41; y0=36; break;
-  }
-  for (int i=x0; i < x0+43; i++) {
+    case 4: x0=42; y0=36; break;
+  }
+  for (int i=x0; i < x0+42; i++) {
     for (int j=y0; j< y0+12; j++) {
       myGLCD.clrPixel(i,j);
     }
   }
-  myGLCD.drawRect(x0,y0,x0+42,y0+11);
+  myGLCD.drawRect(x0,y0,x0+41,y0+11);
   myGLCD.setFont(SmallFont);
   if ( val > 100 ) {
     if (val+0.5 > 1000) {
@@ -302,23 +335,17 @@
 }

 void draw_battery(int x, int y, float u) {
+  // Clear the drawing field
+  for (byte i=x; i<=x+9; i++) {
+    for (byte j=y; j<=y+5; j++) {
+      myGLCD.clrPixel(i,j);
+    }
+  }
   // Drawing a symbol of an battery
-  // Size: 10x4 pixel
+  // Size: 10x5 pixel
   // at position x and y
-  for (byte i=x+2; i <= x+9; i++) {
-    myGLCD.setPixel(i,y);
-    myGLCD.setPixel(i,y+4);
-  }
-  myGLCD.setPixel(x,y+1);
-  myGLCD.setPixel(x,y+2);
-  myGLCD.setPixel(x,y+3);
-  myGLCD.setPixel(x+1,y+1);
-  myGLCD.setPixel(x+1,y+2);
-  myGLCD.setPixel(x+1,y+3);
-  myGLCD.setPixel(x+9,y+1);
-  myGLCD.setPixel(x+9,y+2);
-  myGLCD.setPixel(x+9,y+3);
-  myGLCD.clrRect(x+2,y+1,x+8,y+3);
+  myGLCD.drawRect(x+2,y,x+9,y+4);
+  myGLCD.drawRect(x,y+1,x+1,y+3);
   if ( u > U1 ) draw_battery_filled(x+8,y+1); else myGLCD.drawLine(x+3,y,x+7,y+4);
   if ( u > U2 ) draw_battery_filled(x+6,y+1);
   if ( u > U3 ) draw_battery_filled(x+4,y+1);
@@ -379,15 +406,38 @@
    myGLCD.update();
 }

+void draw_wait(byte x, byte y, int waitcount ) {
+  for (byte i=x; i<x+6; i++) {
+    for(byte j=y; j<y+6; j++) {
+      myGLCD.clrPixel(i,j);
+    }
+  }
+  if (waitcount > 1) myGLCD.setPixel(x+3,y+2);
+  if (waitcount > 2) myGLCD.setPixel(x+3,y+3);
+  if (waitcount > 3) myGLCD.setPixel(x+2,y+3);
+  if (waitcount > 4) myGLCD.setPixel(x+2,y+2);
+  if (waitcount > 5) myGLCD.setPixel(x+3,y  );
+  if (waitcount > 6) myGLCD.setPixel(x+4,y+1);
+  if (waitcount > 7) myGLCD.setPixel(x+5,y+2);
+  if (waitcount > 8) myGLCD.setPixel(x+5,y+3);
+  if (waitcount > 9) myGLCD.setPixel(x+4,y+4);
+  if (waitcount > 10) myGLCD.setPixel(x+3,y+5);
+  if (waitcount > 11) myGLCD.setPixel(x+2,y+5);
+  if (waitcount > 12) myGLCD.setPixel(x+1,y+4);
+  if (waitcount > 13) myGLCD.setPixel(x  ,y+3);
+  if (waitcount > 14) myGLCD.setPixel(x  ,y+2);
+  if (waitcount > 15) myGLCD.setPixel(x+1,y+1);
+  if (waitcount > 16) myGLCD.setPixel(x+2,y  );
+}
+
 void loop(void) {
   if (network.update()) {
     network_busy = true;
     stayawakeloopcount=0;
   }
   if ( ! network_busy ) {
-    sensors.requestTemperatures(); // Send the command to get temperatures
-    temp=sensors.getTempCByIndex(0);
-    draw_temp(temp);
+    // save energy get the temperature every 10. loop (with sleeptime 1min => every 10min)
+    if (free_loop_counter == 11) get_temp();
   }
   if ( network.available() ) {
     network_busy = true;
@@ -403,15 +453,17 @@
     sleep4ms(100);
     stayawakeloopcount++;
   } else {
+    draw_wait(WAIT_X0, WAIT_Y0, free_loop_counter);
     if ( radiomode == radio_sleep ) {
       radio.powerDown();
-      wipe_antenna(74,10);
+      wipe_antenna(ANT_X0, ANT_Y0);
     }
     sleep4ms(sleeptime * 1000);
     if ( radiomode == radio_sleep ) {
       radio.powerUp();
     }
-    draw_antenna(74,10);
-    sleep4ms(500);
+    draw_antenna(ANT_X0, ANT_Y0);
+    sleep4ms(1000);
+    free_loop_counter++;
   }
 }


changed colors and rewired rgb

changed colors and rewired rgb

--- circadian_hallway_cycle_colors/circadian_hallway_cycle_colors.ino
+++ circadian_hallway_cycle_colors/circadian_hallway_cycle_colors.ino
@@ -1,6 +1,6 @@
-#define GRN_PIN 5
+#define GRN_PIN 9
 #define RED_PIN 6
-#define BLU_PIN 9
+#define BLU_PIN 5

 byte RED, GREEN, BLUE;
 byte RED_A = 0;
@@ -19,48 +19,48 @@
 boolean is_using_morning_colors = true;

 //Evening colors defined here
-#define E_C1_R 200
-#define E_C1_G 10
+#define E_C1_R 255
+#define E_C1_G 61
 #define E_C1_B 0

-#define E_C2_R 225
-#define E_C2_G 20
+#define E_C2_R 255
+#define E_C2_G 10
 #define E_C2_B 0

-#define E_C3_R 255
-#define E_C3_G 40
+#define E_C3_R 100
+#define E_C3_G 25
 #define E_C3_B 0

-#define E_C4_R 245
-#define E_C4_G 30
+#define E_C4_R 150
+#define E_C4_G 10
 #define E_C4_B 0

-#define E_C5_R 150
-#define E_C5_G 10
+#define E_C5_R 200
+#define E_C5_G 50
 #define E_C5_B 0

 #define E_MAX_COLOR_DIFFERENCE 105

 //Morning colors defined here
-#define M_C1_R 145
-#define M_C1_G 13
-#define M_C1_B 200
-
-#define M_C2_R 72
-#define M_C2_G 12
-#define M_C2_B 200
-
-#define M_C3_R 255
-#define M_C3_G 255
+#define M_C1_R 50
+#define M_C1_G 50
+#define M_C1_B 50
+
+#define M_C2_R 20
+#define M_C2_G 20
+#define M_C2_B 20
+
+#define M_C3_R 150
+#define M_C3_G 150
 #define M_C3_B 150

-#define M_C4_R 50
-#define M_C4_G 90
-#define M_C4_B 150
-
-#define M_C5_R 13
-#define M_C5_G 140
-#define M_C5_B 200
+#define M_C4_R 100
+#define M_C4_G 100
+#define M_C4_B 100
+
+#define M_C5_R 255
+#define M_C5_G 255
+#define M_C5_B 255

 #define M_MAX_COLOR_DIFFERENCE 243


updated Fri 02/17/2017 11:34:12.69

updated Fri 02/17/2017 11:34:12.69

--- rtc-relay-static.ino
+++ rtc-relay-static.ino
@@ -25,7 +25,7 @@
 #include <WiFiUdp.h>
 //Local libraries
 #include "constants.h"
-#include "Wi-Fi-Config.h"
+#include "wi-fi-config.h"

 //============================================================
 // USER CONFIGURABLE OPTIONS