Format Code

Format Code

--- monitor_client/monitor_client.ino
+++ monitor_client/monitor_client.ino
@@ -11,65 +11,61 @@

 void setup(){

-  Serial.begin(9600);
-  Serial.print("Temperature (oC): ");
-  Serial.println((float)DHT11.temperature, 2);
-  Serial.print("Humidity (%): ");
-  Serial.println((float)DHT11.humidity, 2);
-  //snprintf(http_cmd,sizeof(http_cmd),"GET monitor.ourjnu.com/submit.php?device_index=13726247339&longitude=113.540718&latitude=22.256467&temperature=%03d&humidity=%03d&particulate_matter=25 HTTP/1.0\r\n\r\n",DHT11.temperature,DHT11.humidity);
-  //sprintf(http_cmd,"GET /submit.php?device_index=13726247339&longitude=113.540718&latitude=22.256467&temperature=%03d&humidity=%03d&particulate_matter=25 HTTP/1.0\r\n\r\n",DHT11.temperature,DHT11.humidity);
-  //Serial.println(http_cmd);
-  //Use rewrited url to prevent memory overflow
-  snprintf(target_url, sizeof(target_url), "GET /13726247339-113.540718-22.256467-%03d-%03d-25 HTTP/1.0\r\n\r\n",DHT11.temperature,DHT11.humidity);
-  Serial.println(target_url);
+	Serial.begin(9600);
+	Serial.print("Temperature (oC): ");
+	Serial.println((float)DHT11.temperature, 2);
+	Serial.print("Humidity (%): ");
+	Serial.println((float)DHT11.humidity, 2);
+	//snprintf(http_cmd,sizeof(http_cmd),"GET monitor.ourjnu.com/submit.php?device_index=13726247339&longitude=113.540718&latitude=22.256467&temperature=%03d&humidity=%03d&particulate_matter=25 HTTP/1.0\r\n\r\n",DHT11.temperature,DHT11.humidity);
+	//sprintf(http_cmd,"GET /submit.php?device_index=13726247339&longitude=113.540718&latitude=22.256467&temperature=%03d&humidity=%03d&particulate_matter=25 HTTP/1.0\r\n\r\n",DHT11.temperature,DHT11.humidity);
+	//Serial.println(http_cmd);
+	//Use rewrited url to prevent memory overflow
+	snprintf(target_url, sizeof(target_url), "GET /13726247339-113.540718-22.256467-%03d-%03d-25 HTTP/1.0\r\n\r\n",DHT11.temperature,DHT11.humidity);
+	Serial.println(target_url);

- gprs.init();
-  // attempt DHCP
-  while(false == gprs.join()) {
-      Serial.println("gprs join network error");
-      delay(2000);
-  }
+	gprs.init();
+	// attempt DHCP
+	while(false == gprs.join()) {
+		Serial.println("gprs join network error");
+		delay(2000);
+	}

-  // successful DHCP
-  Serial.print("IP Address is ");
-  Serial.println(gprs.getIPAddress());
+	// successful DHCP
+	Serial.print("IP Address is ");
+	Serial.println(gprs.getIPAddress());

-  if(false == gprs.connect(TCP,"monitor.ourjnu.com", 80)) {
-      Serial.println("connect error");
-  }else{
-      Serial.println("connect monitor.ourjnu.com success");
-  }
+	if(false == gprs.connect(TCP,"monitor.ourjnu.com", 80)) {
+		Serial.println("connect error");
+		}else{
+		Serial.println("connect monitor.ourjnu.com success");
+	}

-  Serial.println("waiting to fetch...");
-  gprs.send(target_url, sizeof(target_url)-1);
-  while (true) {
-      int ret = gprs.recv(buffer, sizeof(buffer)-1);
-      if (ret <= 0){
-          Serial.println("fetch over...");
-          break;
-      }
-      buffer[ret] = '\0';
-      Serial.print("Recv: ");
-      Serial.print(ret);
-      Serial.print(" bytes: ");
-      Serial.println(buffer);
-  }
-  gprs.close();
-  gprs.disconnect();
+	Serial.println("waiting to fetch...");
+	gprs.send(target_url, sizeof(target_url)-1);
+	while (true) {
+		int ret = gprs.recv(buffer, sizeof(buffer)-1);
+		if (ret <= 0){
+			Serial.println("fetch over...");
+			break;
+		}
+		buffer[ret] = '\0';
+		Serial.print("Recv: ");
+		Serial.print(ret);
+		Serial.print(" bytes: ");
+		Serial.println(buffer);
+	}
+	gprs.close();
+	gprs.disconnect();

 }

 void loop(){
-  /*
-  while(!gprs.available()) {
-      gprs.write("AT+CGATT?");
-      delay(2000);
-  }
-  Serial.println(gprs.read());*/
-  delay(100000);
-}
-
-
-
-
+	/*
+	while(!gprs.available()) {
+	gprs.write("AT+CGATT?");
+	delay(2000);
+	}
+	Serial.println(gprs.read());*/
+	delay(100000);
+}


Fix typo(s)

Fix typo(s)

LENGHT -> LENGTH

--- gameboy.ino
+++ gameboy.ino
@@ -168,7 +168,7 @@
       }
       INPUT_BLOCK[counter] = in;
       counter++;
-      if(counter == PLAYER_LENGHT) {
+      if(counter == PLAYER_LENGTH) {
         trade_centre_state = SENDING_PATCH_DATA;
       }
     } else if(trade_centre_state == SENDING_PATCH_DATA && in == 0xFD) {


Everything functionally working!!!!

Everything functionally working!!!!

--- Arduino/sketchbook/XbeeCppTest/XbeeCppTest.ino
+++ Arduino/sketchbook/XbeeCppTest/XbeeCppTest.ino
@@ -76,9 +76,18 @@

   for(int jk = 0; jk <= rx_packet.getlength(); jk++)
   {
+   Serial.print(rx_packet[jk], BYTE);
+  }
+    for(int jk = 0; jk <= rx_packet.getlength(); jk++)
+  {
    Serial.print(rx_packet[jk], HEX);
   }
+
+  rx_packet.clear();
+  //Serial.print('\n');
+  //Serial.println("Done!");
+
    k = 1;
   }
-
+
 }


Добавлены глобальные переменные

Добавлены глобальные переменные

Переменные для работы цикла обновления слайдов в GraphMode

--- general_code14.ino
+++ general_code14.ino
@@ -82,7 +82,11 @@

 int buttonPushCounter = 0;
 int buttonState = 0;
-int lastButtonState = 0;
+int lastButtonState = 0;
+
+long previousMillis = 0;
+long interval = 5000;
+int slide = 0;

 void setup() {
   display.begin(); //Инициализация дисплея


Added default heading function to Arduino sketch for when  magnetometer available.

--- libraries/FreeIMU/examples/FreeIMU_serial/FreeIMU_serial_temp_303.ino
+++ libraries/FreeIMU/examples/FreeIMU_serial/FreeIMU_serial_temp_303.ino
@@ -198,6 +198,8 @@
         #if Has_LSM303
            compass.read();
            val_array[16] = compass.heading();
+        #elif IS_9DOM()
+           calcMagHeading(val_array);
         #else
             val_array[16] = -9999;
         #endif
@@ -237,6 +239,8 @@
         #if Has_LSM303
 	   compass.read();
            val_array[16] = compass.heading();
+        #elif IS_9DOM()
+           calcMagHeading(val_array);
         #else
             val_array[16] = -9999;
         #endif
@@ -353,3 +357,51 @@
   }
 }

+//=============================================================
+// Get heading from magnetometer if LSM303 not available
+// code extracted from rob42/FreeIMU-20121106_1323 Github library
+// (https://github.com/rob42/FreeIMU-20121106_1323.git)
+// which is based on
+//
+//=========================================================
+float calcMagHeading(float * val_array){
+  float Head_X, Head_Y;
+  float cos_roll, sin_roll, cos_pitch, sin_pitch;
+  float gx, gy, gz; // estimated gravity direction
+  //float ypr1[3];
+
+  gx = 2 * (val_array[1]*val_array[3]
+            - val_array[0]*val_array[2]);
+  gy = 2 * (val_array[0]*val_array[1]
+            + val_array[2]*val_array[3]);
+  gz = val_array[0]*val_array[0]
+       - val_array[1]*val_array[1]
+       - val_array[2]*val_array[2]
+       + val_array[3]*val_array[3];
+
+  ypr[0] = atan2(2 * val_array[1] * val_array[2]
+          - 2 * val_array[0] * val_array[3],
+          2 * val_array[0]*val_array[0]
+          + 2 * val_array[1] * val_array[1] - 1);
+  ypr[1] = atan(gx / sqrt(gy*gy + gz*gz));
+  ypr[2] = atan(gy / sqrt(gx*gx + gz*gz));
+
+  cos_roll = cos(-ypr[2]);
+  sin_roll = sin(-ypr[2]);
+  cos_pitch = cos(ypr[1]);
+  sin_pitch = sin(ypr[1]);
+
+  //Example calc
+  //Xh = bx * cos(theta) + by * sin(phi) * sin(theta) + bz * cos(phi) * sin(theta)
+  //Yh = by * cos(phi) - bz * sin(phi)
+  //return wrap((atan2(-Yh, Xh) + variation))
+
+  // Tilt compensated Magnetic field X component:
+  Head_X = val_array[10]*cos_pitch+val_array[11]*sin_roll*sin_pitch+val_array[12]*cos_roll*sin_pitch;
+  // Tilt compensated Magnetic field Y component:
+  Head_Y = val_array[11]*cos_roll-val_array[12]*sin_roll;
+  // Magnetic Heading
+  val_array[16] = atan2(-Head_Y,-Head_X)*180./M_PI;
+
+}
+


Update gfxdemo

Update gfxdemo

--- hardware/zpuino/zpu20/libraries/ZPUino_GFX/examples/gfxdemo/gfxdemo.ino
+++ hardware/zpuino/zpu20/libraries/ZPUino_GFX/examples/gfxdemo/gfxdemo.ino
@@ -1,3 +1,5 @@
+#define circuit VGA_ZPUino
+
 #include <Adafruit_GFX.h>
 #include <ZPUino_GFX.h>
 #include <PLL.h>


fix sd example returning bad json on empty folder

--- hardware/esp8266com/esp8266/libraries/ESP8266WebServer/examples/SDWebServer/SDWebServer.ino
+++ hardware/esp8266com/esp8266/libraries/ESP8266WebServer/examples/SDWebServer/SDWebServer.ino
@@ -183,16 +183,15 @@
   server.setContentLength(CONTENT_LENGTH_UNKNOWN);
   server.send(200, "text/json", "");
   WiFiClient client = server.client();
-
+
+  server.sendContent("[");
   for (int cnt = 0; true; ++cnt) {
     File entry = dir.openNextFile();
     if (!entry)
     break;

     String output;
-    if (cnt == 0)
-      output = '[';
-    else
+    if (cnt > 0)
       output = ',';

     output += "{\"type\":\"";


Update examples/7.Display/LCD_5110_SPI/Examples/LCD_5110_SPI_main/LCD_5110_SPI_main.ino

`#include "SPI.h"` seems to be required instead of `#include "spi.h"`

--- examples/7.Display/LCD_5110_SPI/Examples/LCD_5110_SPI_main/LCD_5110_SPI_main.ino
+++ examples/7.Display/LCD_5110_SPI/Examples/LCD_5110_SPI_main/LCD_5110_SPI_main.ino
@@ -60,7 +60,7 @@

 // Include application, user and local libraries
-#include "spi.h"
+#include "SPI.h"
 #include "LCD_5110_SPI.h"

 // Variables


[setup] tiny static configuration for summer temperatures.

--- heater_control.ino
+++ heater_control.ino
@@ -135,6 +135,7 @@
   radiatorConverter.add(  0,21);
   radiatorConverter.add( 10,11);
   radiatorConverter.add( 20, 2);
+  radiatorConverter.add( 30, 0);
   bp1.setConverter(&radiatorConverter);
   // preparing for configurable channels.
   // in future the amount of channels will be specified with config


minor

minor

--- examples/ESP8266_library_test/ESP8266_library_test.ino
+++ examples/ESP8266_library_test/ESP8266_library_test.ino
@@ -62,7 +62,7 @@
   if (in.hasData) {
     Serial.println(in.message);
     //Echo back;
-    wifi.send(in.channel, "ES:", false);
+    wifi.send(in.channel, "Echo:", false);
     wifi.send(in.channel, in.message);
     nextPing = millis() + 10000;
   }


fix example for the latest ESP8266 SDK 2.5.0

--- examples/esp8266_webinterface/esp8266_webinterface.ino
+++ examples/esp8266_webinterface/esp8266_webinterface.ino
@@ -223,14 +223,14 @@
 void srv_handle_set() {
   for (uint8_t i=0; i < server.args(); i++){
     if(server.argName(i) == "c") {
-      uint32_t tmp = (uint32_t) strtol(&server.arg(i)[0], NULL, 16);
+      uint32_t tmp = (uint32_t) strtol(server.arg(i).c_str(), NULL, 16);
       if(tmp >= 0x000000 && tmp <= 0xFFFFFF) {
         ws2812fx.setColor(tmp);
       }
     }

     if(server.argName(i) == "m") {
-      uint8_t tmp = (uint8_t) strtol(&server.arg(i)[0], NULL, 10);
+      uint8_t tmp = (uint8_t) strtol(server.arg(i).c_str(), NULL, 10);
       ws2812fx.setMode(tmp % ws2812fx.getModeCount());
       Serial.print("mode is "); Serial.println(ws2812fx.getModeName(ws2812fx.getMode()));
     }
@@ -241,7 +241,7 @@
       } else if(server.arg(i)[0] == ' ') {
         ws2812fx.setBrightness(min(max(ws2812fx.getBrightness(), 5) * 1.2, 255));
       } else { // set brightness directly
-        uint8_t tmp = (uint8_t) strtol(&server.arg(i)[0], NULL, 10);
+        uint8_t tmp = (uint8_t) strtol(server.arg(i).c_str(), NULL, 10);
         ws2812fx.setBrightness(tmp);
       }
       Serial.print("brightness is "); Serial.println(ws2812fx.getBrightness());


Fixed issue with digitalPinToInterrupt on older Arduino IDEs

--- ArduinoSerialInterface/ArduinoPythonInterfacer/ArduinoPythonInterfacer.ino
+++ ArduinoSerialInterface/ArduinoPythonInterfacer/ArduinoPythonInterfacer.ino
@@ -6,8 +6,8 @@
 volatile int countB = 0;

 //encoder pins: pins 2,3 are hardware interrupts
-const int encoderA = 2;
-const int encoderB = 3;
+const int hardwareEncoderA = 2;
+const int hardwareEncoderB = 3;

 //actuator pins: pins 3,5,6,9,10,11 are capable of hardware pwm
 Servo motor;
@@ -29,13 +29,13 @@

 void setup() {
   // put your setup code here, to run once:
-  pinMode(encoderA, INPUT_PULLUP);
-  pinMode(encoderB, INPUT_PULLUP);
+  pinMode(hardwareEncoderA, INPUT_PULLUP);
+  pinMode(hardwareEncoderB, INPUT_PULLUP);
   motor.attach(motorPin);
   steering.attach(servoPin);

-  attachInterrupt(digitalPinToInterrupt(encoderA), incA, CHANGE);
-  attachInterrupt(digitalPinToInterrupt(encoderB), incB, CHANGE);
+  attachInterrupt(0, incA, RISING);
+  attachInterrupt(1, incB, RISING);
   curr_time = millis();
   Serial.begin(250000);
   Serial.println("Running");


Cleanup.

Cleanup.

--- aquacontrol32.ino
+++ aquacontrol32.ino
@@ -40,14 +40,15 @@

 //HWSPI pin definitions
 #define _cs   0   // Goes to TFT CS
-#define _dc   25   // Goes to TFT DC
+#define _dc   25  // Goes to TFT DC
 #define _mosi 32  // Goes to TFT MOSI
 #define _sclk 12  // Goes to TFT SCK/CLK
-#define _rst  0  // ESP RST goes to TFT RESET
+#define _rst  0   // ESP RST goes to TFT RESET
 #define _miso 4   // Goes to TFT MISO
 //       3.3V     // Goes to TFT LED
 //       5v       // Goes to TFT Vcc-
 //       Gnd      // Goes to TFT Gnd
+#define  SD_CS 27 // Goes to SD CS

 //i2c pin definitions for oled
 #define I2C_SCL_PIN 19
@@ -105,20 +106,13 @@

 byte numberOfFoundSensors;

-unsigned long sensorReadTime;
-
 SSD1306  OLED( 0x3c, I2C_SDA_PIN, I2C_SCL_PIN );

 // TCP server at port 80 will respond to HTTP requests
 ESP32WebServer server(80);

-
 double brightness = 200;    // how bright the LED is
 int fadeAmount = 1;         // how many points to fade the LED by
-
-int ledcActualFrequency;
-
-#define SD_CS 27

 void setup()
 {
@@ -268,7 +262,7 @@
   for ( byte thisChannel = 0; thisChannel < NUMBER_OF_CHANNELS; thisChannel++ )
   {
     // Setup timers and attach timer to a led pin
-    ledcActualFrequency = ledcSetup(thisChannel, LEDC_BASE_FREQ, LEDC_NUMBER_OF_BIT);
+    int ledcActualFrequency = ledcSetup(thisChannel, LEDC_BASE_FREQ, LEDC_NUMBER_OF_BIT);
     Serial.print( "\nChannel: " ); Serial.println( thisChannel + 1 );
     Serial.print( "PWM frequency requested: " ); Serial.print( LEDC_BASE_FREQ / 1000.0 ); Serial.println( "kHz." );
     Serial.print( "PWM frequency actual:    " ); Serial.print( ledcActualFrequency / 1000.0 ); Serial.println( "kHz." );


Changed invalid bonding value to 0xFF in ble_HID_keyboard_2_bonds_template

--- libraries/BLE/examples/ble_HID_keyboard_2_bonds_template/ble_HID_keyboard_2_bonds_template.ino
+++ libraries/BLE/examples/ble_HID_keyboard_2_bonds_template/ble_HID_keyboard_2_bonds_template.ino
@@ -242,7 +242,7 @@
   uint8_t len =0;

   eeprom_status      = EEPROM.read(bond_index * BYTES_PER_BOND_IN_HEADER);
-  if (0x00 == eeprom_status)
+  if (eeprom_status == 0xFF)
   {
     return (aci_status_code_t)BOND_DOES_NOT_EXIST_AT_INDEX;
   }
@@ -394,7 +394,7 @@
       {
         //We failed the read dymanic data
         //Set the flag in the EEPROM that the contents of the EEPROM is invalid
-        EEPROM.write(new_bond_index * BYTES_PER_BOND_IN_HEADER, 0x00);
+        EEPROM.write(new_bond_index * BYTES_PER_BOND_IN_HEADER, 0xFF);

         status = false;
         break;
@@ -457,12 +457,12 @@
                   //Reset the number of bonds and count from the EEPROM header
                   bond_number = 0;
                   eeprom_status = EEPROM.read(0);
-                  if (eeprom_status != 0x00)
+                  if (eeprom_status != 0xFF)
                   {
                     bond_number++;
                     //Update the write offset to the correct number
                     eeprom_write_offset = EEPROM.read(bond_number * BYTES_PER_BOND_IN_HEADER + 1);
-                    if (0x00 != EEPROM.read(2))
+                    if (EEPROM.read(2) != 0xFF)
                     {
                       bond_number++;
                       //This is needed only if we wanted to add a 3rd bond
@@ -698,12 +698,12 @@
           //Reset the number of bonds and count from the EEPROM header
           bond_number = 0;
           eeprom_status = EEPROM.read(0);
-          if (eeprom_status != 0x00)
+          if (eeprom_status != 0xFF)
           {
             bond_number++;
             //Update the write offset to the correct number
             eeprom_write_offset = EEPROM.read(bond_number * BYTES_PER_BOND_IN_HEADER + 1);
-            if (0x00 != EEPROM.read(2))
+            if (EEPROM.read(2) != 0xFF)
             {
               bond_number++;
               //This is needed only if we wanted to add a 3rd bond
@@ -834,10 +834,10 @@
     //Clear the pairing
     Serial.println(F("Pairing cleared. Remove the wire on Pin 6 and reset the board for normal operation."));
     //Address. Value
-    EEPROM.write(0, 0);
-    EEPROM.write(1, 0);
-    EEPROM.write(2, 0);
-    EEPROM.write(3, 0);
+    EEPROM.write(0, 0xFF);
+    EEPROM.write(1, 0xFF);
+    EEPROM.write(2, 0xFF);
+    EEPROM.write(3, 0xFF);
     while(1) {};
   }
 }


Turn off laser on powerup

Turn off laser on powerup

--- hardware_interface/hardware_interface.ino
+++ hardware_interface/hardware_interface.ino
@@ -18,6 +18,7 @@
     s2.attach(3);
     s1.attach(9);
     pinMode(fricken_laser, OUTPUT);
+    digitalWrite(fricken_laser, HIGH);
 }

 void loop()
@@ -43,4 +44,4 @@
 // 100,100,1

 // 150,100,0
-
+


preparing ino skeleton

preparing ino skeleton

--- Arduino/hardware/V0p2_Main_PCB_REV7_DORM1_and_REV8/testsuite/201611/REV7Minimal/REV7Minimal.ino
+++ Arduino/hardware/V0p2_Main_PCB_REV7_DORM1_and_REV8/testsuite/201611/REV7Minimal/REV7Minimal.ino
@@ -0,0 +1,53 @@
+/*
+The OpenTRV project licenses this file to you
+under the Apache Licence, Version 2.0 (the "Licence");
+you may not use this file except in compliance
+with the Licence. You may obtain a copy of the Licence at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the Licence is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the Licence for the
+specific language governing permissions and limitations
+under the Licence.
+
+Author(s) / Copyright (s): Deniz Erbilgin 2016
+*/
+/**
+ * Minimal REV7 config for testing power consumption.
+ * Aim is to:
+ *     - todo init GPIO pins to safe mode.
+ *     - todo init peripherals to safe low power mode.
+ *     - todo loop endlessly.
+ */
+
+// INCLUDES & DEFINES
+
+
+
+// OBJECTS & VARIABLES
+
+
+
+// FUNCTIONS
+/**
+ * @brief   Initialise GPIO pins and peripherals to a safe and low power mode.
+ */
+void setup()
+{
+
+}
+
+
+/**
+ * @brief   Loop endlessly doing nothing.
+ */
+void loop() { }
+
+
+
+/**
+ * @note    Power consumption figures.
+ */


make default color purple

make default color purple

--- arduino_firmware/arduino_firmware.ino
+++ arduino_firmware/arduino_firmware.ino
@@ -15,7 +15,7 @@
  * defaults tp pulse between white and black with 1 second period
  */
 RGB color = {
-  255, 255, 255};
+  102, 0, 102};

 RGB backgroundColor = {
   0, 0, 0};


Fix typos in BlinkWithoutDelay.ino

Fix typos in BlinkWithoutDelay.ino

--- build/shared/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino
+++ build/shared/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino
@@ -1,6 +1,6 @@
 /* Blink without Delay

- Turns on and off a light emitting diode(LED) connected to a digital
+ Turns on and off a light emitting diode (LED) connected to a digital
  pin, without using the delay() function.  This means that other code
  can run at the same time without being interrupted by the LED code.

@@ -28,7 +28,7 @@
 // Variables will change :
 int ledState = LOW;             // ledState used to set the LED

-// Generally, you shuould use "unsigned long" for variables that hold time
+// Generally, you should use "unsigned long" for variables that hold time
 // The value will quickly become too large for an int to store
 unsigned long previousMillis = 0;        // will store last time LED was updated


Added Capacitor Sensor Code

Added Capacitor Sensor Code

--- Testing_Arduino101_2/Testing_Arduino101_2.ino
+++ Testing_Arduino101_2/Testing_Arduino101_2.ino
@@ -1,3 +1,4 @@
+#include <CapacitiveSensor.h>
 #include <EnableInterrupt.h>
 #include <NewPing.h>
 #include <Servo.h>
@@ -100,8 +101,8 @@

 #define ULTRA_FREQUENCY 10

-#define IRA 7
-#define IRB 6
+#define CAP_REC 7
+#define CAP_SEND 6

@@ -111,6 +112,7 @@
 Servo myservo;
 I2CEncoder encoder_B;
 I2CEncoder encoder_A;
+CapacitiveSensor capSense = CapacitiveSensor(CAP_SEND,CAP_REC); // (send_pin, receive_pin);

@@ -307,6 +309,19 @@
   Serial.print('-');
   Serial.print(ultrasonic2);
   Serial.print("&");
+}
+
+void get_cap_value() {
+  int i;
+  long cap = capSense.capacitiveSensorRaw(30);
+  long capAvg;
+
+  for (i = 0, capAvg = 0; i < 100; i++) {
+    capAvg += cap;
+  }
+  Serial.print(capAvg/100);
+  Serial.print('-');
+  //return capAvg/100;
 }

 void servo_info(){
@@ -511,8 +526,12 @@
                 //Serial.print("report");
               }
               break;
-
-            break;
+            case 'C':
+              if(command_status == 1){
+                get_cap_value();
+              }
+              break;
+
             default:
               //Serial.print("Hello11");
             break;


PinChangeInterrupt

PinChangeInterrupt

--- _49-emontxv2-esp-01-i2c/emontxv2/emontxv2.ino
+++ _49-emontxv2-esp-01-i2c/emontxv2/emontxv2.ino
@@ -1,35 +1,109 @@
-#include <avr/pgmspace.h>
 #include <Wire.h>
 #include <RtcDS1307.h>
+#include "PinChangeInterrupt.h"

-#define SquareWave_Pin 2 // int 0
-#define LED_PIN 9
+/*
+  atmega328  -  esp - ds1307
+  3v
+  gnd
+  scl - d2  - scl
+  sda - d0  - sda // led
+  d12 -     - sqw
+  d6  - tx
+  d7  - rst
+  d12 - rx  -     // button to inform flashing of esp
+*/
+
+// pins
+// IN
+#define SQW_PIN         2 // int 0
+#define FLAH_ESP_PIN    12
+// OUT
+#define LED_PIN        9
+#define NOTIFY_ESP_PIN 6
+#define RESET_ESP_PIN  7
+// Using SDA to put LOW D0 of ESP

 RtcDS1307 Rtc;

-void SquareWaveCheck() {
+volatile bool sqw_start;
+volatile bool flash_start;
+
+void SQW_CHECK() {
+  sqw_start = true;
   digitalWrite(LED_PIN, HIGH);
 }

+void FLASH_STOP_CHECK() {
+  detachPinChangeInterrupt(digitalPinToPinChangeInterrupt(SCL));
+  Wire.begin();
+}
+
+void FLASH_START_CHECK() {
+  flash_start = !flash_start;
+  if (flash_start) {
+    Wire.end();
+    // PUT ESP to FLASH mode
+    pinMode(SDA, OUTPUT);
+    digitalWrite(SDA, LOW);
+
+    // RESET ESP
+    digitalWrite(RESET_ESP_PIN, LOW);
+    delayMicroseconds(5);
+    digitalWrite(RESET_ESP_PIN, HIGH);
+    delayMicroseconds(10);
+
+    // TO CHECK FLASHING IS DONE
+    pinMode(SCL, INPUT_PULLUP);
+    delayMicroseconds(10);
+    attachPinChangeInterrupt(digitalPinToPinChangeInterrupt(SCL), FLASH_STOP_CHECK, FALLING);
+  } else {
+    FLASH_STOP_CHECK();
+  }
+}
+
+void start_measure() {
+  delay(200);
+  digitalWrite(LED_PIN, LOW);
+}
+
+void nofify_esp() {
+  digitalWrite(NOTIFY_ESP_PIN, LOW);
+  delayMicroseconds(5);
+  digitalWrite(NOTIFY_ESP_PIN, HIGH);
+}
+
 void setup() {
-  Serial.begin(115200);
-  Wire.begin();
-
   Rtc.Begin();
   Rtc.SetIsRunning(true);
   Rtc.SetSquareWavePin(DS1307SquareWaveOut_1Hz);
+
+  sqw_start = flash_start = false;

+  // OUT
   pinMode(LED_PIN, OUTPUT);
-  pinMode(SquareWave_Pin, INPUT_PULLUP);
-  attachInterrupt(digitalPinToInterrupt(SquareWave_Pin), SquareWaveCheck, FALLING);
-  Wire.end();
-
-  pinMode(SDA, OUTPUT);
+  pinMode(NOTIFY_ESP_PIN, OUTPUT);
+  pinMode(RESET_ESP_PIN, OUTPUT);
+
+  // IN
+  pinMode(SQW_PIN, INPUT_PULLUP);
+  pinMode(FLAH_ESP_PIN, INPUT);
+
+  //
+  digitalWrite(NOTIFY_ESP_PIN, HIGH);
+  digitalWrite(RESET_ESP_PIN, HIGH);
+
+  attachInterrupt(digitalPinToInterrupt(SQW_PIN), SQW_CHECK, FALLING);
+  attachPinChangeInterrupt(digitalPinToPinChangeInterrupt(FLAH_ESP_PIN), FLASH_START_CHECK, FALLING);
 }

 void loop() {
-  digitalWrite(SDA, LOW);
-  delay(200);
-  digitalWrite(LED_PIN, LOW);
-
+  if (sqw_start) {
+    start_measure();
+    if (!flash_start) {
+      //write_nvram();
+      nofify_esp();
+    }
+    sqw_start = false;
+  }
 }


tweaked rollover handling

tweaked rollover handling

--- Pan_Tilt_laser/Pan_Tilt_laser.ino
+++ Pan_Tilt_laser/Pan_Tilt_laser.ino
@@ -207,7 +207,7 @@
       heartBeat();
       delay(10000);
       if(startTime > millis()){ //check for rollovers
-        break;
+        startTime = millis();
       }
     }
     startTime = millis();


Tweaks

Tweaks

--- Pan_Tilt_laser/Pan_Tilt_laser.ino
+++ Pan_Tilt_laser/Pan_Tilt_laser.ino
@@ -125,9 +125,6 @@
 //                           |  \/
   lmShake.addLinkToBack( 2, 30, 0 ); // Shake

-
-
-
   randomSeed(analogRead(5));

   mSwitch.heartBeat(3);
@@ -267,7 +264,7 @@
   unsigned long startTime = millis();
   for(unsigned long i = 0; i < delayVal; i++){
     while(millis() - startTime < 1000){
-      heartBeat(millis(), 10000);
+      heartBeat(10000);

       if(!mSwitch.switchState()){ //return if switch is turned off. Main program waits for restart.
         return;
@@ -288,7 +285,7 @@

 void heartBeat(unsigned long mSeconds, int hbInterval){
   static unsigned long oldTime;
-  if(mSeconds - oldTime > hbInterval){
+  if(millis() - oldTime > hbInterval){

     mSwitch.heartBeat(1);


fixes to NaN handling in json

fixes to NaN handling in json

--- WeatherStation/WeatherStation.ino
+++ WeatherStation/WeatherStation.ino
@@ -63,7 +63,7 @@

 void loop() {
   digitalWrite(XBEESLEEPPIN, LOW);  //Wake UP XBEE
-  delay(2000);
+  delay(4000);

   blink(25, 50);
   digitalWrite(LEDPIN, LOW);
@@ -73,46 +73,43 @@

   sample += 1;

-  if (!pingCoordinator()){          //check if xbee woke up and got its association address. blink LED rapidly and quit loop otherwise
-    blink(10);
-    digitalWrite(LEDPIN, LOW);
-    digitalWrite(XBEESLEEPPIN, LOW);  //Wake UP XBEE
-    sleep(60000);
-    return;
-  }
-
-  Serial.print("{\"_sensor\": \"weather\", \"_sample\": {\"_id\":");
-  Serial.print(sample);
-  Serial.print(", ");
-
-  Serial.print("\"Temp\":"); printValue(dht.getTemperature());
-  Serial.print("\"RH\":"); printValue(dht.getHumidity());
-
-  sensors_event_t event;
-  bmp.getEvent(&event);
-  Serial.print("\"AtmoPressure\":"); printValue(event.pressure);
-
-  uint16_t broadband = 0;
-  uint16_t infrared = 0;
-
-  tsl.getEvent(&event);
-  long lx = event.light;
-  tsl.getLuminosity (&broadband, &infrared);
-  if (lx == 0 && broadband > 65000){ //Sensor appears to be in direct sunlight outside it's resolution limits. Set lx value to max to simplify downstream logic
-      lx = 0xFFFF;
-  }
-  Serial.print("\"AmbientLight\":"); printValue(lx);
-  Serial.print("\"BroadbandLight\":"); printValue((long)broadband);
-  Serial.print("\"Infrared\":"); printValue((long)infrared, 0);
-
-  Serial.println("}}");
-
-  delay(2000);   //Delay at the end to allow xbee to flush its send buffer
+  if (!pingDestination()){          //check if xbee woke up and got its association address. blink LED rapidly and quit loop otherwise
+    blink(50, 100);
+  } else {                          //connected to the destination
+
+    Serial.print("{\"__device\": \"weather\", \"__sample\": {\"__id\":");
+    Serial.print(sample);
+    Serial.print(", ");
+
+    Serial.print("\"Temp\":"); printValue(dht.getTemperature());
+    Serial.print("\"RH\":"); printValue(dht.getHumidity());
+
+    sensors_event_t event;
+    bmp.getEvent(&event);
+    Serial.print("\"AtmoPressure\":"); printValue(event.pressure);
+
+    uint16_t broadband = 0;
+    uint16_t infrared = 0;
+
+    tsl.getEvent(&event);
+    long lx = event.light;
+    tsl.getLuminosity (&broadband, &infrared);
+    if (lx == 0 && broadband > 65000){ //Sensor appears to be in direct sunlight outside it's resolution limits. Set lx value to max to simplify downstream logic
+        lx = 0xFFFF;
+    }
+    Serial.print("\"AmbientLight\":"); printValue(lx);
+    Serial.print("\"BroadbandLight\":"); printValue((long)broadband);
+    Serial.print("\"Infrared\":"); printValue((long)infrared, 0);
+
+    Serial.println("}}");
+
+    delay(2000);   //Delay at the end to allow xbee to flush its send buffer
+  }

   digitalWrite(LEDPIN, LOW);
   digitalWrite(XBEESLEEPPIN, HIGH);  //Put XBEE to sleep

-  sleep(60000);
+  sleep(150000);
 }

 void printValue(float value){
@@ -122,7 +119,7 @@
   }
   else
   {
-    Serial.print("'NaN', ");
+    Serial.print("null, ");
   }
 }

@@ -137,7 +134,7 @@
   }
   else
   {
-    Serial.print("'NaN'");
+    Serial.print("null");
   }

   if (separator){
@@ -145,15 +142,15 @@
   }
 }

-int pingCoordinator(void){
-
-    for(int i = 0; i<10; i++){
-      blink(i);
+int pingDestination(void){
+
+    for(int i = 0; i<5; i++){
+      blink(i+1);
       while(getCh() != NULL) ;       //Drain any pending chars on the serial.
       Serial.println("@PING");
       int c=0;
       while(Serial.available()<2 && c++<10){
-          delay(400);
+          delay(200);
           blink(2, 50);
       }
       if (getCh()=='O' && getCh()=='K'){


firmata was resetting wifi shield pins, altered reset to not do this

--- examples/skynetim_wifi_StandardFirmata/skynetim_wifi_StandardFirmata.ino
+++ examples/skynetim_wifi_StandardFirmata/skynetim_wifi_StandardFirmata.ino
@@ -579,6 +579,11 @@
   // pins with analog capability default to analog input
   // otherwise, pins default to digital output
   for (byte i=0; i < TOTAL_PINS; i++) {
+
+	// skip SPI pins
+	if ( (i==7) || (i==MOSI) || (i==MISO) || (i==SCK) || (i==SS) )
+		continue;
+
     if (IS_PIN_ANALOG(i)) {
       // turns off pullup, configures everything
       setPinModeCallback(i, ANALOG);


Note that CERTS.IDX file is generated on-chip (#4902)

Several users have been worried that they need to generate the IDX file,
but don't know how.  The CertStore code actually writes this file on object
creation, and the user never needs to explicitly generate or upload it.

Add a comment to the example explicitly noting this.

--- libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino
+++ libraries/ESP8266WiFi/examples/BearSSL_CertStore/BearSSL_CertStore.ino
@@ -2,8 +2,11 @@
 //
 // Before running, you must download the set of certs using
 // the script "certs-from-mozilla.py" (no parameters)
-// and then uploading the generated data directory to
-// SPIFFS.
+// and then uploading the generated .AR file to SPIFFS or SD.
+//
+// You do not need to generate the ".IDX" file listed below,
+// it is generated automatically when the CertStore object
+// is created and written to SD or SPIFFS by the ESP8266.
 //
 // Why would you need a CertStore?
 //
@@ -19,7 +22,7 @@
 // 10s or 100s of CAs against which you can check the
 // target's X.509, without taking any more RAM than a single
 // certificate.  This is the same way that standard browsers
-// and operating systems use to verify SSL connections.
+// and operating systems verify SSL connections.
 //
 // About the chosen certs:
 // The certificates are scraped from the Mozilla.org current
@@ -82,8 +85,8 @@
     const char *_name;
 };

-SDCertStoreFile certs_idx("/certs.idx");
-SDCertStoreFile certs_ar("/certs.ar");
+SDCertStoreFile certs_idx("/certs.idx"); // Generated by the ESP8266
+SDCertStoreFile certs_ar("/certs.ar"); // Uploaded by the user

 #else

@@ -118,8 +121,9 @@
     const char *_name;
 };

-SPIFFSCertStoreFile certs_idx("/certs.idx");
-SPIFFSCertStoreFile certs_ar("/certs.ar");
+SPIFFSCertStoreFile certs_idx("/certs.idx"); // Generated by the ESP8266
+SPIFFSCertStoreFile certs_ar("/certs.ar"); // Uploaded by the user
+
 #endif

 // Set time via NTP, as required for x.509 validation


Update MinimalInterrupt.ino

Update MinimalInterrupt.ino

--- examples/MinimalInterrupt/MinimalInterrupt.ino
+++ examples/MinimalInterrupt/MinimalInterrupt.ino
@@ -30,7 +30,7 @@
 #include <MFRC522.h>

 #define RST_PIN         9           // Configurable, see typical pin layout above
-#define SS_PIN         10           // Configurable, see typical pin layout above
+#define SS_PIN          3           // Configurable, see typical pin layout above
 #define IRQ_PIN         2

 MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.


ArduinoDueFuncGen: Set up test waveform in firmware.

git-svn-id: 03a8048b5ee8463be5048a3801110fb50f378627@12592 d0ab736e-dc22-4aeb-8dc9-08def0aa14fd

--- DeviceAdapters/ArduinoDueFuncGen/due_ad660_firmware/due_ad660_firmware.ino
+++ DeviceAdapters/ArduinoDueFuncGen/due_ad660_firmware/due_ad660_firmware.ino
@@ -375,6 +375,22 @@
     g_banks[i].channel_offset = g_channel_offset;
   }

+  // By default, the waveform tables initially contain invalid data. To
+  // facilitate testing from a terminal (without loading a binary waveform),
+  // load a test "waveform" if length <= 4 is requested.
+  if (waveform_length <= 4) {
+    for (uint8_t t = 0; t < n_tables; t++) {
+      if (waveform_length >= 1)
+        waveform_table(t)[0] = 32768;
+      if (waveform_length >= 2)
+        waveform_table(t)[1] = 65535;;
+      if (waveform_length >= 3)
+        waveform_table(t)[2] = 32768;;
+      if (waveform_length >= 4)
+        waveform_table(t)[3] = 0;;
+    }
+  }
+
   return true;
 }


Add debug info

Add debug info

--- Arduino/KiteBarUnit/KiteBarUnit.ino
+++ Arduino/KiteBarUnit/KiteBarUnit.ino
@@ -104,6 +104,14 @@
     computeFeedback();
     driver.send(data, sizeof(data));
     driver.waitPacketSent();
+    Serial.print(data[0]);
+    Serial.print(", ");
+        Serial.print(data[1]);
+    Serial.print(", ");
+        Serial.print(data[2]);
+    Serial.print(", ");
+        Serial.print(data[3]);
+    Serial.println(", ");
   }
 }
 // Taken from http://playground.arduino.cc/Main/RotaryEncoders J.Carter(of Earth)


naming fix

naming fix

--- Arduino/servo-radar/servo-radar.ino
+++ Arduino/servo-radar/servo-radar.ino
@@ -106,7 +106,7 @@

     if(rangeFront > 0)
     {
-        Serial.print("Servo_Front");
+        Serial.print("Ultrasonic|Front");
         Serial.print("|");
         Serial.print(servoPos);
         Serial.print("|");
@@ -115,7 +115,7 @@

     if(rangeBack > 0)
     {
-        Serial.print("Servo_Back");
+        Serial.print("Ultrasonic|Back");
         Serial.print("|");
         Serial.print((servoPos+180%360));
         Serial.print("|");


comment moved to right place

comment moved to right place

--- ArduCAM_OSD/OSD_Panels.ino
+++ ArduCAM_OSD/OSD_Panels.ino
@@ -653,7 +653,7 @@

 		warning = 0;						// if we are lucky

-		do {			// full cycle done
+		do {
 			++x;

 			switch (x) {
@@ -680,7 +680,7 @@
 				break;
 			}

-		} while (x != warning_type);
+		} while (x != warning_type);    // full cycle done

 		if (warning == 0) {	// no warning
 			warning_type = 0;		// cancel


Change the CS pin from pin9 to pin10

Change the CS pin from pin9 to pin10

--- ArduCAM/examples/mini/ArduCAM_Mini_OV5642_Video_Streaming/ArduCAM_Mini_OV5642_Video_Streaming.ino
+++ ArduCAM/examples/mini/ArduCAM_Mini_OV5642_Video_Streaming/ArduCAM_Mini_OV5642_Video_Streaming.ino
@@ -27,7 +27,7 @@
 #define BMPIMAGEOFFSET 66

 // set pin 10 as the slave select for the digital pot:
-const int CS = 9;
+const int CS = 10;
 bool is_header = false;
 int mode = 0;
 uint8_t start_capture = 0;


test file

test file

--- arduino/opencr_arduino/opencr/libraries/OpenManipulator/example/OPM_for_Arduino/test_manager/test_manager.ino
+++ arduino/opencr_arduino/opencr/libraries/OpenManipulator/example/OPM_for_Arduino/test_manager/test_manager.ino
@@ -1,9 +1,6 @@
 #include <OMManager.h>
-<<<<<<< HEAD
 #include <OMMath.h>
 #include <OMKinematics.h>
-=======
->>>>>>> d5ad3ac41573ad5609aabe5d679a3f5c631fb9e9

 #define WORLD     0
 #define BASE      1
@@ -18,6 +15,7 @@
 void setup()
 {
   Manipulator manipulator;
+  manipulator.addworld(WORLD,position, orientation)
   manipulator.addComponent(WORLD, NONE, BASE, mass, inertia_tensor, relative_position, relative_orientation, axis_of_rotation);
   manipulator.addComponent(WORLD, NONE, BASE, mass, inertia_tensor, relative_position, relative_orientation, axis_of_rotation);
   manipulator.addComponent(WORLD, NONE, BASE, mass, inertia_tensor, relative_position, relative_orientation, axis_of_rotation);


Fixed disconnect values

Fixed disconnect values

--- ps2_controller/ps2_controller.ino
+++ ps2_controller/ps2_controller.ino
@@ -212,7 +212,33 @@
   serial_rx_buffer_controller[9] = 0x00; //  Delay Byte 2
   serial_rx_buffer_controller[10] = 0x00; // Delay Byte 1
   serial_rx_buffer_controller[11] = 0x01; // Postamble
+
+  resetCalled = currentMillis;
+  serial_rx_buffer_reset[8] = (byte)((resetCalled & 0xFF));
+  serial_rx_buffer_reset[7] = (byte)((resetCalled >> 8) & 0xFF);
+  serial_rx_buffer_reset[6] = (byte)((resetCalled >> 16) & 0xFF);
+  serial_rx_buffer_reset[5] = (byte)((resetCalled >> 24) & 0xFF);
+  serial_rx_buffer_reset[0] = 0xA0;
+  serial_rx_buffer_reset[11] = 0xA0;
+  for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_reset); serial_rx_buffer_counter++) {
+    Serial.write(serial_rx_buffer_reset[serial_rx_buffer_counter]); //  This line writes the serial data back to the computer as a way to check if the Arduino isn't interpreting wrong values
+  }
+  Serial.flush();
+
   delay(5000); // Wait for the serial program on the computer to startup before sending any data
+
+  resetDone = currentMillis;
+  serial_rx_buffer_reset[0] = 0xA1;
+  serial_rx_buffer_reset[11] = 0xA1;
+  serial_rx_buffer_reset[8] = (byte)((resetDone & 0xFF));
+  serial_rx_buffer_reset[7] = (byte)((resetDone >> 8) & 0xFF);
+  serial_rx_buffer_reset[6] = (byte)((resetDone >> 16) & 0xFF);
+  serial_rx_buffer_reset[5] = (byte)((resetDone >> 24) & 0xFF);
+  for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_reset); serial_rx_buffer_counter++) {
+    Serial.write(serial_rx_buffer_reset[serial_rx_buffer_counter]); //  This line writes the serial data back to the computer as a way to check if the Arduino isn't interpreting wrong values
+  }
+  Serial.flush();
+
   serial_rx_buffer_disconnect[0] = 0x0B;
   serial_rx_buffer_disconnect[11] = 0x0B;
   isConnected = true;
@@ -424,8 +450,8 @@
   serial_rx_buffer_reset[7] = (byte)((resetCalled >> 8) & 0xFF);
   serial_rx_buffer_reset[6] = (byte)((resetCalled >> 16) & 0xFF);
   serial_rx_buffer_reset[5] = (byte)((resetCalled >> 24) & 0xFF);
-  serial_rx_buffer_reset[0] = 0xA1;
-  serial_rx_buffer_reset[11] = 0xA1;
+  serial_rx_buffer_reset[0] = 0xA0;
+  serial_rx_buffer_reset[11] = 0xA0;
   for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_reset); serial_rx_buffer_counter++) {
     Serial.write(serial_rx_buffer_reset[serial_rx_buffer_counter]); //  This line writes the serial data back to the computer as a way to check if the Arduino isn't interpreting wrong values
   }
@@ -448,6 +474,8 @@
   disconnectDone = currentMillis;
   delay(5000); // Wait 5 seconds before resetting
   resetDone = currentMillis;
+  serial_rx_buffer_reset[0] = 0xA1;
+  serial_rx_buffer_reset[11] = 0xA1;
   serial_rx_buffer_reset[8] = (byte)((resetDone & 0xFF));
   serial_rx_buffer_reset[7] = (byte)((resetDone >> 8) & 0xFF);
   serial_rx_buffer_reset[6] = (byte)((resetDone >> 16) & 0xFF);
@@ -788,8 +816,8 @@
     //Serial.println("DISCONNECTING...");
     //Serial.print("DISCONNECTING PING = ");
     //Serial.println(calcPongTimestampIn);
-    serial_rx_buffer_disconnect[0] = 0x0A;
-    serial_rx_buffer_disconnect[11] = 0x0A;
+    serial_rx_buffer_disconnect[0] = 0x09;
+    serial_rx_buffer_disconnect[11] = 0x09;
     for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_disconnect); serial_rx_buffer_counter++) {
       Serial.write(serial_rx_buffer_disconnect[serial_rx_buffer_counter]); //  This line writes the serial data back to the computer as a way to check if the Arduino isn't interpreting wrong values
     }


Arduino responds PONG with PONG

Arduino responds PONG with PONG

This is only for Debugging purposes

--- ps2_controller/ps2_controller.ino
+++ ps2_controller/ps2_controller.ino
@@ -323,7 +323,7 @@
       for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_pong_in); serial_rx_buffer_counter++) {
         //  Pass Serial Buffer to Pong Input Buffer
         serial_rx_buffer_pong_in[serial_rx_buffer_counter] = serial_rx_buffer[serial_rx_buffer_counter];
-      }s
+      }
       getPong();
     }
     else if ((serial_rx_buffer[0] == 0xA0) && (serial_rx_buffer[11] == 0xA0)) {
@@ -363,6 +363,7 @@
   Serial.end();
   isConnected = false;
   disconnectDone = currentMillis;
+  delay(5000); // Wait 5 seconds before reconnecting
   Serial.begin(baudRate);
   serial_rx_buffer_disconnect[0] = 0x0B;
   serial_rx_buffer_disconnect[11] = 0x0B;
@@ -546,28 +547,28 @@
   lastPongOut = currentMillis;
   Serial.flush();
   /*
-  Serial.print("PONG = ");
-  Serial.println(currentMillis);
-  Serial.flush();
-  Serial.println("PING RECEIVED");
-  Serial.println("");
-  Serial.print("LAST PING TIME IN = ");
-  Serial.println(lastPingIn);
-  Serial.print("LAST PONG TIME IN = ");
-  Serial.println(lastPongIn);
-  Serial.print("LAST PING TIME OUT = ");
-  Serial.println(lastPingOut);
-  Serial.print("LAST PONG TIME OUT = ");
-  Serial.println(lastPongOut);
-  Serial.print("PING TIME OUT = ");
-  Serial.println(pingTimeOut);
-  Serial.print("PONG TIME OUT = ");
-  Serial.println(pongTimeOut);
-  Serial.print("PING TIME IN = ");
-  Serial.println(pingTimeIn);
-  Serial.print("PONG TIME IN= ");
-  Serial.println(pongTimeIn);
-  Serial.flush();
+    Serial.print("PONG = ");
+    Serial.println(currentMillis);
+    Serial.flush();
+    Serial.println("PING RECEIVED");
+    Serial.println("");
+    Serial.print("LAST PING TIME IN = ");
+    Serial.println(lastPingIn);
+    Serial.print("LAST PONG TIME IN = ");
+    Serial.println(lastPongIn);
+    Serial.print("LAST PING TIME OUT = ");
+    Serial.println(lastPingOut);
+    Serial.print("LAST PONG TIME OUT = ");
+    Serial.println(lastPongOut);
+    Serial.print("PING TIME OUT = ");
+    Serial.println(pingTimeOut);
+    Serial.print("PONG TIME OUT = ");
+    Serial.println(pongTimeOut);
+    Serial.print("PING TIME IN = ");
+    Serial.println(pingTimeIn);
+    Serial.print("PONG TIME IN= ");
+    Serial.println(pongTimeIn);
+    Serial.flush();
   */
   sentPong = false;
 }
@@ -575,7 +576,24 @@
 void getPong() {
   //  This function gets PONG sent from the computer, then stores it in an Unsigned Long Integer
   pongTimeIn = (unsigned long)serial_rx_buffer_pong_in[5] << 24 | (unsigned long)serial_rx_buffer_pong_in[6] << 16 | (unsigned long)serial_rx_buffer_pong_in[7] << 8 | (unsigned long)serial_rx_buffer_pong_in[8];
-  //  This for loop doesn't have to be used, the Arduino doesn't have to respond to PONG with PONG, it doesn't have to respont to PONG at all.
+  //  Respond PONG with PONG for debugging purposes
+  for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_pong_in); serial_rx_buffer_counter++) {
+    if (serial_rx_buffer_counter == 0) {
+      Serial.write(0x05);
+    }
+    if ((serial_rx_buffer_counter == 1) || (serial_rx_buffer_counter == 2) || (serial_rx_buffer_counter == 3) || (serial_rx_buffer_counter == 4)) {
+      Serial.write(serial_rx_buffer_pong_in[serial_rx_buffer_counter]);
+    }
+    if ((serial_rx_buffer_counter == 5) || (serial_rx_buffer_counter == 6) || (serial_rx_buffer_counter == 7) || (serial_rx_buffer_counter == 8)) {
+      Serial.write(serial_rx_buffer_pong_in[serial_rx_buffer_counter]);
+    }
+    if ((serial_rx_buffer_counter == 9) || (serial_rx_buffer_counter == 10)) {
+      Serial.write(0x00);
+    }
+    if (serial_rx_buffer_counter == 11) {
+      Serial.write(0x05);
+    }
+  }
   /*
     for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_pong_in); serial_rx_buffer_counter++) {
     serial_rx_buffer_ping_out[serial_rx_buffer_counter] = serial_rx_buffer_pong_in[serial_rx_buffer_counter];
@@ -602,28 +620,28 @@
   lastPongIn = currentMillis;
   //Serial.flush();
   /*
-  Serial.println("PONG RECEIVED");
-  Serial.println("");
-  Serial.print("CURRENT TIME = ");
-  Serial.println(currentMillis);
-  Serial.flush();
-  Serial.print("LAST PING TIME IN = ");
-  Serial.println(lastPingIn);
-  Serial.print("LAST PONG TIME IN = ");
-  Serial.println(lastPongIn);
-  Serial.print("LAST PING TIME OUT = ");
-  Serial.println(lastPingOut);
-  Serial.print("LAST PONG TIME OUT = ");
-  Serial.println(lastPongOut);
-  Serial.print("PING TIME OUT = ");
-  Serial.println(pingTimeOut);
-  Serial.print("PONG TIME OUT = ");
-  Serial.println(pongTimeOut);
-  Serial.print("PING TIME IN = ");
-  Serial.println(pingTimeIn);
-  Serial.print("PONG TIME IN= ");
-  Serial.println(pongTimeIn);
-  Serial.flush();
+    Serial.println("PONG RECEIVED");
+    Serial.println("");
+    Serial.print("CURRENT TIME = ");
+    Serial.println(currentMillis);
+    Serial.flush();
+    Serial.print("LAST PING TIME IN = ");
+    Serial.println(lastPingIn);
+    Serial.print("LAST PONG TIME IN = ");
+    Serial.println(lastPongIn);
+    Serial.print("LAST PING TIME OUT = ");
+    Serial.println(lastPingOut);
+    Serial.print("LAST PONG TIME OUT = ");
+    Serial.println(lastPongOut);
+    Serial.print("PING TIME OUT = ");
+    Serial.println(pingTimeOut);
+    Serial.print("PONG TIME OUT = ");
+    Serial.println(pongTimeOut);
+    Serial.print("PING TIME IN = ");
+    Serial.println(pingTimeIn);
+    Serial.print("PONG TIME IN= ");
+    Serial.println(pongTimeIn);
+    Serial.flush();
   */
 }


added meaningful comments and print binary data splitted by tetrads

--- reciever/reciever.ino
+++ reciever/reciever.ino
@@ -1,113 +1,173 @@
 #include <Arduino.h>

-#define DIVIDER_PULSE_LENGTH 600
-#define START_BIT_LENGTH 9000
-#define BIT_1_LENGTH 3900
-#define BIT_0_LENGTH 1850
+//PWM high and low pulse length
+#define DIVIDER_PULSE_LENGTH 600 //high pulse length of the bit's divider
+#define START_BIT_LENGTH 9000 //length of the start bit low pulse
+#define BIT_1_LENGTH 3900 //binary 1 low pulse length
+#define BIT_0_LENGTH 1850 //binary 0 low puls length

-#define DIVIDER_TRESHOLD 100
-#define START_BIT_TRESHOLD 1000
-#define REGULAR_BIT_TRESHOLD 500
+//Thresholds for pulse length
+#define DIVIDER_THRESHOLD 100 //threshold for divider pulse
+#define START_BIT_THRESHOLD 1000 //threshold for start bit pulse
+#define REGULAR_BIT_THRESHOLD 500 //threshold for 0 and 1 bit's pulse

-#define DATA_BIT_SIZE 36
-#define BITS_PER_PACKET 4
-#define DATA_ARRAY_SIZE 9
+#define DATA_BITS_AMOUNT 36  //total amount of bits sent by BL999 sensor
+#define BITS_PER_PACKET 4 //36 bits are sent in packets by 4 bits (tetrads)
+#define DATA_ARRAY_SIZE 9 //totally we have 36/4 = 9 tetrads

-volatile int pwm_high_length = 0;
-volatile int pwm_low_length = 0;
-volatile int prev_time_rising = 0;
-volatile int prev_time_falling = 0;
+volatile unsigned int pwm_high_length = 0;
+volatile unsigned int pwm_low_length = 0;
+volatile unsigned int prev_time_rising = 0;
+volatile unsigned int prev_time_falling = 0;
 volatile byte state = 0;
+
+// Example of the data array:
+//
+// tetrad:        T1    ||     T2    ||     T3    ||     T4    ||     T5
+// bit:      A0|A1|A2|A3||B0|B1|B2|B3||C0|C1|C2|C3||D0|D1|D2|D3||E0|E1|E2|E3
+//
+// tetrad:        T6    ||     T7    ||     T8    ||     T9
+// bit:      F0|F1|F2|F3||G0|G1|G2|G3||H0|H1|H2|H3||I0|I1|I2|I3
+//
+// A0-A3,B2-B3  - UUID which is randomly set once sensor is turned on
+//                and it not changed until next power off
+//
+// B0-B1  - Number of the sensor: 01 - 1, 10 - 2, 11 - 3
+//
+// C0 - battery info: 0 - battery is ok, 1 - battery is low
+//
+// C1-C3 - unknown
+//
+// D0-F3 - temperature written backwards and multiplied by 10. For example:
+//         1010|0011|0000 = 19.7° (Celsius) because 0000|1100|0101 = 197
+//
+// G0-H3 - humidity. format is not recognized yet TODO
+//
+// I0-I3 - 4 less significant bits of check sum of the tetrads T1-T8 written backwards.
+//            for example let's look at the example message:
+//            1011|1100|0000|0101|0011|0000|0001|1011|1101
+//            sum of the tetrad T1-T8 = 101011, lets take last 4 bits and wrote them backward:
+//            1101 which is equal T9 tetrad
+
 volatile byte data[DATA_ARRAY_SIZE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};

 void setup() {
-  Serial.begin(115200);
-  // when pin D2 goes high, call the rising function
-  attachInterrupt(0, rising, RISING);
+    Serial.begin(115200);
+    // when pin D2 goes high, call the rising function
+    attachInterrupt(0, rising, RISING);
 }
-
+
 void loop() { }
-
+
 void rising() {
-  attachInterrupt(0, falling, FALLING);
-  prev_time_rising = micros();
+    attachInterrupt(0, falling, FALLING);
+    prev_time_rising = micros();

-  pwm_low_length = micros() - prev_time_falling;
+    pwm_low_length = micros() - prev_time_falling;

-  if (state % 2 == 0) {
-    setState(state, false);
-  } else {
-      if (state == 1) {
-        setState(2, matchStartBit(pwm_low_length));
-        return;
-      }
-
-      byte newState = state + 1;
-      boolean matchOne = matchOneBit(pwm_low_length);
-      boolean matchZero = matchZeroBit(pwm_low_length);
-
-      setState(newState, matchOne || matchZero);
+    if (state % 2 == 0) {
+        setState(state, false);
+    } else {
+        if (state == 1) {
+            setState(2, matchStartBit(pwm_low_length));
+            return;
+        }

-      if (state == newState) {
-          int bitNumber = (state - 1) / 2 - 1;
-          fillDataArray(bitNumber, matchOne);
+        byte newState = state + 1;
+        boolean matchOne = matchOneBit(pwm_low_length);
+        boolean matchZero = matchZeroBit(pwm_low_length);

-          if (bitNumber == DATA_BIT_SIZE - 1) {
-            for (byte i = 0; i < DATA_ARRAY_SIZE; i++) {
-                Serial.print(data[i]);
-                Serial.print(" ");
+        setState(newState, matchOne || matchZero);
+
+        if (state == newState) {
+            int bitNumber = (state - 1) / 2 - 1;
+            fillDataArray(bitNumber, matchOne);
+
+            if (bitNumber == DATA_BITS_AMOUNT - 1) {
+                printDataArray();
+                setState(state, false);
             }
-            Serial.println();
+        }
+    }
+}

-            setState(state, false);
-          }
-      }
-  }
+void falling() {
+    attachInterrupt(0, rising, RISING);
+    prev_time_falling = micros();
+
+    pwm_high_length = micros() - prev_time_rising;
+
+    if (state % 2 == 0) {
+        setState(state + 1, matchDivider(pwm_high_length));
+    } else {
+        setState(state, false);
+    }
 }
-
-void falling() {
-  attachInterrupt(0, rising, RISING);
-  prev_time_falling = micros();
-
-  pwm_high_length = micros() - prev_time_rising;

-  if (state % 2 == 0) {
-      setState(state + 1, matchDivider(pwm_high_length));
-  } else {
-      setState(state, false);
-  }
+void printDataArray() {
+    for (byte i = 0; i < DATA_ARRAY_SIZE; i++) {
+        printByteAsBitSet(data[i]);
+        Serial.print("|");
+    }
+    Serial.println();
+}
+
+void printByteAsBitSet(byte b) {
+    if (b & 8) {
+        Serial.print("1");
+    } else {
+        Serial.print("0");
+    }
+
+    if (b & 4) {
+        Serial.print("1");
+    } else {
+        Serial.print("0");
+    }
+
+    if (b & 2) {
+        Serial.print("1");
+    } else {
+        Serial.print("0");
+    }
+
+    if (b & 1) {
+        Serial.print("1");
+    } else {
+        Serial.print("0");
+    }
 }

 void fillDataArray(byte bitNumber, boolean isOne) {
-   byte dataArrayIndex = bitNumber / BITS_PER_PACKET;
-   data[dataArrayIndex] = (data[dataArrayIndex] << 1) | isOne;
+    byte dataArrayIndex = bitNumber / BITS_PER_PACKET;
+    data[dataArrayIndex] = (data[dataArrayIndex] << 1) | isOne;
 }

 void clearDataArray(byte upTo) {
-  for (byte i = 0; i <= upTo; i++) {
-    data[i] = 0;
-  }
+    for (byte i = 0; i <= upTo; i++) {
+        data[i] = 0;
+    }
 }

 boolean matchDivider(int value) {
-    return match(value, DIVIDER_PULSE_LENGTH, DIVIDER_TRESHOLD);
+    return match(value, DIVIDER_PULSE_LENGTH, DIVIDER_THRESHOLD);
 }

 boolean matchStartBit(int value) {
-    return match(value, START_BIT_LENGTH, START_BIT_TRESHOLD);
+    return match(value, START_BIT_LENGTH, START_BIT_THRESHOLD);
 }

 boolean matchOneBit(int value) {
-    return match(value, BIT_1_LENGTH, REGULAR_BIT_TRESHOLD);
+    return match(value, BIT_1_LENGTH, REGULAR_BIT_THRESHOLD);
 }

 boolean matchZeroBit(int value) {
-    return match(value, BIT_0_LENGTH, REGULAR_BIT_TRESHOLD);
+    return match(value, BIT_0_LENGTH, REGULAR_BIT_THRESHOLD);
 }

 boolean match(int value, int mathConst, int treshold) {
-    return value >  mathConst - treshold && value < mathConst + treshold;
+    return value > mathConst - treshold && value < mathConst + treshold;
 }

 void setState(byte st, boolean condition) {
@@ -116,15 +176,8 @@
     } else {
         state = 0;
         if (st > 3) {
-          clearDataArray(((st - 2) / 2 - 1) / BITS_PER_PACKET);
+            clearDataArray(((st - 2) / 2 - 1) / BITS_PER_PACKET);
         }
     }
 }

-
-
-
-
-
-
-


add note for GREE air-conditioner spec

add note for GREE air-conditioner spec

--- main/main/main.ino
+++ main/main/main.ino
@@ -529,6 +529,7 @@
  *
  * https://github.com/arduino/ArduinoCore-samd/blob/master/cores/arduino/main.cpp
  *
+ * GREE air conditioner ir-remote spec(Chinese) -- http://wenku.baidu.com/view/2197b3400b4e767f5bcfce34.html
  * Be aware that, in Uno and other ATMega based boards, long or unsigned long is 32bits
  */


more game logic

more game logic

--- colors_arduino/colors_arduino.ino
+++ colors_arduino/colors_arduino.ino
@@ -1,7 +1,7 @@
 /* colors_arduino.ino
  * by Angela Li
  *
- * Arduino controller for Colors, the best game ever! <3 <3 <3 <3 <3
+ * Arduino controller for Colors, the best game ever! <3
  *
  * I/O and game logic. Listens for inputs (push buttons), updates game state, and sends
  * outputs (LEDs, via shift registers). Delegates sundry cuteness to a Node.js app
@@ -9,14 +9,15 @@
  *
  */

-// Constants are fun!
 const int UP = 0;
 const int RIGHT = 1;
 const int DOWN = 2;
 const int LEFT = 3;

 // Game state
+const int blankBoard[4][4] = {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}};
 int board[4][4];
+int tempBoard[4][4];
 boolean gameInProgress = false;
 boolean buttonPressed = false;

@@ -27,6 +28,9 @@
 const int LEFT_PIN = 0; // TODO
 const int FOO = 13; // TODO

+const int colorMap[8] = {0, 0, 0, 0, 0, 0, 0, 0}; // TODO
+const int pinMap[4]]4]; // TODO
+
 /* Initializes all connections and creates a new game. */
 void setup() {
     // Initialize serial
@@ -52,6 +56,7 @@
         return;
     }

+    // Read inputs
     int upVal = digitalRead(UP_PIN);
     int rightVal = digitalRead(RIGHT_PIN);
     int downVal = digitalRead(DOWN_PIN);
@@ -88,21 +93,10 @@
  ********** GAME METHODS ****************
  ****************************************/

-/* Randomly returns either 0 or 1. */
-int randomTile() {
-    return random(0, 2); /* OMG WOW CHECK THIS ONE OUT */
-
-}
-
-/* Randomly returns the index of a row or column. */
-int randomIndex() {
-    return random(0, 4);
-}
-
 /* Resets internal game state and display. */
 void newGame() {
     // Clear board
-    board = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]];
+    memcpy(board, blankBoard, sizeof(board));

     // Add |initialTiles| new tiles to the board
     int initialTiles = 2;
@@ -115,7 +109,7 @@
     }

     // Update game state
-    gameinProgress = true;
+    gameInProgress = true;

     // Update display
     renderBoard();
@@ -123,6 +117,32 @@

 /* Updates internal game state and display. */
 void makeMove(int dir) {
+    boolean validMove = attemptMove(dir);
+
+    // Don't do anything if the move wasn't valid
+    if (!validMove) {
+        return;
+    }
+
+    // Grab the updated board from |tempBoard|
+    memcpy(board, tempBoard, sizeof(board));
+
+    // Update display
+    renderBoard();
+
+    // Check if there are any valid moves left
+    checkLost();
+}
+
+/* Returns whether or not a given move is valid on the current board.
+ * Stores the updated board (with a new inserted tile) in |tempBoard|. */
+boolean attemptMove(int dir) {
+    // Clone our current board so we can work with it
+    memcpy(tempBoard, board, sizeof(board));
+
+    // Keep track of whether anything moves
+    boolean movedAnythingYet = false;
+
     switch(dir) {
         case UP:
             // TODO
@@ -137,17 +157,53 @@
         break;

         case LEFT:
-            // TODO
-        break;
-    }
-
-    // Update display
-    renderBoard();
-}
-
-void endGame() {
+            for (int i = 0; i < 4; i++) {
+                for (int j = 0; j < 4; j++) {
+                    if (j == 0) {
+                        continue;
+                    }
+
+                    movedAnythingYet = attemptTileMove(i, j, i, j - 1) || movedAnythingYet;
+                }
+            }
+        break;
+    }
+
+    // If no tiles moved, this was an invalid move
+    if (!movedAnythingYet) {
+        return false;
+    }
+
+    // Otherwise, it was valid, so add a new tile
+    // TODO
+
+    return true;
+}
+
+/* Checks whether the game is still winnable. Calls lostGame() if not. */
+void checkLost() {
+    for (int i = 0; i < 4; i++) {
+        if (attemptMove(i)) {
+            return;
+        }
+    }
+
+    // Whoops, we lost the game
+    lostGame();
+}
+
+void lostGame() {
     // Update game state
     gameInProgress = false;
+
+    // TODO ~ Do something to show they lost (womp womp)
+}
+
+void wonGame() {
+    // Update game state
+    gameInProgress = false;
+
+    // TODO ~ Do something to show they won (woohooo!)
 }

 /****************************************
@@ -155,13 +211,55 @@
  ****************************************/

  void renderBoard() {
-    // DEBUGGING ~ Print board to serial
+    // TODO ~ Hahahahahahahaha
+ }
+
+ /* Prints board to serial. For debugging. */
+ void printBoard() {
     for (int i = 0; i < 4; i++) {
         for (int j = 0; j < 4; j++) {
             Serial.print(board[i][j]);
         }
         Serial.println("");
     }
-
-    // (GIANT FUCKING) TODO ~ Display the board
- }+ }
+
+ /****************************************
+ ********** UTILITY METHODS *************
+ ****************************************/
+
+ /* Randomly returns either 0 or 1. */
+int randomTile() {
+    return random(0, 2);
+
+}
+
+/* Randomly returns the index of a row or column. */
+int randomIndex() {
+    return random(0, 4);
+}
+
+/* Returns whether tile at (i, j) can be moved to (i2, j2).
+ * Updates |tempBoard| if a move is possible. */
+boolean attemptTileMove(int i, int j, int i2, int j2) {
+    // No tile in the original space
+    if (tempBoard[i][j] == 0) {
+        return false;
+    }
+
+    // No tile in the new space
+    if (tempBoard[i2][j2] == 0) {
+        tempBoard[i2][j2] = tempBoard[i][j];
+        tempBoard[i][j] = 0;
+        return true;
+    }
+
+    // Identical tiles, collapse them into the new location
+    if (tempBoard[i][j] == tempBoard[i2][j2]) {
+        tempBoard[i][j] = 0;
+        tempBoard[i2][j2]++;
+        return true;
+    }
+
+    return false;
+}