add odds of things happening, instead of looping in a pattern

--- CocaCola/CocaCola.ino
+++ CocaCola/CocaCola.ino
@@ -13,6 +13,7 @@

 // )'(
 // Scenes
+// roughly: anything that calls `digitalWrite()` is a scene

 void lettersAllOn() {
     log('lettersAllOn - START');
@@ -140,11 +141,13 @@
 }

 // Patterns
+// roughly: anything that calls functions that call digitalWrite() is a pattern

 void classicBackground() {
     backgroundOnLeftToRight();
     delay(extended);
     backgroundOffRightToLeft();
+    delay(normal);
 }

 void outsideInOnInsideOutOffBackground(int times, int endingWithLightsOn) {
@@ -167,7 +170,15 @@
 	 }
 }

-void racingOnLeftToRight() {
+void insideOutOutsideInBackground() {
+	outsideInOnInsideOutOffBackground(random(2, 5), true);
+	delay(normal);
+
+	insideOutOnOutsideInOffBackground(random(2, 5), false);
+	delay(normal);
+}
+
+void racingOnLeftToRightBackground() {
 	for (int x = 0; x < sizeof(background); x++) {
 		for (int y = 0; y < sizeof(background) - x - 1; y++) {
 			digitalWrite(background[y], PATTERN_ON);
@@ -206,13 +217,15 @@
 }

 void blinkBackground(int times) {
-   for (int x = 0; x < times; x++) {
-       backgroundAllOff();
-       delay(blinky);
-
-       backgroundAllOn();
-       delay(blinky);
-   }
+	for (int x = 0; x < times; x++) {
+	    backgroundAllOff();
+	    delay(blinky);
+
+	    backgroundAllOn();
+	    delay(blinky);
+	}
+
+	delay(normal);
 }

 // Arduino loop
@@ -220,23 +233,31 @@
 void loop() {
     allOff();

-    lettersOnLeftToRight();
-    classicBackground();
-    delay(normal);
-
-    outsideInOnInsideOutOffBackground(random(2, 5), true);
-    delay(normal);
-
-	 insideOutOnOutsideInOffBackground(random(2, 5), false)
-	 delay(normal);
-
-	 racingOnLeftToRight();
-	 blinkBackground(random(5, 10));
-    delay(normal);
-
-    blinkLetters(random(5, 10));
-
-    lettersAllOff();
+	int possibility = random(0, 100);
+	if (possibility < 70) {
+	    lettersOnLeftToRight();
+	    classicBackground();
+	} else if (possibility < 95) {
+		// if new patterns are added, add a new case statement, and bump up the max random value by one
+        switch (random(0, 2)) {
+       	case 0: { lettersOnLeftToRight(); break; }
+		case 1: { blinkLetters(random(5, 10)); break; }
+		default: { break; }
+		}
+
+		switch(random(0, 4)) {
+		case 0: { classicBackground(); break; }
+		case 1: { insideOutOutsideInBackground(); break; }
+		case 2: { racingOnLeftToRightBackground(); break; }
+		case 3: { blinkBackground(random(5, 10)); backgroundAllOn(); break; }
+		}
+	} else {
+		// super rare things
+	}
+
+   	blinkLetters(random(3, 7));
+
+   	lettersAllOff();

     delay(ish);
 }


Fixed typo

Fixed typo

--- pentair_driver_v2/pentair_driver_v2.ino
+++ pentair_driver_v2/pentair_driver_v2.ino
@@ -64,5 +64,5 @@
 // P: A500 d=10 s=60 c=04 l=01 00 <011A> CTRL is local

 void DoCycleTest(){
-	pentair->PumpStatusCheck(1);
+	pentair.PumpStatusCheck(1); // set to remote, ask status of pump 1, set back to local
 }


removed reference to Note

removed reference to Note

class was deprecated previously

--- chaise2.ino
+++ chaise2.ino
@@ -14,7 +14,6 @@
 #include "ColorCoordinator.h"
 //#include "SerialDebugger.h"
 #include "DxLEDTimers.h"
-#include "Note.h" 			//	a "note" played on the "keys"
 #include "NoteManager.h"	//	manages/coordinates the notes

 #define NOP __asm__ __volatile__ ("nop\n\t")
@@ -35,7 +34,6 @@
 uint16_t loop_count = 0;

 CRGB leds[NUM_LEDS];
-Note notes[NUM_NOTES];

 void welcomePrint() {
 	DEBUG_PRINTLN("Kalimba Chair Software");


Cleaning up.

Cleaning up.

--- examples/VWI/CosaVWItempsensor/CosaVWItempsensor.ino
+++ examples/VWI/CosaVWItempsensor/CosaVWItempsensor.ino
@@ -48,7 +48,7 @@
 DS18B20 indoors(&owi);
 DS18B20 outdoors(&owi);

-// Connect RF433 transmitter to ATtiny/D1
+// Connect RF433 transmitter to ATtiny/D1 alt. Arduino/D9
 VirtualWireCodec codec;
 #if defined(__ARDUINO_TINYX5__)
 VWI::Transmitter tx(Board::D1, &codec);


tidyup

tidyup

--- Arduino/V0p2_Main/V0p2_Main.ino
+++ Arduino/V0p2_Main/V0p2_Main.ino
@@ -97,7 +97,6 @@
   OTV0P2BASE::serialPrintlnAndFlush(s); // Print supplied detail text. // May fail.
   panic();
   }
-

 // Signal position in basic POST sequence as a small positive integer, or zero for done/none.
@@ -330,7 +329,6 @@
   // Assume no RX nor filtering on secondary radio.
 #endif // ENABLE_RADIO_SECONDARY_MODULE

-
 //  posPOST(1, F("Radio OK, checking buttons/sensors and xtal"));

 // Buttons should not be activated DURING boot for user-facing boards; an activated button implies a fault.
@@ -490,7 +488,6 @@
 #endif
 #endif

-
 #if !defined(ALT_MAIN_LOOP) && !defined(UNIT_TESTS)
   // Get current power supply voltage (internal sensor).
   const uint16_t Vcc = Supply_cV.read();
@@ -513,7 +510,6 @@
 #endif
 #endif

-
 #if !defined(ALT_MAIN_LOOP) && !defined(UNIT_TESTS)
 #if 0 && defined(DEBUG)
   DEBUG_SERIAL_PRINTLN_FLASHSTRING("Computing initial target/demand...");
@@ -523,7 +519,6 @@
   NominalRadValve.read();
 #endif
 #endif
-

   // Ensure that the unique node ID is set up (mainly on first use).
   // Have one attempt (don't want to stress an already failing EEPROM) to force-reset if not good, then panic.
@@ -534,9 +529,7 @@
       { panic(F("!Bad ID")); }
     }

-
-  // Initialised: turn heatcall UI LED off.
-//  pinMode(LED_HEATCALL, OUTPUT);
+  // Initialised: turn main/heatcall UI LED off.
   LED_HEATCALL_OFF();

 #if defined(ENABLE_CLI) && defined(ENABLE_CLI_HELP) && !defined(ALT_MAIN_LOOP) && !defined(UNIT_TESTS) && !defined(ENABLE_TRIMMED_MEMORY)
@@ -551,12 +544,6 @@
   setupOpenTRV();
 #endif
   }
-
-
-
-
-
-

 //========================================


Allow for TX only when not already transmitting

--- crossbow.ino
+++ crossbow.ino
@@ -319,6 +319,7 @@
 #ifdef DEVICE_MODE_TX

     if (
+        radioState.deviceState == RADIO_STATE_RX &&
         qsp.protocolState == QSP_STATE_IDLE &&
         qsp.lastTxSlotTimestamp + TX_TRANSMIT_SLOT_RATE < currentMillis
     ) {


don't let commands pile up on the serial bus

--- sunlight_doorman.ino
+++ sunlight_doorman.ino
@@ -243,11 +243,23 @@
         case 'R':
           LEDDenyState();
           delay(1000);
+
+          // clear out the serial bus
+          while(Serial.available()>0){
+            Serial.read();
+          }
+
           break;

         case 'G':
           LEDOKState();
           delay(1000);
+
+          // clear out the serial bus
+          while(Serial.available()>0){
+            Serial.read();
+          }
+
           break;

         case 'Y':


bugfix

bugfix

--- KISS_OSD/KISS_OSD.ino
+++ KISS_OSD/KISS_OSD.ino
@@ -3,6 +3,8 @@
 #include <WiFiServer.h>
 #include <WiFiUdp.h>
 #include <EEPROM.h>
+//#include <iterator>
+//#include <vector>

 /*
 KISS FC OSD v1.0


Allow Triangle plus L/R to move 4th axis.

--- OpenStage/openStage_pollPS3.ino
+++ OpenStage/openStage_pollPS3.ino
@@ -175,13 +175,16 @@

   //Handle the D-Pad: make fixed size (blocking) motions in X, Y, or Z

-  //Z motion (up/down plus triangle button)
+  //Z and z motion (up/down plus triangle button)
   if (PS3.getButtonPress(TRIANGLE)){
     if (PS3.getButtonClick(UP))
       dButtonMove(2,+1);
     if (PS3.getButtonClick(DOWN))
-    dButtonMove(2,-1);
-
+      dButtonMove(2,-1);
+   if (PS3.getButtonClick(LEFT))
+      dButtonMove(3,+1);
+   if (PS3.getButtonClick(RIGHT))
+      dButtonMove(3,-1);
   } else {

     //X motion


editor password is the same as access password - sspin sets to 15 if undefined in config

--- esp-rfid.ino
+++ esp-rfid.ino
@@ -97,11 +97,6 @@
   // Start WebSocket Plug-in and handle incoming message on "onWsEvent" function
   server.addHandler(&ws);
   ws.onEvent(onWsEvent);
-
-  // Configure web server
-  // Add Text Editor (http://esp-rfid.local/edit) to Web Server. This feature likely will be dropped on final release.
-  server.addHandler(new SPIFFSEditor("admin", "admin"));
-
   // Serve all files in root folder
   server.serveStatic("/", SPIFFS, "/");
   // Handle what happens when requested web file couldn't be found
@@ -684,7 +679,10 @@
   Serial.println(F("[ INFO ] Config file found"));
   json.prettyPrintTo(Serial);
   Serial.println();
-  int rfidss = json["sspin"];
+  int rfidss = 15;
+  if (json.containsKey("sspin")) {
+    rfidss = json["sspin"];
+  }
   int rfidgain = json["rfidgain"];
   Serial.println(F("[ INFO ] Trying to setup RFID Hardware"));
   setupRFID(rfidss, rfidgain);
@@ -729,6 +727,8 @@
   // Serve confidential files in /auth/ folder with a Basic HTTP authentication
   server.serveStatic("/auth/", SPIFFS, "/auth/").setDefaultFile("users.htm").setAuthentication("admin", adminpass);
   ws.setAuthentication("admin", adminpass);
+  // Add Text Editor (http://esp-rfid.local/edit) to Web Server. This feature likely will be dropped on final release.
+  server.addHandler(new SPIFFSEditor("admin", adminpass));

   if (wmode == 1) {
     Serial.println(F("[ INFO ] ESP-RFID is running in AP Mode "));


New Arduino code.

New Arduino code.

--- server/server.ino
+++ server/server.ino
@@ -1,167 +1,126 @@
-//Piezo defines
-#define NUM_PIEZOS 1
+#define NUMPADS 1  // number of pads

-// Thresholds
-#define LOW_THRESHOLD 30     //anything < TRIGGER_THRESHOLD is treated as 0
-#define MEDIUM_THRESHOLD 50
-#define HIGH_THRESHOLD 100
+int val;
+String inputString = "";

-//first analog slot of piezos
-#define START_SLOT 0
+// config
+unsigned int piezoThresholds[NUMPADS];
+unsigned int relevantSamples[NUMPADS];
+unsigned int irrelevantNoise[NUMPADS];

-//MIDI baud rate
-#define SERIAL_RATE 38400
+// data
+byte state[NUMPADS];
+unsigned int peak[NUMPADS];
+unsigned long lastNoteStart[NUMPADS];
+unsigned int sampleCount[NUMPADS];

-//Program defines
-//ALL TIME MEASURED IN MILLISECONDS
-#define SIGNAL_BUFFER_SIZE 100
-#define PEAK_BUFFER_SIZE 30
-#define MAX_TIME_BETWEEN_PEAKS 20
-#define MIN_TIME_BETWEEN_NOTES 50
-
-//map that holds the respective threshold to each piezo
-unsigned short thresholdMap[NUM_PIEZOS];
-
-//Ring buffers to store analog signal and peaks
-short currentSignalIndex[NUM_PIEZOS];
-short currentPeakIndex[NUM_PIEZOS];
-unsigned short signalBuffer[NUM_PIEZOS][SIGNAL_BUFFER_SIZE];
-unsigned short peakBuffer[NUM_PIEZOS][PEAK_BUFFER_SIZE];
-
-boolean noteReady[NUM_PIEZOS];
-unsigned short noteReadyVelocity[NUM_PIEZOS];
-boolean isLastPeakZeroed[NUM_PIEZOS];
-
-unsigned long lastPeakTime[NUM_PIEZOS];
-unsigned long lastNoteTime[NUM_PIEZOS];
-
-void setup()
-{
-  Serial.begin(SERIAL_RATE);
-
-  //initialize globals
-  for(short i=0; i<NUM_PIEZOS; ++i)
-  {
-    currentSignalIndex[i] = 0;
-    currentPeakIndex[i] = 0;
-    memset(signalBuffer[i],0,sizeof(signalBuffer[i]));
-    memset(peakBuffer[i],0,sizeof(peakBuffer[i]));
-    noteReady[i] = false;
-    noteReadyVelocity[i] = 0;
-    isLastPeakZeroed[i] = true;
-    lastPeakTime[i] = 0;
-    lastNoteTime[i] = 0;
-  }
-
-  thresholdMap[0] = LOW_THRESHOLD;
-  thresholdMap[1] = LOW_THRESHOLD;
-  thresholdMap[2] = HIGH_THRESHOLD;
-  thresholdMap[3] = HIGH_THRESHOLD;
-  thresholdMap[4] = HIGH_THRESHOLD;
-  thresholdMap[5] = MEDIUM_THRESHOLD;
-}
-
-void loop()
-{
-  unsigned long currentTime = millis();
-
-  for(unsigned short i=0; i<NUM_PIEZOS; ++i)
-  {
-    //get a new signal from analog read
-    unsigned short newSignal = analogRead(i);
-    signalBuffer[i][currentSignalIndex[i]] = newSignal;
-
-    //if new signal is 0
-    if(newSignal < thresholdMap[i])
-    {
-      if(!isLastPeakZeroed[i] && (currentTime - lastPeakTime[i]) > MAX_TIME_BETWEEN_PEAKS)
-      {
-        recordNewPeak(i,0);
-      }
-      else
-      {
-        //get previous signal
-        short prevSignalIndex = currentSignalIndex[i]-1;
-        if(prevSignalIndex < 0) prevSignalIndex = SIGNAL_BUFFER_SIZE-1;
-        unsigned short prevSignal = signalBuffer[i][prevSignalIndex];
-
-        unsigned short newPeak = 0;
-
-        //find the wave peak if previous signal was not 0 by going
-        //through previous signal values until another 0 is reached
-        while(prevSignal >= thresholdMap[i])
-        {
-          if(signalBuffer[i][prevSignalIndex] > newPeak)
-          {
-            newPeak = signalBuffer[i][prevSignalIndex];
-          }
-
-          //decrement previous signal index, and get previous signal
-          prevSignalIndex--;
-          if(prevSignalIndex < 0) prevSignalIndex = SIGNAL_BUFFER_SIZE-1;
-          prevSignal = signalBuffer[i][prevSignalIndex];
-        }
-
-        if(newPeak > 0)
-        {
-          recordNewPeak(i, newPeak);
-        }
-      }
-
-    }
-
-    currentSignalIndex[i]++;
-    if(currentSignalIndex[i] == SIGNAL_BUFFER_SIZE) currentSignalIndex[i] = 0;
+void setup() {
+  pinMode(LED_BUILTIN, OUTPUT);
+  Serial.begin(57600);
+  inputString.reserve(100);
+  for(byte piezo = 0; piezo < NUMPADS; piezo++) {
+    state[piezo] = 0;
+    piezoThresholds[piezo] = 50;
+    relevantSamples[piezo] = 15;
+    irrelevantNoise[piezo] = 100;
   }
 }

-void recordNewPeak(unsigned short slot, short newPeak)
-{
-  isLastPeakZeroed[slot] = (newPeak == 0);
-
-  unsigned long currentTime = millis();
-  lastPeakTime[slot] = currentTime;
-
-  //new peak recorded (newPeak)
-  peakBuffer[slot][currentPeakIndex[slot]] = newPeak;
-
-  //1 of 3 cases can happen:
-  // 1) note ready - if new peak >= previous peak
-  // 2) note fire - if new peak < previous peak and previous peak was a note ready
-  // 3) no note - if new peak < previous peak and previous peak was NOT note ready
-
-  //get previous peak
-  short prevPeakIndex = currentPeakIndex[slot]-1;
-  if(prevPeakIndex < 0) prevPeakIndex = PEAK_BUFFER_SIZE-1;
-  unsigned short prevPeak = peakBuffer[slot][prevPeakIndex];
-
-  if(newPeak > prevPeak && (currentTime - lastNoteTime[slot])>MIN_TIME_BETWEEN_NOTES)
-  {
-    noteReady[slot] = true;
-    if(newPeak > noteReadyVelocity[slot])
-      noteReadyVelocity[slot] = newPeak;
+void loop() {
+
+  for(byte piezo = 0; piezo < NUMPADS; piezo++) {
+    switch(state[piezo]) {
+      case 0:
+        val = analogRead(piezo);
+        if (val >= piezoThresholds[piezo]) {
+          state[piezo] = 1;
+          lastNoteStart[piezo] = millis();
+          sampleCount[piezo] = 1;
+          peak[piezo] = val;
+        }
+        break;
+      case 1:
+        val = analogRead(piezo);
+        if (val > peak[piezo]) {
+          peak[piezo] = val;
+        }
+        sampleCount[piezo]++;
+        if (sampleCount[piezo] >= relevantSamples[piezo]) {
+          Serial.print(piezo);
+          Serial.print(";");
+          Serial.print(peak[piezo]);
+          Serial.print(";");
+          Serial.print(lastNoteStart[piezo]);
+          Serial.print(";");
+          Serial.print(piezoThresholds[piezo]);
+          Serial.print(";");
+          Serial.print(relevantSamples[piezo]);
+          Serial.print(";");
+          Serial.print(irrelevantNoise[piezo]);
+          Serial.println();
+          /*byte buf[11];
+          buf[ 0] = piezo;
+          buf[ 1] = lowByte(peak[piezo]));
+          buf[ 2] = highByte(peak[piezo]));
+          buf[ 3] = (byte) lastNoteStart[piezo];
+          buf[ 4] = (byte) lastNoteStart[piezo] >> 8;
+          buf[ 5] = (byte) lastNoteStart[piezo] >> 16;
+          buf[ 6] = (byte) lastNoteStart[piezo] >> 24;
+          buf[ 7] = lowByte(piezoThresholds[piezo]));
+          buf[ 8] = highByte(piezoThresholds[piezo]));
+          buf[ 9] = lowByte(relevantSamples[piezo]));
+          buf[10] = highByte(relevantSamples[piezo]));
+          buf[11] = lowByte(irrelevantNoise[piezo]));
+          buf[12] = highByte(irrelevantNoise[piezo]));
+          Serial.write(buf, 6);*/
+          state[piezo] = 2;
+        }
+        break;
+      case 2:
+        if (lastNoteStart[piezo] + irrelevantNoise[piezo] <= millis()) {
+          state[piezo] = 0;
+        }
+        break;
+    }
   }
-  else if(newPeak < prevPeak && noteReady[slot])
-  {
-    noteFire(slot, noteReadyVelocity[slot]);
-    noteReady[slot] = false;
-    noteReadyVelocity[slot] = 0;
-    lastNoteTime[slot] = currentTime;
-  }
-
-  currentPeakIndex[slot]++;
-  if(currentPeakIndex[slot] == PEAK_BUFFER_SIZE) currentPeakIndex[slot] = 0;
 }

-void noteFire(unsigned short slot, unsigned short velocity)
-{
-  byte buf[6];
-  buf[0] = slot / 256;
-  buf[1] = slot % 256;
-  buf[2] = velocity / 256;
-  buf[3] = velocity % 256;
-  buf[4] = thresholdMap[slot] / 256;
-  buf[5] = thresholdMap[slot] % 256;
-  Serial.write(buf, 6);
+byte inputBytes[7];
+byte bytesRead = 0;
+void serialEvent(){
+  while (Serial.available()) {
+    // get the new byte:
+    char inChar = (char)Serial.read();
+    // add it to the inputString:
+    inputString += inChar;
+    // if the incoming character is a newline, set a flag
+    // so the main loop can do something about it:
+    if (inChar == '\n') {
+      int div1 = inputString.indexOf(";");
+      int div2 = inputString.indexOf(";", div1 + 1);
+      int div3 = inputString.indexOf(";", div2 + 1);
+      int piezo = inputString.substring(0,div1).toInt();
+      piezoThresholds[piezo] = inputString.substring(div1 + 1, div2).toInt();
+      relevantSamples[piezo] = inputString.substring(div2 + 1, div3).toInt();
+      irrelevantNoise[piezo] = inputString.substring(div3 + 1).toInt();
+      Serial.print("Setting piezo ");
+      Serial.print(piezo);
+      Serial.print(" piezoThresholds ");
+      Serial.print(piezoThresholds[piezo]);
+      Serial.print(" relevantSamples ");
+      Serial.print(relevantSamples[piezo]);
+      Serial.print(" irrelevantNoise ");
+      Serial.println(irrelevantNoise[piezo]);
+      inputString = "";
+    }
+
+
+    /*inputBytes[bytesRead++] = Serial.read();
+    if (bytesRead == 7) {
+      piezoThresholds[inputBytes[0]] = (unsigned int) (inputBytes[1] << 8) | inputBytes[2];
+      relevantSamples[inputBytes[0]] = (unsigned int) (inputBytes[3] << 8) | inputBytes[4];
+      irrelevantNoise[inputBytes[0]] = (unsigned int) (inputBytes[5] << 8) | inputBytes[6];
+      bytesRead = 0;
+    }*/
+  }
 }
-


Added WEMOS D1 prat

Added WEMOS D1 prat


added note

added note

--- examples/ArduinoYun_YunMQTTClient_SSL/ArduinoYun_YunMQTTClient_SSL.ino
+++ examples/ArduinoYun_YunMQTTClient_SSL/ArduinoYun_YunMQTTClient_SSL.ino
@@ -1,5 +1,9 @@
 // This example uses an Arduino Yun or a Yun-Shield
 // and the YunMQTTClient to connect to shiftr.io.
+//
+// Note: You need to upgrade the Arduino Yun to the
+// latest firmware version to have the certificates
+// present.
 //
 // The YunMQTTClient uses a Linux side python
 // script to manage the connection which results


back to the old way

back to the old way

Signed-off-by: Robert Nelson <d6c41255011d14bfa93d8562b946ca186cfa0c7b@gmail.com>

--- BatteryCharger/BatteryCharger.ino
+++ BatteryCharger/BatteryCharger.ino
@@ -16,7 +16,7 @@
 #define RELAY_A0_ON		1
 #define RELAY_A1_ON		2

-int relay_mode=RELAY_UNDEF;
+volatile int relay_mode=RELAY_UNDEF;

 long lastSecond; //The millis counter to see when a second rolls by

@@ -63,22 +63,6 @@
 	digitalWrite(A1, LOW);

 	relay_mode=RELAY_A1_ON;
-}
-
-void turnon(){
-	pinMode(A0, OUTPUT);
-	digitalWrite(A0, HIGH);
-	delay(10);
-	digitalWrite(A0, LOW);
-	relay_mode = RELAY_A0_ON;
-}
-
-void turnoff(){
-	pinMode(A1, OUTPUT);
-	digitalWrite(A1, HIGH);
-	delay(10);
-	digitalWrite(A1, LOW);
-	relay_mode = RELAY_A1_ON;
 }

 void loop () {
@@ -131,20 +115,34 @@
 		//Turn on
 		if ( relay_mode == RELAY_A1_ON ) {
 			if ( busvoltage_A > 13.1 ) {
-				turnon;
+				pinMode(A0, OUTPUT);
+				digitalWrite(A0, HIGH);
+				delay(10);
+				digitalWrite(A0, LOW);
+				relay_mode = RELAY_A0_ON;
 			}
+		}
+		//Turn on
+		if ( relay_mode == RELAY_A1_ON ) {
 			if (( busvoltage_A > 12.6 ) && ( current_mA_B > 400 )) {
-				turnon;
+				pinMode(A0, OUTPUT);
+				digitalWrite(A0, HIGH);
+				delay(10);
+				digitalWrite(A0, LOW);
+				relay_mode = RELAY_A0_ON;
 			}
 		}

 		//Turn off
 		if ( relay_mode == RELAY_A0_ON ) {
 			if ( busvoltage_A < 12.1 ) {
-				turnoff;
+				pinMode(A1, OUTPUT);
+				digitalWrite(A1, HIGH);
+				delay(10);
+				digitalWrite(A1, LOW);
+				relay_mode = RELAY_A1_ON;
 			}
 //			else if (( current_mA_A > 100 ) && ( current_mA_A < 200 )) {
-//				turnoff;
 //			}
 		}


Added comment text.

Added comment text.

--- ArduAutoCar/ArduAutoCar.ino
+++ ArduAutoCar/ArduAutoCar.ino
@@ -10,7 +10,9 @@
 #define trigPin 2
 #define echoPin 3

-const int obstacle_pin = 8;
+const int obstacle_pin = 8; // Use this pin to connect an LED. If an obstacle is detected, the LED will turn on.
+                            // Beware that I have not shown this connection in the schematic, it is simply here for
+                            // debugging.

 class RF24Test: public RF24
 {


Update 005_Osvetlenie.ino

Update 005_Osvetlenie.ino

--- Programy/005_Osvetlenie.ino
+++ Programy/005_Osvetlenie.ino
@@ -1,4 +1,4 @@
-#include "Attiny85_IO_basic.h"
+#include "Attiny84_IO_basic.h"
 Attiny attiny;
 #dafine ciara 0
 void setup() {}


fixed up the html

fixed up the html

--- src/babysteps/websockets/app.ino
+++ src/babysteps/websockets/app.ino
@@ -33,7 +33,7 @@

Connecting...
\

\
         <form id='message-form' action='#' method='post'>\
-            <textarea id='message' placeholder='Write your message here...' required></textarea>
\
+            <input id='message' placeholder='Write your message here...' required></input>\
             <button type='submit'>Send Message</button>\
             <button type='button' id='close'>Close Connection</button>\
         </form>\
@@ -132,23 +132,12 @@
 uint32_t timeout;

 void setup() {
-    // USE_SERIAL.begin(921600);
     USE_SERIAL.begin(115200);

     //Serial.setDebugOutput(true);
     USE_SERIAL.setDebugOutput(true);

-    USE_SERIAL.println();
-    USE_SERIAL.println();
-    USE_SERIAL.println();
-
-    for(uint8_t t = 4; t > 0; t--) {
-        USE_SERIAL.printf("[SETUP] BOOT WAIT %d...\n", t);
-        USE_SERIAL.flush();
-        delay(1000);
-    }
-
-    WiFiMulti.addAP("zeeboo", "zaralily");
+    WiFiMulti.addAP("ssid", "pass");

     while(WiFiMulti.run() != WL_CONNECTED) {
         delay(100);
@@ -169,9 +158,9 @@
     webSocket.loop();
     if (millis() > timeout) {
       char buf[50];
-      sprintf(buf,"%d",millis());
+      sprintf(buf,"{\"uptime\":%d}",millis());
       webSocket.broadcastTXT(buf);
-      timeout = millis() + 5000;
+      timeout = millis() + 1000;
     }
     yield();
 }


changed variable names in positionFunction

--- SensorShirt/PositionFunctions.ino
+++ SensorShirt/PositionFunctions.ino
@@ -4,9 +4,53 @@
 */

 boolean armAtSideRight() {
-  if(backValue > 0 && backValue < 0) {
-    if(shoulderValue > 0 && shoulderValue < 0) {
-      if(underarmValue > 0 && underarmValue < 0) {
+  if(backValue > (armSRBackVal - armSRBackTol) && backValue < (armSRBackVal + armSRBackTol)) {
+    if(shoulderValue > (armSRShoulderVal - armSRShoulderTol) && shoulderValue < (armSRShoulderVal + armSRShoulderTol)) {
+      if(underarmValue > (armSRUnderVal - armSRUnderTol) && underarmValue < (armSRUnderVal + armSRUnderTol) {
+        return true;
+      }
+    }
+  }
+  return false;
+}
+
+boolean armSideRight45() {
+  if(backValue > (armSR45BackVal - armSR45BackTol) && backValue < (armSR45BackVal + armSR45BackTol)) {
+    if(shoulderValue > (armSR45ShoulderVal - armSR45ShoulderTol) && shoulderValue < (armSR45ShoulderVal + armSR45ShoulderTol)) {
+      if(underarmValue > (armSR45UnderVal - armSR45UnderTol) && underarmValue < (armSR45UnderVal + armSR45UnderTol)) {
+        return true;
+      }
+    }
+  }
+  return false;
+}
+
+boolean armSideRight90() {
+  if(backValue > (armSR90BackVal - armSR90BackTol) && backValue < (armSR90BackVal + armSR90BackTol)) {
+    if(shoulderValue > (armSR90ShoulderVal - armSR90ShoulderTol) && shoulderValue < (armSR90ShoulderVal + armSR90ShoulderTol)) {
+      if(underarmValue > (armSR90UnderVal - armSR90UnderTol) && underarmValue < (armSR90UnderVal + armSR90UnderTol)) {
+        return true;
+      }
+    }
+  }
+  return false;
+}
+
+boolean armSideRight135() {
+  if(backValue > (armSR135BackVal - armSR135BackTol) && backValue < (armSR135BackVal + armSR135BackTol)) {
+    if(shoulderValue > (armSR135ShoulderVal - armSR135ShoulderTol) && shoulderValue < (armSR135ShoulderVal + armSR135ShoulderTol)) {
+      if(underarmValue > (armSR135UnderVal - armSR135UnderTol) && underarmValue < (armSR135UnderVal + armSR135UnderTol)) {
+        return true;
+      }
+    }
+  }
+  return false;
+}
+
+boolean armSideRight180() {
+  if(backValue > (armSR180BackVal - armSR180BackTol) && backValue < (armSR180BackVal + armSR180BackTol)) {
+    if(shoulderValue > (armSR180ShoulderVal - armSR180ShoulderTol) && shoulderValue < (armSR180ShoulderVal + armSR180ShoulderTol)) {
+      if(underarmValue > (armSR180UnderVal - armSR180UnderTol) && underarmValue < (armSR180UnderVal + armSR180UnderTol)) {
         return true;
       }
     }
@@ -15,9 +59,9 @@
 }

 boolean armFwdRight45() {
-  if(backValue > 0 && backValue < 0) {
-    if(shoulderValue > 0 && shoulderValue < 0) {
-      if(underarmValue > 0 && underarmValue < 0) {
+  if(backValue > (armFR45BackVal - armFR45BackTol) && backValue < (armFR45BackVal + armFR45BackTol)) {
+    if(shoulderValue > (armFR45ShoulderVal - armFR45ShoulderTol) && shoulderValue < (armFR45ShoulderVal + armFR45ShoulderTol)) {
+      if(underarmValue > (armFR45UnderVal - armFR45UnderTol) && underarmValue < (armFR45UnderVal + armFR45UnderTol)) {
         return true;
       }
     }
@@ -26,9 +70,9 @@
 }

 boolean armFwdRight90() {
-  if(backValue > 0 && backValue < 0) {
-    if(shoulderValue > 0 && shoulderValue < 0) {
-      if(underarmValue > 0 && underarmValue < 0) {
+  if(backValue > (armFR90BackVal - armFR90BackTol) && backValue < (armFR90BackVal + armFR90BackTol)) {
+    if(shoulderValue > (armFR90ShoulderVal - armFR90ShoulderTol) && shoulderValue < (armFR90ShoulderVal + armFR90ShoulderTol)) {
+      if(underarmValue > (armFR90UnderVal - armFR90UnderTol) && underarmValue < (armFR90UnderVal + armFR90UnderTol)) {
         return true;
       }
     }
@@ -37,9 +81,9 @@
 }

 boolean armFwdRight135() {
-  if(backValue > 0 && backValue < 0) {
-    if(shoulderValue > 0 && shoulderValue < 0) {
-      if(underarmValue > 0 && underarmValue < 0) {
+  if(backValue > (armFR135BackVal - armFR135BackTol) && backValue < (armFR135BackVal + armFR135BackTol)) {
+    if(shoulderValue > (armFR135ShoulderVal - armFR135ShoulderTol) && shoulderValue < (armFR135ShoulderVal + armFR135ShoulderTol)) {
+      if(underarmValue > (armFR135UnderVal - armFR135UnderTol) && underarmValue < (armFR135UnderVal + armFR135UnderTol)) {
         return true;
       }
     }
@@ -48,53 +92,9 @@
 }

 boolean armFwdRight180() {
-  if(backValue > 0 && backValue < 0) {
-    if(shoulderValue > 0 && shoulderValue < 0) {
-      if(underarmValue > 0 && underarmValue < 0) {
-        return true;
-      }
-    }
-  }
-  return false;
-}
-
-boolean armSideRight45() {
-  if(backValue > 0 && backValue < 0) {
-    if(shoulderValue > 0 && shoulderValue < 0) {
-      if(underarmValue > 0 && underarmValue < 0) {
-        return true;
-      }
-    }
-  }
-  return false;
-}
-
-boolean armSideRight90() {
-  if(backValue > 0 && backValue < 0) {
-    if(shoulderValue > 0 && shoulderValue < 0) {
-      if(underarmValue > 0 && underarmValue < 0) {
-        return true;
-      }
-    }
-  }
-  return false;
-}
-
-boolean armSideRight135() {
-  if(backValue > 0 && backValue < 0) {
-    if(shoulderValue > 0 && shoulderValue < 0) {
-      if(underarmValue > 0 && underarmValue < 0) {
-        return true;
-      }
-    }
-  }
-  return false;
-}
-
-boolean armSideRight180() {
-  if(backValue > 0 && backValue < 0) {
-    if(shoulderValue > 0 && shoulderValue < 0) {
-      if(underarmValue > 0 && underarmValue < 0) {
+  if(backValue > (armFR180BackVal - armFR180BackTol) && backValue < (armFR180BackVal + armFR180BackTol)) {
+    if(shoulderValue > (armFR180ShoulderVal - armFR180ShoulderTol) && shoulderValue < (armFR180ShoulderVal + armFR180ShoulderTol)) {
+      if(underarmValue > (armFR180UnderVal - armFR180UnderTol) && underarmValue < (armFR180UnderVal + armFR180UnderTol)) {
         return true;
       }
     }
@@ -103,9 +103,9 @@
 }

 boolean backStraight() {
-  if(backValue > 0 && backValue < 0) {
-    if(shoulderValue > 0 && shoulderValue < 0) {
-      if(underarmValue > 0 && underarmValue < 0) {
+  if(backValue > (backStraightBackVal - backStraightBackTol) && backValue < (backStraightBackVal + backStraightBackTol)) {
+    if(shoulderValue > (backStraightShoulderVal - backStraightShoulderTol) && shoulderValue < (backStraightShoulderVal + backStraightShoulderTol)) {
+      if(underarmValue > (backStraightUnderVal - backStraightUnderTol) && underarmValue < (backStraightUnderVal + backStraightUnderTol)) {
         return true;
       }
     }
@@ -114,9 +114,9 @@
 }

 boolean backBentFwd() {
-  if(backValue > 0 && backValue < 0) {
-    if(shoulderValue > 0 && shoulderValue < 0) {
-      if(underarmValue > 0 && underarmValue < 0) {
+  if(backValue > (backBentFBackVal - backBentFBackTol) && backValue < (backBentFBackVal + backBentFBackTol)) {
+    if(shoulderValue > (backBentFShoulderVal - backBentFShoulderTol) && shoulderValue < (backBentFShoulderVal + backBentFShoulderTol)) {
+      if(underarmValue > (backBentFUnderVal - backBentFUnderTol) && underarmValue < (backBentFUnderVal + backBentFUnderTol)) {
         return true;
       }
     }
@@ -125,9 +125,9 @@
 }

 boolean backBentBack() {
-  if(backValue > 0 && backValue < 0) {
-    if(shoulderValue > 0 && shoulderValue < 0) {
-      if(underarmValue > 0 && underarmValue < 0) {
+  if(backValue > (backBentBBackVal - backBentBBackTol) && backValue < (backBentBBackVal + backBentBBackTol)) {
+    if(shoulderValue > (backBentBShoulderVal - backBentBShoulderTol) && shoulderValue < (backBentBShoulderVal + backBentBShoulderTol)) {
+      if(underarmValue > (backBentBUnderVal - backBentBUnderTol) && underarmValue < (backBentBUnderVal + backBentBUnderTol)) {
         return true;
       }
     }


Update RTC_Tests.ino

Update RTC_Tests.ino

--- src/piggy_back_loggers/RTC_Tests.ino
+++ src/piggy_back_loggers/RTC_Tests.ino
@@ -56,12 +56,20 @@
 char *months     = 0;
 byte years       = 0;

+volatile bool FLAG = false;
+
 void setup()
 {
   // put your setup code here, to run once:
   Wire.begin();
   Serial.begin(9600);
   while(!Serial);
+
+  pinMode(7, OUTPUT);
+  digitalWrite(7, HIGH);
+
+  pinMode(3, INPUT);
+  attachInterrupt(digitalPinToInterrupt(3), INT1_ISR, FALLING);

   Serial.println(F("PCF8523 Registers:"));
   Wire.beginTransmission(deviceAddr);
@@ -106,6 +114,11 @@
     reg += 1;
   }
   Serial.println();
+
+  if(seconds >= 128)
+  {
+    Serial.println(F("/!\\ WARNING: RTC oscillator frozen. Recommend reset.\n"));
+  }

   seconds  = (seconds & 0x0F)  + ((seconds >> 4) * 10);
   minutes  = (minutes & 0x0F)  + ((minutes >> 4) * 10);
@@ -227,4 +240,22 @@
 void loop()
 {
   // put your main code here, to run repeatedly:
+  while(1)
+  {
+    if(FLAG)
+    {
+      digitalWrite(7, LOW);
+      FLAG = false;
+      Wire.beginTransmission(deviceAddr);
+      Wire.write(reg_Control_2);
+      Wire.write(byte(0x02));
+      Wire.endTransmission();
+      digitalWrite(7, HIGH);
+    }
+  }
 }
+
+void INT1_ISR()                 // Serial On Button ISR. Activate Serial Interface
+{
+  FLAG = true;
+}


First arduino commit

First arduino commit

--- src/main/arduino/MasterSlave.ino
+++ src/main/arduino/MasterSlave.ino
@@ -5,6 +5,7 @@
 **                    Case Western Reserve University                   **
 **                          2016 Fall Semester                          **
 \*                                                                      */
+
 void setup() {

 }


Better comments

Better comments

--- contrib/specgram.ino
+++ contrib/specgram.ino
@@ -9,12 +9,15 @@

 class SpecGram
 {
-public:
   uint32_t base;
   int y;
   int width, history;

+public:
   void setup(int _width = 256, int _history = 256) {
+    // width is the number of freqency buckets
+    // history is how many samples to keep
+
     GD.cmd_loadimage(0, 0);
     GD.copy(jet, sizeof(jet));
     base = 512UL;
@@ -22,15 +25,15 @@
     history = _history;
     y = 0;

-    GD.cmd_memset(base, 0, 256 * 256);
+    GD.cmd_memset(base, 0, width * history);
     GD.BitmapSource(base);
-    GD.BitmapLayout(PALETTED565, 256, history);
-    GD.BitmapSize(NEAREST, BORDER, REPEAT, 256, history - 1);
+    GD.BitmapLayout(14 /*PALETTED565*/, width, history);
+    GD.BitmapSize(NEAREST, BORDER, REPEAT, width, history - 1);
   }
   void draw() {
     GD.Begin(BITMAPS);
     GD.SaveContext();
-    GD.BitmapTransformF(((y - 254) & 0xff) << 8);
+    GD.BitmapTransformF(((y + 2) & (history - 1)) << 8);
     GD.Vertex2f(16 * 112, 16 * 10);
     GD.RestoreContext();
   }


Remove Esplora include

Remove Esplora include

Now included in DuinoCube library.

--- invaders.ino
+++ invaders.ino
@@ -37,10 +37,6 @@

 #include <DuinoCube.h>
 #include <SPI.h>
-
-#if defined(__AVR_ATmega32U4__)
-#include <Esplora.h>
-#endif  // defined(__AVR_ATmega32U4__)

 #include "game.h"
 #include "game_defs.h"


Updates xadow-watch.ino to use updated watch API

--- xadow-watch.ino
+++ xadow-watch.ino
@@ -48,9 +48,12 @@
   delay(3000);

   oled.fillScreen(COLOR_BLACK);
-  watch_update();
+  watch_show(0xFF);
 }

 void loop() {
-  watch_show();
+  uint8_t changes = watch_tick();
+  if (changes) {
+      watch_show(changes);
+  }
 }


Adds buzzer.into into xadow-watch

Adds buzzer.into into xadow-watch

--- xadow-watch.ino
+++ xadow-watch.ino
@@ -58,10 +58,13 @@
   animation_boot();
   oled.fillScreen(COLOR_BLACK);

+  buzzer_init();
+  buzzer_jingle(0);
+
   menu_init();
   status_init();
   watch_init(now);
-  batlog_init(0x00);
+  batlog_init(0x01);
   sync_init();

   oled.fillScreen(COLOR_BLACK);
@@ -76,6 +79,7 @@

   now = 0;
   checkpoint = millis();
+
 }

 void loop() {


IR codes will now also be printed without debug enabled

--- wled00/wled19_ir.ino
+++ wled00/wled19_ir.ino
@@ -138,10 +138,9 @@

       if (irrecv->decode(&results))
       {
-        DEBUG_PRINT("IR recv\r\n0x");
-        #ifdef WLED_DEBUG
+        Serial.print("IR recv\r\n0x");
         Serial.println((uint32_t)results.value, HEX);
-        #endif
+        Serial.println();
         decodeIR(results.value);
         irrecv->resume();
       }


Change color of notification message

Change color of notification message

--- arduino_src/src/sba/sba.ino
+++ arduino_src/src/sba/sba.ino
@@ -43,9 +43,9 @@

 const String TAG_MESSAGE = "[MESSAGE]";
 const String TAG_NOTIFICATION = "[NOTIFICATION]";
-const uint16_t colors[] = { matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) };
+const uint16_t colors[] = { matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(230, 230, 0) };
 const String notifications[] = {
-  "Tag me, get the 20\% coupon",
+  "Tag me, get the 20\% coupon.",
   "Today is a recycling day!",
   "Have a nice day."
 };


removed date from startup again.. ati8 should be enough.

git-svn-id: d8bfcd070c2c81762cca1b3912331324182919ba@17116 0d6f1817-ed0e-0410-87c9-987e46238f29

--- zimodem/zcommand.ino
+++ zimodem/zcommand.ino
@@ -2613,9 +2613,9 @@
 #endif
   HWSerial.setTimeout(60000);
   serial.prints(ZIMODEM_VERSION);
-  serial.prints(" (");
-  serial.prints(compile_date);
-  serial.prints(")");
+  //serial.prints(" (");
+  //serial.prints(compile_date);
+  //serial.prints(")");
   serial.prints(commandMode.EOLN);
   char s[100];
 #ifdef ZIMODEM_ESP32


Update main.ino

Update main.ino

--- main/main.ino
+++ main/main.ino
@@ -31,21 +31,13 @@
 for (int i=36; i<=52; i++){digitalWrite(i, LOW);delay(250);} // Toggle Leds OFF

 attachInterrupt(JogWheelPinA, sendJogWheel, RISING); // interrupts
+
+
 }

 void loop(){
 void getMidiIn();
 void setMidiOut();
-}
-
-void noteOn(byte channel, byte pitch, byte velocity) {
-  midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
-  MidiUSB.sendMIDI(noteOn);
-}
-
-void noteOff(byte channel, byte pitch, byte velocity) {
-  midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
-  MidiUSB.sendMIDI(noteOff);
 }

 void controlChange(byte channel, byte control, byte value) {
@@ -343,15 +335,14 @@

   // track 0 to 400
   valJogWheel = valJogWheel % CPR;
-
-  mappedvalJogWheel = map(abs(valJogWheel), 0, JogWheelMaxval, 0, 127);
-
+ if (valJogWheel >= JogWheelToggle) { //Prevent Intempestive Move
   controlChange(MidiChannel, 63, 127); // Send CC For JogWheel Activity
+  mappedvalJogWheel = map(abs(valJogWheel), 0, JogWheelMaxval, 0, 127); //map Jog Wheel value from 0 to 127
   JogWheelActive = 1;
-    if (currentDirection = CLOCKWISE){
+    if (currentDirection = CLOCKWISE) {
      controlChange(MidiChannel, 61, mappedvalJogWheel); // Send CC For JogWheel Direction
       }
-     if (currentDirection = COUNTER_CLOCKWISE){
+    if (currentDirection = COUNTER_CLOCKWISE) {
      controlChange(MidiChannel, 62, mappedvalJogWheel); // Send CC For JogWheel Direction
       }
   MidiUSB.flush(); // Be sure CC is Send


fetch CLT from CAN, fix struct

fetch CLT from CAN, fix struct

--- main/main.ino
+++ main/main.ino
@@ -64,8 +64,8 @@

 struct EngineVariable
 {
-  char shortLabel;
-  char longLabel;
+  String shortLabel;
+  String longLabel;
   double currentValue;
   double previousValue;
   double minimum;
@@ -124,7 +124,7 @@
   lcd.createChar(4, fill5);

   lcd.begin(20, 4);
-  lcd.print("RPM");
+  lcd.print(engine_clt.shortLabel);
   lcd.setCursor(0, 2);
   lcd.print("TGT");

@@ -139,7 +139,7 @@
 }

 void loop() {
-
+  //Serial.println(engine_clt.shortLabel);
   currentMillis = millis();
   if(currentMillis - lastMillis >= interval) {
     lastMillis = currentMillis;
@@ -148,8 +148,8 @@
     draw_bar(engine_tgt.currentValue, 3, 10.0, 20.0);

     lcd.setCursor(4, 0);
-    lcd.print(engine_rpm.currentValue);
-    draw_bar(engine_rpm.currentValue, 1, 0.0, 6500.0);
+    lcd.print(engine_clt.currentValue);
+    draw_bar(engine_clt.currentValue, 1, 20.0, 250.0);

   }

@@ -167,7 +167,8 @@
           case 1512:
             engine_map.currentValue = ((buf[0] * 256) + buf[1]) / 10.0;
             engine_rpm.currentValue = buf[2] * 256 + buf[3];
-            Serial.println(engine_rpm.currentValue);
+            engine_clt.currentValue = (buf[4] * 256 + buf[5]) / 10;
+            Serial.println(engine_clt.currentValue);
             break;
           case 1513:


Delete 001.ino

Delete 001.ino

--- examples/codes/001.ino
+++ examples/codes/001.ino
@@ -1,28 +0,0 @@
-include <Keyboard.h>
-
-void setup() {
-Keyboard.begin();
-Keyboard.press(KEY_LEFT_GUI);
-delay(500);
-Keyboard.press('r');
-Keyboard.releaseAll();
-delay(200);
-Keyboard.print("cmd");
-delay(200);
-Keyboard.releaseAll();
-Keyboard.press(KEY_RETURN);
-delay(200);
-Keyboard.print("notepad");
-delay(200);
-Keyboard.releaseAll();
-Keyboard.press(KEY_RETURN);
-delay(200);
-Keyboard.print("Ismail Tasdelen");
-}
-
-void loop() {}
-void typeKey(int key) {
-Keyboard.press(key);
-delay(100);
-Keyboard.release(key);
-}


fix case in examples

fix case in examples

--- firmware/examples/readTag/readtag.ino
+++ firmware/examples/readTag/readtag.ino
@@ -1,4 +1,4 @@
-#include <PN532_I2C.h>
+#include <pn532_i2c.h>
 #include <PN532.h>
 #include <NfcAdapter.h>


Save before ditching arduino.

Save before ditching arduino.

--- firmware/node/node.ino
+++ firmware/node/node.ino
@@ -4,6 +4,7 @@
 #include <EEPROM.h>
 #include <Adafruit_NeoPixel.h>
 #include <avr/pgmspace.h>
+#include <avr/wdt.h>
 #include <stdarg.h>
 #include "parse.h"

@@ -31,10 +32,17 @@
 const uint8_t PACKET_CALIBRATE    = 14;
 const uint8_t PACKET_BRIGHTNESS   = 15;
 const uint8_t PACKET_ANGLE        = 16;
-
-// where in EEPROM our node id is stored
-const int id_address = 0;
-const int calibration_address = 10;
+const uint8_t PACKET_BOOTLOADER   = 17;
+
+// where in EEPROM our node id is stored. The first 16 are reserved for the bootloader
+// Bootloader items
+const uint8_t ee_start_program_offset       = 0;
+const uint8_t ee_have_valid_program_offset  = 1;
+const uint8_t ee_program_version_offset     = 2;
+
+// Node items
+const uint8_t ee_id_offset                  = 16;
+const uint8_t ee_calibration_offset         = 17;

 // ----- globals ------------
 uint8_t    g_error = ERR_OK;
@@ -236,7 +244,7 @@
                 if (g_node_id == NODE_ID_UNKNOWN)
                 {
                     g_node_id = data[0];
-                    EEPROM.write(id_address, g_node_id);
+                    EEPROM.write(ee_id_offset, g_node_id);
                 }
                 break;
             }
@@ -244,7 +252,7 @@
         case PACKET_CLEAR_ID:
             {
                 g_node_id = NODE_ID_UNKNOWN;
-                EEPROM.write(id_address, g_node_id);
+                EEPROM.write(ee_id_offset, g_node_id);
                 break;
             }

@@ -375,6 +383,11 @@
                 set_brightness(b);
                 break;
             }
+        case PACKET_BOOTLOADER:
+            {
+                EEPROM.write(ee_start_program_offset, 0);
+                wdtreset();
+            }
         default:
             dprintf("Invalid packet received\n");
     }
@@ -508,17 +521,22 @@
 {
     uint32_t timer_cal;
     color_t col;
-    uint8_t i;
+    uint8_t i, valid_program;
+
+    // Tell the bootloader that we ran, if we haven't before.
+    EEPROM.get(ee_have_valid_program_offset, valid_program);
+    if (!valid_program)
+        EEPROM.write(ee_have_valid_program_offset, 1);

     Serial.begin(38400);
-    Serial.println("hue-chandelier board!\n");
+    Serial.println("hippie-trap led board!\n");

     g_pixels.begin();
     startup_animation();

-    g_node_id = EEPROM.read(id_address);
-
-    EEPROM.get(calibration_address, timer_cal);
+    g_node_id = EEPROM.read(ee_id_offset);
+
+    EEPROM.get(ee_calibration_offset, timer_cal);
     if (timer_cal > 1 && timer_cal != 0xFFFF)
     {
         g_ticks_per_sec = timer_cal;
@@ -584,7 +602,7 @@

              g_ticks_per_sec = (done - g_calibrate_start) / g_calibrate;
              g_ticks_per_frame = g_ticks_per_sec * g_delay / 1000;
-             EEPROM.put(calibration_address, g_ticks_per_sec);
+             EEPROM.put(ee_calibration_offset, g_ticks_per_sec);

              Serial.read();


update sensor

update sensor

--- sensor/sensor.ino
+++ sensor/sensor.ino
@@ -1,21 +1,21 @@
 int sensorPin = A0;
-int speakerPin = 10;
+int speakerPin = 8;
 int sensorValue = 400;

 void setup() {
   // put your setup code here, to run once:
   pinMode(sensorPin, INPUT);
   pinMode(speakerPin, OUTPUT);
-  Serial.begin(9600);
+//  Serial.begin(9600);
 }

 void loop() {
   // put your main code here, to run repeatedly:
   int light= analogRead(sensorPin);
   if (light > sensorValue){
-    analogWrite(speakerPin, 200);
+    digitalWrite(speakerPin, HIGH);
   } else {
-    analogWrite(speakerPin, 0);
+    digitalWrite(speakerPin, LOW);
   }
-  Serial.println(light);
+//  Serial.println(light);
 }


Wire library is not needed

Wire library is not needed

- saves 1,012 bytes

--- ArduBreakout.ino
+++ ArduBreakout.ino
@@ -10,7 +10,6 @@
  */

 #include <SPI.h>
-#include <Wire.h>
 #include "Arduboy.h"

 #include <EEPROM.h>


Create fixed.ino

Create fixed.ino


Code descriptions added

Code descriptions added

--- mech/mech.ino
+++ mech/mech.ino
@@ -1,17 +1,18 @@
 // Motor 1 = Ch1 = set 1 = Stepper 1 = "L" Motor
-// Motor 2 = Ch2 = set 2 = Stepper 2 = "C" Motor
+// Motor 2 = Ch2 = set 2 = Stepper 2 = "C1" Motor "Cold"
+// Motor 3 = Ch3 = set 3 = Stepper 3 = "C2 Motor "Hot"
 // Motor C: 200 steps 360 degrees revolution (no gear). In quater-step mode 800 steps 360 degrees revolution (no gear).
 // Measured 2964 steps 360 degrees revolution.

-#include "proto/device_id.h"
-#include <AccelStepper.h>   // Accel Stepper library
+#include "proto/device_id.h"  // communication protocol device ID
+#include <AccelStepper.h>     / Accel Stepper library

-#define PJON_ID ID_MECH
-#include "proto/common.h"
+#define PJON_ID ID_MECH       // PJON definition (communication protocol)
+#include "proto/common.h"     // communication protocol library

 AccelStepper stepper1 = AccelStepper(1, 3, 4);  // Custom pinout "L" - Step to D3, Dir to D4 (Default AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5)
-AccelStepper stepper2 = AccelStepper(1, 5, 6);  // Custom pinout "C" - Step to D5, Dir to D6 (Default AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5)
-AccelStepper stepper3 = AccelStepper(1, 7, 8);  // Custom pinout "C" - Step to D7, Dir to D8 (Default AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5)
+AccelStepper stepper2 = AccelStepper(1, 5, 6);  // Custom pinout "C1" - Step to D5, Dir to D6 (Default AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5)
+AccelStepper stepper3 = AccelStepper(1, 7, 8);  // Custom pinout "C2" - Step to D7, Dir to D8 (Default AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5)
 PROTO_MechStatus status;

 const byte ledPin = 13;     // Initialise LED for indication


Added optocoupler test

Added optocoupler test

--- Testing/optocoupler.ino
+++ Testing/optocoupler.ino
@@ -1,4 +1,34 @@
 // Arduino Interactive: Optocoupler Example
 // Copyright 2015 Jeroen Doggen, Christian Munk, Tom Peeters

-TODO
+
+int optoCoupler1 = 10;
+// TODO add other pins
+
+int delayTime = 10000;                            // 10 seconds
+
+void setup()
+{
+  Serial.begin(9600);                             // initialize serial communication:
+  pinMode(optoCoupler1, OUTPUT);
+  // TODO other pins;
+}
+
+void loop()
+{
+  takePicture();
+  delay(delayTime);                               // delay to avoid overloading the serial port buffer
+}
+
+
+void takePicture()
+{
+  digitalWrite(led, HIGH);
+  delay(100);                                     // wait a short time for the camera to complete
+  digitalWrite(led, LOW);
+}
+
+void focus()
+{
+  // TODO: similar to takePicture;
+}


Update RF24MeshMaster.ino

Update RF24MeshMaster.ino

--- examples/NanoRFMesh/RF24MeshMaster.ino
+++ examples/NanoRFMesh/RF24MeshMaster.ino
@@ -21,7 +21,7 @@
 #include <EEPROM.h>

 /***** Configure the chosen CE,CS pins *****/
-RF24 radio(10, 9);
+RF24 radio(7, 8);
 RF24Network network(radio);
 RF24Mesh mesh(radio, network);
 struct payload_t {


Updated Ex 36 FM

Updated Ex 36 FM

--- exercises/36/Exercise36/Exercise36.ino
+++ exercises/36/Exercise36/Exercise36.ino
@@ -1,4 +1,4 @@
-//**************ACTIVITES TO CHECK WHILE GRADING**********BEGIN*********
+//**************ACTIVITIES TO CHECK WHILE GRADING**********BEGIN*********
 //
 //1.	Verify that LEDs blink in the order 2, 3, 4, 5, 6, 7, 8, 15, 14, 13, 12, 11, 10, 9
 //2.	Check to make sure sequenceLEDsCounterClockwise repeats RepeatCount amount of times.
@@ -22,6 +22,7 @@
 	sequenceLEDsCounterClockwise(150, 150, 3);
 	delay(5000);
 }
+
 void sequenceLEDsCounterClockwise(int LEDOnTime, int LEDOffTime, int RepeatCount)
 {
   int count;
@@ -44,6 +45,4 @@
       delay(LEDOffTime);
     }
   }
-}
-
-
+}


Ajout de l'accelerometre

Ajout de l'accelerometre

--- eqbe.ino
+++ eqbe.ino
@@ -1,5 +1,6 @@
 #include "painlessMesh.h"
 #include "FastLED.h"
+#include<Wire.h>
 FASTLED_USING_NAMESPACE

 // Configuration
@@ -49,6 +50,12 @@
 void (*gActivePattern)();
 void (*gSelectedPattern)();
 bool gIsOurSentPattern = true;
+
+// Variables used in CheckAccel() routine
+uint8_t MPU_addr=0x68;
+int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ; //These will be the raw data from the MPU6050.;
+#define ACCELEROMETER_ORIENTATION 4     // 0, 1, 2, 3 or 4 to set the orientation of the accerometer module
+int a_forward=0,a_sideway=0,a_vertical=0;

 void solid()
 {
@@ -369,4 +376,30 @@
   }
 }

-
+void CheckAccel(){
+  // Reads acceleration from MPU6050 to evaluate current condition.
+  // Tunables:
+  // Output values: still, cruising, braking, fallen, unknown
+
+  // Get accelerometer readings
+  Wire.beginTransmission(MPU_addr);
+  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
+  Wire.endTransmission(false);
+  Wire.requestFrom(MPU_addr,(size_t)14,true);  // request a total of 14 registers
+  AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
+  AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
+  AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
+  Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
+  GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
+  GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
+  GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
+
+  // Convert to expected orientation - includes unit conversion to "cents of g" for MPU range set to 2g
+  a_forward = (ACCELEROMETER_ORIENTATION == 0?-AcX:(ACCELEROMETER_ORIENTATION == 1?-AcX:(ACCELEROMETER_ORIENTATION == 2?-AcX:(ACCELEROMETER_ORIENTATION == 3?-AcY:AcY))))/164.0;
+  a_sideway = (ACCELEROMETER_ORIENTATION == 0?AcY:(ACCELEROMETER_ORIENTATION == 1?AcZ:(ACCELEROMETER_ORIENTATION == 2?-AcZ:(ACCELEROMETER_ORIENTATION == 3?AcZ:-AcZ))))/164.0;
+  a_vertical = (ACCELEROMETER_ORIENTATION == 0?AcZ:(ACCELEROMETER_ORIENTATION == 1?-AcY:(ACCELEROMETER_ORIENTATION == 2?AcY:(ACCELEROMETER_ORIENTATION == 3?AcX:AcX))))/164.0;
+
+  Serial.print("AcX: "); Serial.print(AcX);Serial.print(" AcY: "); Serial.print(AcY);Serial.print(" AcZ: "); Serial.print(AcZ);
+  Serial.print("a_forward:");Serial.print(a_forward);Serial.print(" a_sideway:");Serial.print(a_sideway);Serial.print(" a_vertical:");Serial.println(a_vertical);
+}
+


fix accel setup

fix accel setup

--- eqbe.ino
+++ eqbe.ino
@@ -329,7 +329,20 @@
   FastLED.setBrightness(BRIGHTNESS);
   fill_solid(leds, NUM_LEDS, CHSV(HUE_GREEN, 255, 100));
   FastLED.show();
-
+
+// Set up MPU 6050:
+  Wire.begin();
+  #if ARDUINO >= 157
+    Wire.setClock(400000UL); // Set I2C frequency to 400kHz
+  #else
+    TWBR = ((F_CPU / 400000UL) - 16) / 2; // Set I2C frequency to 400kHz
+  #endif
+
+  Wire.beginTransmission(MPU_addr);
+  Wire.write(0x6B);  // PWR_MGMT_1 register
+  Wire.write(0);     // set to zero (wakes up the MPU-6050)
+  Wire.endTransmission(true);
+
   wasPressed = false;
   pinMode(PUSH_BUTTON_PIN, INPUT_PULLUP);

@@ -364,7 +377,7 @@

   updatePattern();

-  EVERY_N_MILLISECONDS( 2000 ) {
+  EVERY_N_MILLISECONDS( 500 ) {
     CheckAccel();
   }

@@ -403,7 +416,8 @@
   a_sideway = (ACCELEROMETER_ORIENTATION == 0?AcY:(ACCELEROMETER_ORIENTATION == 1?AcZ:(ACCELEROMETER_ORIENTATION == 2?-AcZ:(ACCELEROMETER_ORIENTATION == 3?AcZ:-AcZ))))/164.0;
   a_vertical = (ACCELEROMETER_ORIENTATION == 0?AcZ:(ACCELEROMETER_ORIENTATION == 1?-AcY:(ACCELEROMETER_ORIENTATION == 2?AcY:(ACCELEROMETER_ORIENTATION == 3?AcX:AcX))))/164.0;

-  Serial.print("AcX: "); Serial.print(AcX);Serial.print(" AcY: "); Serial.print(AcY);Serial.print(" AcZ: "); Serial.print(AcZ);
-  Serial.print("a_forward:");Serial.print(a_forward);Serial.print(" a_sideway:");Serial.print(a_sideway);Serial.print(" a_vertical:");Serial.println(a_vertical);
-}
-
+  Serial.printf("f:%d s:%d v:%d\n", a_forward,a_sideway,a_vertical);
+
+
+}
+


Performance Tweaks

Performance Tweaks

--- quadcopter/quadcopter.ino
+++ quadcopter/quadcopter.ino
@@ -314,7 +314,7 @@

 }

-void updateMotors(){
+inline void updateMotors(){

   a.write(va);
   c.write(vc);
@@ -323,7 +323,7 @@

 }

-void arm(){
+inline void arm(){

   a.write(ESC_MIN);
   b.write(ESC_MIN);
@@ -334,11 +334,11 @@

 }

-void dmpDataReady() {
+inline void dmpDataReady() {
     mpuInterrupt = true;
 }

-void initRC(){
+inline void initRC(){
   pinMode(RC_PWR, OUTPUT);
   digitalWrite(RC_PWR, HIGH);

@@ -366,7 +366,7 @@
   }
 }

-void initESCs(){
+inline void initESCs(){

   a.attach(ESC_A);
   b.attach(ESC_B);
@@ -379,7 +379,7 @@

 }

-void initBalancing(){
+inline void initBalancing(){

   bal_axes = 0;
   bal_ac = 0;
@@ -387,7 +387,7 @@

 }

-void initRegulators(){
+inline void initRegulators(){

   pitchReg.SetMode(AUTOMATIC);
   pitchReg.SetOutputLimits(-PID_PITCH_INFLUENCE, PID_PITCH_INFLUENCE);
@@ -400,36 +400,36 @@

 }

-void rcInterrupt1(){
+inline void rcInterrupt1(){
    if(!interruptLock) ch1 = micros() - rcLastChange1;
    rcLastChange1 = micros();
 }

-void rcInterrupt2(){
+inline void rcInterrupt2(){
   if(!interruptLock) ch2 = micros() - rcLastChange2;
   rcLastChange2 = micros();
 }

-void rcInterrupt3(){
+inline void rcInterrupt3(){
   if(!interruptLock) ch3 = micros() - rcLastChange3;
   rcLastChange3 = micros();
 }

-void rcInterrupt4(){
+inline void rcInterrupt4(){
   if(!interruptLock) ch4 = micros() - rcLastChange4;
   rcLastChange4 = micros();
 }

-void rcInterrupt5(){
+inline void rcInterrupt5(){
   if(!interruptLock) ch5 = micros() - rcLastChange5;
   rcLastChange5 = micros();
 }

-void acquireLock(){
+inline void acquireLock(){
   interruptLock = true;
 }

-void releaseLock(){
+inline void releaseLock(){
   interruptLock = false;
 }


時刻繰り上がり時のNTPアクセス対策

時刻繰り上がり時のNTPアクセス対策

--- 2_example/example25_fs/example25_fs.ino
+++ 2_example/example25_fs/example25_fs.ino
@@ -52,6 +52,7 @@
     if(time<100){
         TIME=getNTP(NTP_SERVER,NTP_PORT);   // NTPを用いて時刻を取得
         if(TIME)TIME-=millis()/1000;        // 経過時間を減算
+        while(millis()<100)delay(1);        // 100ms超過待ち
     }
     if((time/20)%50==0){                    // 1秒間隔で以下を実行
         if(LCD_EN){                                         // LCD_ENが0以外の時


Adds code to read from the gyroscope sensor

--- drone_control/drone_control.ino
+++ drone_control/drone_control.ino
@@ -1,7 +1,7 @@
 /*
  *
  */
-
+#include <Adafruit_L3GD20.h>
 #include <Servo.h>
 #include "drone_common.h"

@@ -21,6 +21,7 @@
 ulong TimeDelta;
 bool ManualControl;

+Adafruit_L3GD20 gyro;

 void SetMotor(int MotorID, int value)
 {
@@ -73,6 +74,9 @@
     rotor[i].attach(i); // Set up ESC channels. TODO: Find the offset for i in this case
     SetMotor(i, SERVO_OFF);
   }
+
+  gyro.begin(gyro.L3DS20_RANGE_250DPS);
+
   delay(5000);
   LiftOff(1.5);

@@ -100,6 +104,8 @@

 void loop(){
+  gyro.read();
+
   if (ManualControl)
   {
     const int CONTROLLER_MAX = 5;


Added mouse and keyboard functionality

Added mouse and keyboard functionality

--- Keyboard_Mouse/Keyboard_Mouse.ino
+++ Keyboard_Mouse/Keyboard_Mouse.ino
@@ -1,3 +1,6 @@
+#include <Keyboard.h>
+#include <Mouse.h>
+
 const int TOGGLE_BTN = 2;
 const int LEFT_BTN = 12;
 const int RIGHT_BTN = 11;
@@ -14,12 +17,16 @@
   pinMode(LEFT_BTN, INPUT);
   pinMode(RIGHT_BTN, INPUT);
   pinMode(LED, OUTPUT);
+
+  Keyboard.begin();
+  Mouse.begin();
 }

 //this code runs continuously
 void loop() {

   if (digitalRead(TOGGLE_BTN)){
+    //invert the state of the boolean variable
     toggleOn = !toggleOn;
     if (toggleOn){
       digitalWrite(LED, HIGH);
@@ -31,10 +38,15 @@

   if (toggleOn) {
     if (digitalRead(LEFT_BTN)){
-      Serial.println("Read left button");
+      Keyboard.print("LB\n"); //Keyboard.println() doesn't actually put text on the next line?
+      //keyboard doesn't respond instantaneously, allow 2 millisecond delay
+      delay(2);
     }
     else if (digitalRead(RIGHT_BTN)){
-      Serial.println("Read right button");
+      //motion onscreen is always relative to the cursor's current location
+      Mouse.move(1, 2, 0); // parameters: xVal, yVal, scroll wheel
+      //mouse doesn't respond instantaneously, allow 2 millisecond delay
+      delay(2);
     }
   }
 }


limit month to correct values

limit month to correct values

--- vibrate_alarm_clock.ino
+++ vibrate_alarm_clock.ino
@@ -178,7 +178,16 @@
         newTime = DateTime(now.year(), now.month(), now.day() - 1, now.hour(), now.minute(), now.second());
         break;
       case T_MONTH:
-        newTime = DateTime(now.year(), now.month() - 1, now.day(), now.hour(), now.minute(), now.second());
+      {
+        int month = now.month();
+        if(month == 1){
+          month = 12;
+        } else {
+          month--;
+        }
+
+        newTime = DateTime(now.year(), month, now.day(), now.hour(), now.minute(), now.second());
+      }
         break;
       case T_YEAR:
         newTime = DateTime(now.year() - 1, now.month(), now.day(), now.hour(), now.minute(), now.second());
@@ -335,7 +344,15 @@
         newTime = DateTime(now.year(), now.month(), now.day() + 1, now.hour(), now.minute(), now.second());
         break;
       case T_MONTH:
-        newTime = DateTime(now.year(), now.month() + 1, now.day(), now.hour(), now.minute(), now.second());
+      {
+        int month = now.month();
+        if(month == 12){
+          month = 1;
+        } else {
+          month++;
+        }
+        newTime = DateTime(now.year(), month, now.day(), now.hour(), now.minute(), now.second());
+      }
         break;
       case T_YEAR:
         newTime = DateTime(now.year() + 1, now.month(), now.day(), now.hour(), now.minute(), now.second());


Updated node.

Updated node.

--- node/node.ino
+++ node/node.ino
@@ -41,7 +41,7 @@
 // See the tutorial on how to obtain these addresses:
 // http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

-DeviceAddress Probe01 = { 0x28, 0xFF, 0x79, 0x92, 0x3E, 0x04, 0x00, 0x21 };
+DeviceAddress Probe01 = { 0x28, 0xFF, 0x7D, 0xBF, 0x3C, 0x04, 0x00, 0x9C };

 void setup() {


Change to include Redbear Duo

Change to include Redbear Duo

--- firmware/examples/RFID_UART.ino
+++ firmware/examples/RFID_UART.ino
@@ -1,6 +1,6 @@
 // RFID_UART.ino

-#if defined (SPARK)
+#if defined (PLATFORM_ID)
 #include "SeeedRFID/SeeedRFID.h"
 #else
 #include <SoftwareSerial.h>


Fixed module to work with serial on lower debug level

--- HMTL_Modules/HMTL_Module/HMTL_Module.ino
+++ HMTL_Modules/HMTL_Module/HMTL_Module.ino
@@ -72,7 +72,7 @@
     active_programs[i] = NULL;
   }

-  int32_t outputs_found = hmtl_setup(&config, readoutputs,
+  int32_t outputs_found = hmtl_setup(&config, readoutputs,
 				     outputs, objects, HMTL_MAX_OUTPUTS,
 				     &rs485, &pixels, NULL,
 				     &rgb_output, &value_output,
@@ -112,7 +112,7 @@
 		  print_hex_string(msg, offset)
 		  );
     DEBUG_PRINT_END();
-    DEBUG_PRINTLN(DEBUG_HIGH, "ok");
+    Serial.println(F("ok")); // XXX: This should come from HMTLprotocol.h

     if ((msg_hdr->address != config.address) ||
 	(msg_hdr->address == RS485_ADDR_ANY)) {


Fixing temperature constant

Fixing temperature constant

--- Medium-Projects/LeakyIntegratino/LeakyIntegratino.ino
+++ Medium-Projects/LeakyIntegratino/LeakyIntegratino.ino
@@ -6,7 +6,7 @@
 double Vm     = 0.0; // membrane potential
 double Vth    = 1.0; // threshold potential
 double Vr     = 0.0; // resetting potential
-double g      = 2.0; //
+double g      = 1.5; //
 int inCurrent = 0;   // input current

 double PulseAmplitude = 5.0; // amplitude of the button pulse
@@ -27,7 +27,7 @@
 // Temperature sensor
 int tempPin = 1;        // Analog temperature sensor pin
 int reading;            // Reading from sensor
-float NersntEffectCons = 0.01;
+float NersntEffectCons = 0.05;

 // Analogical output


tried some buffermethods

tried some buffermethods

--- weather-clock.ino
+++ weather-clock.ino
@@ -1,8 +1,11 @@

 #include <SPI.h>
-#include <WiFi101.h>
+#include "WiFi101.h"
 #include "keys.h"
+#include "ArduinoJson.h"
+
+// using json = nlohmann::json;

 char ssid[] = "Human Condition Global 2.4GHz"; //  your network SSID (name)
 char pass[] = WIFI_PASS;    // your network password (use for WPA, or use as key for WEP)
@@ -12,8 +15,9 @@
 // if you don't want to use DNS (and reduce your sketch size)
 // use the numeric IP instead of the name for the server:
 //IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
-char server[] = "http://api.wunderground.com";
+char server[] = "api.wunderground.com";

+char c;
 // Initialize the Ethernet client library
 // with the IP address and port of the server
 // that you want to connect to (port 80 is default for HTTP):
@@ -51,8 +55,8 @@
   if (client.connect(server, 80)) {
     Serial.println("connected to server");
     // Make a HTTP request:
-    client.println("GET //api/" + String(WEATHER_KEY) + "/conditions/q/40.7055211,-73.9394487.json");
-    client.println("Host: http://api.wunderground.com");
+    client.println("GET /api/" + String(WEATHER_KEY) + "/forecast/q/40.7055211,-73.9394487.json HTTP/1.1");
+    client.println("Host: api.wunderground.com");
     client.println("Connection: close");
     client.println();
   }
@@ -61,8 +65,22 @@
 void loop() {
   // if there are incoming bytes available
   // from the server, read them and print them:
-  while (client.available()) {
-    char c = client.read();
+  // uint8_t json[1000];
+  // for(int i=0; i < 1000; i++) {
+  //   json[i] = 50;
+  // }
+
+  // while (client.available()) {
+    // client.read(json, 1000);
+    // StaticJsonBuffer<10000000000> jsonBuffer;
+    // JsonObject& httpRes = jsonBuffer.parseObject(c);
+    // const char* temp = httpRes["hourly"];
+    // Serial.println(client.available());
+
+  // }
+
+  while(client.available()) {
+    c = client.read();
     Serial.write(c);
   }

@@ -73,8 +91,8 @@
     client.stop();

     // do nothing forevermore:
+  }
     while (true);
-  }
 }


Fixed commetns.

Fixed commetns.

--- BotCode/movement.ino
+++ BotCode/movement.ino
@@ -2,7 +2,7 @@
 bool timeUp = false;
 // Corrects drift in the gyroscope
 double gyroCorrect = 0.015;
-// Used to prevent bot from slowing down too much
+// Prevents the automatic speed correction from slowing down too much
 uint8_t rightForwardSpeed_max = rightForwardSpeed;
 uint8_t rightBackwardSpeed_min = rightBackwardSpeed;

@@ -28,6 +28,7 @@
     Y_calibration += event.magnetic.y;
     delay(10);
   }
+  // Calculates a correction for the gyroscope
   double cur = 0;
   for (int i = 0; i < 10; i++)
   {
@@ -304,6 +305,7 @@
   elapsedMillis mils;
   sensors_event_t event;
   float total = 0;
+  // Calculates a correction for the gyroscope
   double cur = 0;
   for (int i = 0; i < 10; i++)
   {


fix code

fix code

--- little-switches/arduino/galoppo/galoppo.ino
+++ little-switches/arduino/galoppo/galoppo.ino
@@ -57,7 +57,6 @@
   if (keyboard.available()) {

     char c = keyboard.read();
-    Serial.println

     if (c == '1') {
       digitalWrite(zampaAS,HIGH);


That was easy. First light :-)

That was easy. First light :-)

--- kast.ino
+++ kast.ino
@@ -1,11 +1,34 @@
 // LED controller for the light in a bookcase.
 // Herman Kopinga herman@kopinga.nl for 212 Fahrenheit 212f.nl

+// Pin definitions.
+#define LEDOUT 12
+#define STATUSLED 11
+
+// Globals
+unsigned long nextBlink;
+
 void setup() {
-
+  // Speed is ignored by Teensy.
+  Serial.begin(115200);
+
+  pinMode(A0, INPUT);
+  pinMode(A1, INPUT);
+  pinMode(A2, INPUT);
+  pinMode(A3, INPUT);
+  pinMode(STATUSLED, OUTPUT);
+  pinMode(LEDOUT, OUTPUT);
 }

 void loop() {
-
+  // Blink internal LED: working.
+  if (millis() > nextBlink) {
+    digitalWrite(STATUSLED, !digitalRead(STATUSLED));
+    nextBlink = millis() + 1000;
+  }
+  // If sound detected, restart countdown and fade in.
+
+  // Measure light intensity, map to output power (through adjustment pot).
+  analogWrite(LEDOUT, 15);
 }


add find wall

add find wall

--- main.ino
+++ main.ino
@@ -87,6 +87,8 @@
     goalY = 1;
     currentX = 10;
     currentY = 7;
+    startX = 10;
+    startY = 7;
     pwd = 1;
     int counter_for_straighten = stepToStraighten; //every 3 or 5 step do a straighten
     exploration();
@@ -152,19 +154,91 @@
     //go back
     //find farthest obstacle according to the distance
     //go that way
-    //
+
+

     /*
     HOWTO find closest obstacle
     360 turning. use sensor to see the distance
      */
-
+    f_dis = min(shortIR_RF.getDis(), shortIR_LF.getDis());
+    int tempDis = f_dis;
+    int tempMin = 0;
+    for (int i = 1; i <= 4; ++i) {
+        turn(1);
+        f_dis = min(shortIR_RF.getDis(), shortIR_LF.getDis());
+        if (tempDis < f_dis && f_dis - tempDis > 50) {
+            //ignore small difference
+            tempMin = i;
+            tempDis = f_dis;
+        }
+    }
+
+    for (int i = tempMin; i > 0; --i) {
+        turn(1);
+    }
+
+    u_L_dis = u_F.getDis();
+    u_R_dis = u_R.getDis();
+
+    farthestX = currentX;
+    farthestY = currentY;
+    farthestDis = max(u_L_dis, u_R_dis);
+
+    while (1) {
+        u_F_dis = u_F.getDis();
+        if (u_F_dis <= 6) {
+            break;
+        }
+        goAhead(1);
+        u_L_dis = u_F.getDis();
+        u_R_dis = u_R.getDis();
+        if (u_L_dis > farthestDis) {
+            farthestDis = u_L_dis;
+            farthestX = currentX;
+            farthestY = currentY;
+        }
+        if (u_R_dis > farthestDis) {
+            farthestDis = u_R_dis;
+            farthestX = -currentX;
+            farthestY = -currentY;
+        }
+    }
+
+    straighten();
+    //auto fix
+
+
     /*
     HOWTO find fasest obstacle
-    go back
-    find the farthest distance
+    1. go back
+    2. find the farthest distance
     take this as the wall?
+    3. go to the wall
      */
+    turn(1);
+    turn(1);
+
+    grids2goback = abs(farthestX - currentX) + abs(farthestY - currentY);
+    goAhead(grids2goback);
+
+    if (farthestX < 0) {
+        turn(1);
+    } else {
+        turn(-1);
+
+    }
+    //found where is the wall
+
+    //go to the wall
+    while (1) {
+        u_F_dis = u_F.getDis();
+        if (u_F_dis <= 6) {
+            break;
+        }
+        goAhead(1);
+    }
+    straighten();
 }

 void bridesheadRevisited() {


Remoçaõ de comentário.

Remoçaõ de comentário.

--- quad/quad.ino
+++ quad/quad.ino
@@ -124,7 +124,7 @@

 void writeMotor()
 {
-  val = map(rcThrottle, MIN_CH1, MAX_CH1, 1000, 2000);     // scale it to use it with the servo (value between 0 and 180)
+  val = map(rcThrottle, MIN_CH1, MAX_CH1, 1000, 2000);
   motorFL.writeMicroseconds(val);
   motorFR.writeMicroseconds(val);
   motorBL.writeMicroseconds(val);


Finally got the issues worked out on the logistic display levels. Apparently, calculating number of milliseconds in 30 minutes did not work out as expected and I ended up hard-coding the value.

--- SunriseAlarm.ino
+++ SunriseAlarm.ino
@@ -206,15 +206,17 @@

 //TimerOne timer;
 const int16_t maxBright = 1024; // resolution of TimerOne::pwm (10 bits)
-const int thirtyminutes = 1800; // 1800 seconds = 30 minutes
+const int thirtyMinutes = 30;
+const int16_t thirtyMinutesInSeconds = 1800; // 1800 seconds = 30 minutes
 //const int timerPeriod = 1000; // 1000us = 1 kHz flicker
 const int16_t maxTime = 3600; // 1.0 hours
 const int forward_delay = 15;
 const int rewind_delay = 150;
+const uint32_t millisecondsIn30Minutes = 1800000;

 int defaultSunSetDelta = 15; // minutes

-const unsigned long modeInactivePeriod = 30000; // 30 seconds
+const uint32_t modeInactivePeriod = 30000; // 30 seconds

 AT24Cxx eeprom;
 // This is the time you want to get up.  Lights will start 30 minutes before.
@@ -240,7 +242,7 @@
 uint8_t dot_bit = 0x80;

 RTC_DS3231 RTC;
-unsigned long synchronized_clock_millis;
+uint32_t synchronized_clock_millis;
 ClockTime synchronized_clock_time;
 ClockTime current_clock_time;

@@ -317,8 +319,8 @@
 int debounceInterval = 10;
 int debounceDigitalRead(int pin) {
   int lastResult = digitalRead(pin);
-  unsigned long lastRead = millis();
-  while (static_cast<unsigned long>(millis() - lastRead) < debounceInterval) {
+  uint32_t lastRead = millis();
+  while (static_cast<uint32_t>(millis() - lastRead) < debounceInterval) {
     int result = digitalRead(pin);
     if (result != lastResult) {
       lastResult = result;
@@ -341,10 +343,11 @@

 const uint8_t candleLight[3] = {255, 147, 41};
 const uint8_t sunLight[3] = {255, 255, 255};
+const uint8_t tungsten100W[3] = {255, 214, 170};
+const uint8_t halogen[3] = {255, 241, 224};
 const uint8_t testingLight[3] = {50, 0, 0};
 uint8_t targetColor[3] = {255, 0, 0};

-unsigned long millisecondsIn30Minutes = 1800000;
 uint8_t minRGBLevel = computeMinRGBLevel(targetColor);
 uint16_t totalDimmerSteps = minRGBLevel * NUM_LED;

@@ -362,7 +365,7 @@
 {
   for (uint8_t i = 0 ; i < 3 ; ++i)
   {
-    targetColor[i] = sunLight[i];
+    targetColor[i] = tungsten100W[i];
   }
   minRGBLevel = computeMinRGBLevel(targetColor);
   totalDimmerSteps = minRGBLevel * NUM_LED;
@@ -396,7 +399,7 @@
   strip.show();
 }

-unsigned long linearBrightOfMilliseconds(unsigned long milliseconds)
+uint32_t linearBrightOfMilliseconds(uint32_t milliseconds)
 {
   uint16_t stepNumber = (totalDimmerSteps * milliseconds) / millisecondsIn30Minutes;
   linearBrightOfStep(stepNumber);
@@ -405,17 +408,23 @@
 void logisticBrightOfStep(uint16_t step)
 {
   float p = ((float)step) / ((float)totalDimmerSteps);
+//  Serial.print("logisticBrightOfStep p = "); Serial.println(p);
   float L = 1.0;
   float k = 20.0;
   float x0 = 0.5;
   float logisticP = L / (1 + exp(-k * (p - x0)));
+//  Serial.print("logisticBrightOfStep logisticP = "); Serial.println(logisticP);
   uint16_t logisticStep = logisticP * totalDimmerSteps;
+//  Serial.print("logisticBrightOfStep logisticStep =               "); Serial.println(logisticStep);
   linearBrightOfStep(logisticStep);
 }

-void logisticBrightOfMilliseconds(unsigned long milliseconds)
+void logisticBrightOfMilliseconds(uint32_t milliseconds)
 {
-  uint16_t stepNumber = (totalDimmerSteps * milliseconds) / millisecondsIn30Minutes;
+  uint32_t stepNumber = ((uint32_t)(totalDimmerSteps) * milliseconds) / millisecondsIn30Minutes;
+//  Serial.print("logisticBrightOfMilliseconds stepNumber =               "); Serial.print(stepNumber);
+//  Serial.print(", totalDimmerSteps="); Serial.print(totalDimmerSteps);
+//  Serial.print(", millisecondsIn30Minutes="); Serial.println(millisecondsIn30Minutes);
   logisticBrightOfStep(stepNumber);
 }

@@ -472,22 +481,22 @@

 // wait is in milliseconds
 // last is the last time this function returned true
-bool isTimeNow(unsigned long & last, unsigned wait) {
-  unsigned long time = millis();
-  if (static_cast<unsigned long>(time - last) > wait) {
+bool isTimeNow(uint32_t & last, unsigned wait) {
+  uint32_t time = millis();
+  if (static_cast<uint32_t>(time - last) > wait) {
     last = time;
     return true;
   }
   return false;
 }

-const unsigned long updateInterval = 1000; // every second
-unsigned long lastUpdate = millis();
+const uint32_t updateInterval = 1000; // every second
+uint32_t lastUpdate = millis();
 void updateCurrentTime(bool force = false) {
   if (force || isTimeNow(lastUpdate, updateInterval)) {
     current_clock_time = synchronized_clock_time;
-    const unsigned long seconds_delta = static_cast<unsigned long>(millis() - synchronized_clock_millis) / 1000;
-    const unsigned long minutes_delta = seconds_delta / 60;
+    const uint32_t seconds_delta = static_cast<uint32_t>(millis() - synchronized_clock_millis) / 1000;
+    const uint32_t minutes_delta = seconds_delta / 60;
     current_clock_time.minute += minutes_delta;
     current_clock_time.second += (seconds_delta - minutes_delta * 60);
     current_clock_time.fixTime();
@@ -495,8 +504,8 @@
   }
 }

-const unsigned long clockUpdateInterval = 24 * 60 * 60 * 1000; // every 24 hours
-unsigned long lastClockUpdate = millis();
+const uint32_t clockUpdateInterval = 24 * 60 * 60 * 1000; // every 24 hours
+uint32_t lastClockUpdate = millis();
 void updateClockTime(bool force = false) {
   if (force || isTimeNow(lastClockUpdate, clockUpdateInterval)) {
     synchronized_clock_time = ClockTime(RTC.now());
@@ -507,8 +516,7 @@

 void updateStartTime() {
   startTime = alarmTime;
-  startTime.minute -= 30;
-  startTime.fixTime();
+  startTime -= thirtyMinutes;
 }

@@ -544,7 +552,7 @@
 }

 void setup() {
-  //Serial.begin(9600);
+//  Serial.begin(9600);
   //Serial.println("Starting setup...");
   Wire.begin();
   RTC.begin();
@@ -629,9 +637,9 @@
   digitalWrite(soundBPin, (status ? LOW : HIGH));
 }

-unsigned long alarmStartMillis = 0;
+uint32_t alarmStartMillis = 0;
 const unsigned lightUpdateInterval = 50;
-unsigned long lastLightUpdate = millis();
+uint32_t lastLightUpdate = millis();
 void updateLight() {
   if (!isTimeNow(lastLightUpdate, lightUpdateInterval)) {
     return;
@@ -653,17 +661,17 @@
   if (!alarmActive)
   {
     setColorForSunRise();
-    alarmStartMillis = static_cast<unsigned long>(millis() - 1000 * seconds);
+    alarmStartMillis = static_cast<uint32_t>(millis() - 1000 * seconds);
     alarmActive = true;
   }
-  if (seconds >= thirtyminutes) {
+  if (seconds >= thirtyMinutesInSeconds) {
     linearBrightOfStep(totalDimmerSteps);
+    soundAlarmA(true);
     return;
   }
-  if (seconds == thirtyminutes) {
-    soundAlarmA(true);
-  }
-  logisticBrightOfMilliseconds(static_cast<unsigned long>(millis() - alarmStartMillis));
+  uint32_t debug_millis = static_cast<uint32_t>(millis() - alarmStartMillis);
+//  Serial.print("updateLight: debug_millis =               "); Serial.println(debug_millis);
+  logisticBrightOfMilliseconds(debug_millis);
 }

@@ -686,13 +694,13 @@
   delay(1000);
   updateTimeDisplay(t, true, alarmMasterSwitchEnabled);
   waitForButtonDepress(TimeButton, LOW);
-  unsigned long modeActive = millis();
+  uint32_t modeActive = millis();
   bool normalExit = true;
   while (debounceDigitalRead(TimeButton) == HIGH) {
     int16_t encoderDelta = encoder->getValue();
     updateTime(t, encoderDelta);
     modeActive = millis();
-    if (static_cast<unsigned long>(millis() - modeActive) > modeInactivePeriod) {
+    if (static_cast<uint32_t>(millis() - modeActive) > modeInactivePeriod) {
       normalExit = false;
       break;
     }
@@ -725,14 +733,14 @@
   delay(1000);
   updateTimeDisplay(alarmTime, true, alarmMasterSwitchEnabled);
   waitForButtonDepress(AlarmButton, LOW);
-  unsigned long modeActive = millis();
+  uint32_t modeActive = millis();
   bool normalExit = true;
   while (debounceDigitalRead(AlarmButton) == HIGH) {
     int16_t encoderDelta = encoder->getValue();
     //Serial.print("encoder Delta = "); Serial.println(encoderDelta);
     updateAlarm(encoderDelta);
     modeActive = millis();
-    if (static_cast<unsigned long>(millis() - modeActive) > modeInactivePeriod) {
+    if (static_cast<uint32_t>(millis() - modeActive) > modeInactivePeriod) {
       normalExit = false;
       break;
     }
@@ -750,7 +758,7 @@
   alarmEnabled = true;
 }

-unsigned long millisAtStartOfSunSet = 0;
+uint32_t millisAtStartOfSunSet = 0;
 bool sunSetActive = false;
 void setSunSet() {
   matrix.print(defaultSunSetDelta);
@@ -761,7 +769,7 @@
   sunSetActive = true;
   turnLightOn();
   waitForButtonDepress(OffButton, HIGH);
-  unsigned long modeActive = millis();
+  uint32_t modeActive = millis();
   bool normalExit = true;
   while (debounceDigitalRead(OffButton) == LOW) {
     int16_t encoderDelta = encoder->getValue();
@@ -773,7 +781,7 @@
       if (defaultSunSetDelta == 0) matrix.writeDigitNum(4, 0);
       matrix.writeDisplay();
     }
-    if (static_cast<unsigned long>(millis() - modeActive) > modeInactivePeriod) {
+    if (static_cast<uint32_t>(millis() - modeActive) > modeInactivePeriod) {
       normalExit = false;
       break;
     }
@@ -790,7 +798,7 @@
 }

-unsigned long lastSunSetUpdate = millis();
+uint32_t lastSunSetUpdate = millis();
 unsigned sunSetUpdateInterval = 5;
 int lastSunSetLightLevel = 0;
 void updateSunSet() {
@@ -800,9 +808,9 @@
   if (!isTimeNow(lastSunSetUpdate, sunSetUpdateInterval)) {
     return;
   }
-  unsigned long currentMillis = millis();
-  unsigned long delta = static_cast<unsigned long>(currentMillis - millisAtStartOfSunSet);
-  unsigned long finalMillis = defaultSunSetDelta;
+  uint32_t currentMillis = millis();
+  uint32_t delta = static_cast<uint32_t>(currentMillis - millisAtStartOfSunSet);
+  uint32_t finalMillis = defaultSunSetDelta;
   finalMillis *= 60;
   finalMillis *= 1000;
   if (delta > finalMillis) {
@@ -810,14 +818,14 @@
     linearBrightOfStep(0);
   }
   else {
-    unsigned long temp = totalDimmerSteps - totalDimmerSteps * delta / finalMillis;
+    uint32_t temp = totalDimmerSteps - totalDimmerSteps * delta / finalMillis;
     logisticBrightOfStep(temp);
   }
 }

 void updateBrightness()
 {
-  unsigned long modeActive = millis();
+  uint32_t modeActive = millis();
   bool normalExit = true;
   waitForButtonDepress(rotaryButton, LOW);
   while (debounceDigitalRead(rotaryButton) == HIGH) {
@@ -826,8 +834,9 @@
       int delta = (encoderDelta > 0 ? 1 : -1);
       matrixBrightness = max(min(15, matrixBrightness + delta), 0);
       matrix.setBrightness(matrixBrightness); // 0-15
-    }
-    if (static_cast<unsigned long>(millis() - modeActive) > modeInactivePeriod) {
+      modeActive = millis();
+    }
+    if (static_cast<uint32_t>(millis() - modeActive) > modeInactivePeriod) {
       normalExit = false;
       break;
     }


began to implement stopwatch

began to implement stopwatch

--- TrinketWatch.ino
+++ TrinketWatch.ino
@@ -54,6 +54,12 @@
 #error("Height incorrect, please fix Adafruit_SSD1306.h!");
 #endif

+int hours = 9;
+int minutes = 50;
+
+unsigned long uptime = millis();
+unsigned long stopWatchStart = -1;
+
 void setup() {
  Serial.begin(9600);

@@ -66,10 +72,9 @@
   display.setTextSize(4);
   display.setTextColor(WHITE);
 }
-int hours = 9;
-int minutes = 50;

 void loop() {
+  uptime = millis();
   demo();
 }

@@ -96,3 +101,10 @@

   minutes++;
 }
+
+void stopwatch() {
+  display.clearDisplay();
+  if (stopWatchStart != -1) {
+    unsigned long stopTime = uptime - stopWatchStart;
+  }
+}


MCP23017-testing: Fixed comment

MCP23017-testing: Fixed comment

--- testing-output-23017/testing-output-23017.ino
+++ testing-output-23017/testing-output-23017.ino
@@ -50,6 +50,6 @@
 void setOutput(int value) {
   Wire.beginTransmission(ADDRESS);
   Wire.write(GPIOA);        // select GPIOA register
-  Wire.write(value);  // Set all output HIGH in bank A
-  Wire.endTransmission();    // stop transmitting
+  Wire.write(value);        // Set output bits in bank A
+  Wire.endTransmission();   // stop transmitting
 }


Copyright removed

Copyright removed

--- code.ino
+++ code.ino
@@ -1,6 +1,5 @@
 /*
- * BadUSB - HID Reverse TCP attack for Win, Mac and Unix OS - Last update 25/10/2018 - Copyright (c) by grcasanova
- *
+ * BadUSB - HID Reverse TCP attack for Win, Mac and Unix OS - Last update 25/10/2018
  * change IP and PORT constants to match the attacking machine details
  *
 */


Add more documentation

Add more documentation

--- firmware/imu/imu.ino
+++ firmware/imu/imu.ino
@@ -27,6 +27,11 @@
  * where crc() appends a 16-bit crc to the end of the message
  * and cobs() encodes the data using
  * "Consistent Overhead Byte Stuffing" (Cheshire & Baker 1997)
+ *
+ * Output data:
+ * accelerometer: divide by 32,768 to get to units (2gs)
+ * gyro: divide by 32,768 to get to units (250deg/s)
+ * magnetometer: divide by 1024 to get to units (gauss)
  *
  * Commands:
  * mode=idle             Stops reading data and sending output


error handling bug fixes

error handling bug fixes


remove noise in pulse counting

remove noise in pulse counting

--- _06-power_meter/_06-power_meter.ino
+++ _06-power_meter/_06-power_meter.ino
@@ -314,47 +314,45 @@
         average = ave.mean();
       }

-      //if ( revMills > 600 ) {
-      if ( irStatus == oldirStatus ) {
-        revValue = (float(( 3600  * 1000 ) / ( 600 * float(revMills) ) ) * 1000);
-      }
-      //}
+      if ( revMills > 600 ) {
+      revValue = (float(( 3600  * 1000 ) / ( 600 * float(revMills) ) ) * 1000);
+      }

       if ( oldrevValue == 0 ) {
-        oldrevValue = revValue;
-      }
-
-      if ( oldrevMills == 0 ) {
-        oldrevMills = revMills;
-      }
-
-      payload = "{\"VIrms\":";
-      payload += average;
-      payload += ",\"revValue\":";
-      payload += revValue;
-      payload += ",\"revMills\":";
-      payload += revMills;
-      payload += ",\"powerAvg\":";
-      payload += (( average + revValue ) / 2) ;
-      payload += ",\"Stddev\":";
-      payload += ave.stddev();
-      payload += ",\"calcIrmsmillis\":";
-      payload += calcIrmsmillis;
-      payload += ",\"revCounts\":";
-      payload += revCounts;
-      payload += ",\"FreeHeap\":";
-      payload += ESP.getFreeHeap();
-      payload += ",\"RSSI\":";
-      payload += WiFi.RSSI();
-      payload += ",\"millis\":";
-      payload += (millis() - timemillis);
-      payload += "}";
-
-      if ( doorStatus != olddoorStatus ) {
-
-        doorpayload = "{\"DOOR\":";
-
-        if ( doorStatus == 0 ) {
+      oldrevValue = revValue;
+    }
+
+    if ( oldrevMills == 0 ) {
+      oldrevMills = revMills;
+    }
+
+    payload = "{\"VIrms\":";
+              payload += average;
+              payload += ",\"revValue\":";
+              payload += revValue;
+              payload += ",\"revMills\":";
+              payload += revMills;
+              payload += ",\"powerAvg\":";
+              payload += (( average + revValue ) / 2) ;
+              payload += ",\"Stddev\":";
+              payload += ave.stddev();
+              payload += ",\"calcIrmsmillis\":";
+              payload += calcIrmsmillis;
+              payload += ",\"revCounts\":";
+              payload += revCounts;
+              payload += ",\"FreeHeap\":";
+              payload += ESP.getFreeHeap();
+              payload += ",\"RSSI\":";
+              payload += WiFi.RSSI();
+              payload += ",\"millis\":";
+              payload += (millis() - timemillis);
+              payload += "}";
+
+    if ( doorStatus != olddoorStatus ) {
+
+      doorpayload = "{\"DOOR\":";
+
+      if ( doorStatus == 0 ) {
           doorpayload += "\"CLOSED\"";
         }
         else {
@@ -367,12 +365,12 @@
       }

       if (((millis() - sentMills) > REPORT_INTERVAL ) && ( irStatus == oldirStatus )) {
-        sendmqttMsg(topic, payload);
+      sendmqttMsg(topic, payload);
         sentMills = millis();
       }

       if ( irStatus != oldirStatus ) {
-        sendmqttMsg(topic, payload);
+      sendmqttMsg(topic, payload);
         sentMills = millis();
         oldirStatus = irStatus ;
         oldrevValue = revValue ;
@@ -429,12 +427,9 @@

   if (( millis() - startMills ) < 600 ) {
     return;
-    /*
-      }
-
-      if (( millis() - startMills ) < ( revMills / 3 )) {
-       return;
-    */
+  }
+  if (( millis() - startMills ) < ( revMills / 4 )) {
+    return;
   } else {
     revMills   = (millis() - startMills)  ;
     startMills = millis();


Added header comments

Added header comments


Fix range_threshold interrupt.

Fix range_threshold interrupt.

--- arduino/sonar_driver/sonar_driver.ino
+++ arduino/sonar_driver/sonar_driver.ino
@@ -1,9 +1,9 @@
 #include <Wire.h>
 #include <NewPing.h>

+#define RANGE_THRESHOLD 10
 #define MAX_DISTANCE 250
 #define INVALID_DATA -1
-#define RANGE_THRESHOLD 10
 #define LED13 13

 #define SONAR_NUM 4
@@ -58,7 +58,7 @@
   for (int i = 0; i < SONAR_NUM; i++) {
     if (isEnabled()) {
       ranges[i] = ping(i);
-      if (INVALID_DATA < ranges[i] <= RANGE_THRESHOLD) {
+      if (INVALID_DATA < ranges[i] && ranges[i] <= RANGE_THRESHOLD) {
         digitalWrite(IRQ[i], HIGH);
       } else {
         digitalWrite(IRQ[i], LOW);


Light sensor works now too

Light sensor works now too

--- basement_monitor/basement_monitor.ino
+++ basement_monitor/basement_monitor.ino
@@ -15,9 +15,10 @@
 DHTesp dht;
 WiFiClient espClient;
 PubSubClient mqttClient(espClient);
+char buffer[81];
 double temperature_f = 0;
 double humidity = 0;
-char buffer[81];
+int lightLevel = 0;

 void mqttConnect()
 {
@@ -82,7 +83,6 @@

 void setupDHTTask()
 {
-    // Read dht every 1000[ms] and repeat forever
     Tasks.interval(10000, [] {
         // Reading temperature for humidity takes about 250 milliseconds!
         // Sensor readings may also be up to 2 seconds 'old' (it's a very slow sensor)
@@ -111,6 +111,21 @@
     });
 }

+
+void setupLDRTask()
+{
+    Tasks.interval(15000, [] {
+        lightLevel = analogRead(LDR_PIN);
+        sprintf(buffer, "%d", lightLevel);
+        Serial.print("Light ");
+        Serial.println(buffer);
+        mqttClient.publish("sensors/basement/light", buffer);
+        updateDisplay();
+
+    });
+}
+
+
 void setupMQTT()
 {
     mqttClient.setServer(MQTT_HOST, MQTT_PORT);
@@ -125,9 +140,9 @@
     sprintf(buffer, "IP %s", WiFi.localIP().toString().c_str());
     Heltec.display->drawString(0, CH*1, MQTT_CLIENT_NAME);
     Heltec.display->drawString(0, 0, buffer);
-    sprintf(buffer, "T %2.2f  H %2.2f", temperature_f, humidity);
+    sprintf(buffer, "T %2.2f    H %2.2f", temperature_f, humidity);
     Heltec.display->drawString(0, CH*3, buffer);
-    sprintf(buffer, "MS %ld", millis());
+    sprintf(buffer, "L %d", lightLevel);
     Heltec.display->drawString(0, CH*4, buffer);
     Heltec.display->display();
 }
@@ -148,6 +163,7 @@
     setupWiFi();
     setupMQTT();
     setupDHTTask();
+    setupLDRTask();
 }

 void loop()


oled-dispay-sketch.ino: Fix tabs

oled-dispay-sketch.ino: Fix tabs

Signed-off-by: Leon Anavi <be92910ae7bb6f58bb9b7c6f845bc30640119592@anavi.org>

--- peripherals/oled-dispay-sketch/oled-dispay-sketch.ino
+++ peripherals/oled-dispay-sketch/oled-dispay-sketch.ino
@@ -11,40 +11,40 @@

 void drawDisplay(const char *line1, const char *line2 = "", const char *line3 = "")
 {
-    // Write on OLED display
-    // Clear the internal memory
-    u8g2.clearBuffer();
-    // Set appropriate font
-    u8g2.setFont(u8g2_font_ncenR14_tr);
-    u8g2.drawStr(0,14, line1);
-    u8g2.drawStr(0,39, line2);
-    u8g2.drawStr(0,64, line3);
-    // Transfer internal memory to the display
-    u8g2.sendBuffer();
+  // Write on OLED display
+  // Clear the internal memory
+  u8g2.clearBuffer();
+  // Set appropriate font
+  u8g2.setFont(u8g2_font_ncenR14_tr);
+  u8g2.drawStr(0,14, line1);
+  u8g2.drawStr(0,39, line2);
+  u8g2.drawStr(0,64, line3);
+  // Transfer internal memory to the display
+  u8g2.sendBuffer();
 }

 void setup()
 {
-    // put your setup code here, to run once:
-    Serial.begin(115200);
-    Serial.println();
-    u8g2.begin();
+  // put your setup code here, to run once:
+  Serial.begin(115200);
+  Serial.println();
+  u8g2.begin();

-    delay(10);
+  delay(10);

-    //Button
-    pinMode(pinButton, INPUT);
+  //Button
+  pinMode(pinButton, INPUT);

-    Serial.println("Testing the OLED I2C display...");
-    drawDisplay("TEST", "Hello", "World");
+  Serial.println("Testing the OLED I2C display...");
+  drawDisplay("TEST", "Hello", "World");
 }

 void loop()
 {
-   if (false == digitalRead(pinButton))
-   {
-       Serial.println("Rebooting...");
-       // Restart the board
-       ESP.restart();
-   }
+  if (false == digitalRead(pinButton))
+  {
+    Serial.println("Rebooting...");
+    // Restart the board
+    ESP.restart();
+  }
 }


Fixed: lsb-hsb confusion (saved backwards but also returned it backwards) Fixed: bug introduced by operator precendence Added: debug output

--- pic_programmer_prototype/pic_programmer_prototype.ino
+++ pic_programmer_prototype/pic_programmer_prototype.ino
@@ -8,9 +8,12 @@
 #define PROGRAMMING_MODE_INPUT_LINE_SET_TIME 1       // Tset0
 #define PROGRAMMING_MODE_HOLD_ACTIVATION_TIME 10     // Thld0
 #define PROGRAMMING_MODE_EXIT_DELAY_TIME 2           // Texit
+#define PROGRAMMING_MODE_PROGRAMMING_TIME 10000      // Tprog
+#define PROGRAMMING_MODE_PROGRAMMING_END_TIME 1000   // Tdis

 #define PROGRAMMING_MODE_CLOCK_CYCLE_DELAY 1         // Tset1, Thld1
-#define PROGRAMMING_MODE_COMMAND_DELAY 2             // max(Tdly1, Tdly2, Tdly3)
+#define PROGRAMMING_MODE_COMMAND_DELAY 5             // max(Tdly1, Tdly2, Tdly3)
+

 const int POWER_PIN = 40;
 const int PROG_POWER_PIN = 41;
@@ -47,6 +50,7 @@
       for (int i = 0; i < 6; i++) {
         digitalWrite(PROGRAMMING_CLOCK_PIN, HIGH);
         digitalWrite(PROGRAMMING_DATA_PIN, (cmd & 1) == 1 ? HIGH : LOW);
+        //Serial.print("Writing: "); Serial.println((cmd & 1) == 1 ? HIGH : LOW);

         delayMicroseconds(PROGRAMMING_MODE_CLOCK_CYCLE_DELAY);
         digitalWrite(PROGRAMMING_CLOCK_PIN, LOW);
@@ -148,7 +152,7 @@
         for (int i = 0; i < 16; i++) {
           digitalWrite(PROGRAMMING_CLOCK_PIN, HIGH);
           delayMicroseconds(PROGRAMMING_MODE_COMMAND_DELAY);
-          result = (result << 1) | ((bool) digitalRead(PROGRAMMING_DATA_PIN)) ? 1 : 0;
+          result = (result >> 1) & 0x7FFF | (((bool) digitalRead(PROGRAMMING_DATA_PIN)) ? 0x8000 : 0);
           digitalWrite(PROGRAMMING_CLOCK_PIN, LOW);
           delayMicroseconds(PROGRAMMING_MODE_COMMAND_DELAY);
         }
@@ -158,6 +162,28 @@
         return result;
       }
       return -1;
+    }
+
+    bool writeWord(int w) {
+      w = (w & 0x3F) << 1;
+
+      if (_inProgrammingMode) {
+        writeCommand(0x02);
+        delayMicroseconds(PROGRAMMING_MODE_COMMAND_DELAY);
+
+        for (int i = 0; i < 16; i++) {
+          digitalWrite(PROGRAMMING_CLOCK_PIN, HIGH);
+          digitalWrite(PROGRAMMING_DATA_PIN, (w & 1) == 1 ? HIGH : LOW);
+          Serial.print("Writing: "); Serial.println((w & 1) == 1 ? HIGH : LOW);
+          delayMicroseconds(PROGRAMMING_MODE_CLOCK_CYCLE_DELAY);
+          digitalWrite(PROGRAMMING_CLOCK_PIN, LOW);
+          delayMicroseconds(PROGRAMMING_MODE_CLOCK_CYCLE_DELAY);
+        }
+
+        digitalWrite(PROGRAMMING_DATA_PIN, LOW);
+        return true;
+      }
+      return false;
     }

     bool incAddress() {
@@ -169,6 +195,17 @@
       }
       return false;
     }
+
+    bool burnProgram() {
+      if (_inProgrammingMode) {
+        writeCommand(0x08);
+        delayMicroseconds(PROGRAMMING_MODE_PROGRAMMING_TIME);
+        writeCommand(0x0E);
+        delayMicroseconds(PROGRAMMING_MODE_PROGRAMMING_END_TIME);
+        return true;
+      }
+      return false;
+    }
 };

 PICProgrammer* programmer;
@@ -282,8 +319,7 @@
           Serial.print(String(programmer->getLocation(), HEX));
           Serial.print(": ");
           for (int i = 0; i < 16; i++) {
-            Serial.print((w & 1) == 1 ? "1 " : "0 ");
-            w >>= 1;
+            Serial.print(((w >> (15 - i)) & 1) == 1 ? "1 " : "0 ");
           }
           Serial.println();

@@ -300,16 +336,47 @@
     }
 };

-class IncAddressControl : public Command {
-  public:
-    virtual bool match(const String& name) const {
-      return name.startsWith("inc");
+class WriteTextWordControl : public Command {
+  public:
+    virtual bool match(const String& name) const {
+      return name.startsWith("text_write");
     }

     virtual void execute(const String& commandString) {
       if (!programmer->inProgrammingMode()) {
         Serial.println("ERROR: Programmer not in programming mode");
       } else {
+        StringSplitter splitter(commandString, ' ', 2);
+        if (splitter.getItemCount() < 2) {
+          Serial.println("ERROR: Expected word to write as first argument");
+        }
+        String parameter = splitter.getItemAtIndex(1);
+        parameter.toLowerCase();
+        int data = hexToInt(parameter);
+
+        if (data < 0 || data > 0x3F) {
+          Serial.println("ERROR: Word must be >= 0 and <= 3F");
+        } else {
+          programmer->writeWord(data);
+        }
+      }
+    }
+
+    virtual void printHelpString() const {
+      Serial.println("  text_write hex_value  writes a word to the current memory location");
+    }
+};
+
+class IncAddressControl : public Command {
+  public:
+    virtual bool match(const String& name) const {
+      return name.startsWith("inc");
+    }
+
+    virtual void execute(const String& commandString) {
+      if (!programmer->inProgrammingMode()) {
+        Serial.println("ERROR: Programmer not in programming mode");
+      } else {
         programmer->incAddress();
       }
     }
@@ -318,6 +385,26 @@
       Serial.println("  inc                   increment write/read address");
     }
 };
+
+class BurnProgramControl : public Command {
+  public:
+    virtual bool match(const String& name) const {
+      return name.startsWith("burn_prog");
+    }
+
+    virtual void execute(const String& commandString) {
+      if (!programmer->inProgrammingMode()) {
+        Serial.println("ERROR: Programmer not in programming mode");
+      } else {
+        programmer->burnProgram();
+      }
+    }
+
+    virtual void printHelpString() const {
+      Serial.println("  burn_prog             burn the program into program memory");
+    }
+};
+

 void setup() {
   memset(&commands, COMMANDS_SIZE * sizeof(commands[0]), 0);
@@ -326,6 +413,8 @@
   commands[2] = new ProgrammingModeControl();
   commands[3] = new IncAddressControl();
   commands[4] = new ReadTextWordControl();
+  commands[5] = new WriteTextWordControl();
+  commands[6] = new BurnProgramControl();

   Serial.begin(57600);
   Serial.setTimeout(10);


minor fixes

minor fixes

EPOS nos enabling

--- send/send.ino
+++ send/send.ino
@@ -86,6 +86,7 @@
     Serial.println(" Init CAN BUS Shield again");
     delay(100);
   }
+  State = Startup;
   Serial.println("CAN BUS Shield init ok!");
 }

@@ -107,9 +108,7 @@
   Serial.println("Max Following Error set as 5000rpm/s");
   delay(10);
   CAN.sendMsgBuf(0x601, 0, 8, set_max_profile_velocity);
-  Serial.println("Max Profile Velocity set as 2000rpm");
-  delay(10);
-
+  Serial.println("Max Profile Velocity set as 2000rpm");
   delay(10);
   State = Operational;
 }
@@ -123,6 +122,7 @@
   unsigned char buf[8];

     Serial.println("Enviei a mensagem");
+    // Serial.println(setpoint_position,HEX);
     // clear the string:
     CAN.sendMsgBuf(0x601, 0, 8, setpoint_position);
     delay(10);
@@ -175,12 +175,10 @@

 void loop()
 {
-  State = Startup;
-
   switch (State)
   {
     case Startup:
-      do doStartup();
+      doStartup();
       break;
     case Operational:
       dataRead();
@@ -194,5 +192,3 @@
 *********************************************************************************************************/

-
-


implement stepper control commands in firmware

--- antenna_tracker/antenna_tracker.ino
+++ antenna_tracker/antenna_tracker.ino
@@ -41,17 +41,26 @@
 enum {
 	TC_ACK = 0x00,

-	CT_SET_CONFIG = 0x01,
-	CT_SET_POSITION = 0x02,
-
-	CT_GET_CONFIG = 0x03,
-	TC_CONFIG = 0x30
+	CT_SET_POSITION 	= 0x01,
+	CT_SET_MAX_SPEED 	= 0x02,
+	CT_SET_ACCEL 		= 0x03,
+	CT_SET_MOTOR_STATE 	= 0x04,
+
+	CT_GET_MAX_SPEED 	= 0x20,
+	CT_GET_ACCEL 		= 0x30,
+	CT_GET_MOTOR_STATE 	= 0x40
+};
+
+enum {
+	MOTOR_STATE_OFF = 0,
+	MOTOR_STATE_ON = 1
 };

 enum {
 	ACK_STATUS_SUCCESS = 0,
 	ACK_STATUS_FAIL
 };
+
 typedef struct {
 	uint8_t type; // TC_ACK
 	uint8_t status;
@@ -61,31 +70,27 @@
 typedef struct {
 	uint8_t type; // CT_SET_POSITION
 	uint8_t motor; // 0 - elevation, 1 - azimuth
+	bool is_absolute;
 	int16_t degrees;
 } set_position_packet_t __attribute__((packed));

 typedef struct {
-	uint8_t type; // CT_SET_CONFIG
-	uint8_t motor; // 0 - elevation, 1 - azimuth
-	bool	motor_state; // 0 off, 1 on
-	uint16_t max_speed;
-	uint16_t acceleration;
-	int16_t current_steps;
-} set_config_packet_t __attribute__((packed));
-
-typedef struct {
-	uint8_t type; // CT_GET_CONFIG
-	uint8_t motor; // 0 - elevation, 1 - azimuth
-} get_config_packet_t __attribute__((packed));
-
-typedef struct {
-	uint8_t type; // TC_CONFIG
-	uint8_t motor; // 0 - elevation, 1 - azimuth
-	uint16_t max_speed;
-	uint16_t acceleration;
-	int16_t current_steps;
-	int16_t current_degrees;
-} config_packet_t __attribute__((packed));
+	uint8_t type; // CT_SET_MAX_SPEED
+	uint8_t motor; // 0 - elevation, 1 - azimuth
+	uint16_t maxspeed;
+} set_max_speed_packet_t __attribute__((packed));
+
+typedef struct {
+	uint8_t type; // CT_SET_MOTOR_STATE
+	uint8_t motor; // 0 - elevation, 1 - azimuth
+	bool accel;
+} set_accel_packet_t __attribute__((packed));
+
+typedef struct {
+	uint8_t type; // CT_SET_ACCEL
+	uint8_t motor; // 0 - elevation, 1 - azimuth
+	bool state; // 0 - off, 1 - on
+} set_motor_state_packet_t __attribute__((packed));

 ack_packet_t ack_packet;

@@ -160,17 +165,76 @@
 		if (m_rx_len > 0) {
 			uint8_t type = ((uint8_t*)m_rx_buffer)[0];

-			if (CT_SET_CONFIG == type) {
-
-			}
-			else if (CT_SET_POSITION == type) {
-				set_position_packet_t* set_position_p = (set_position_packet_t*)m_rx_buffer;
-				if (set_position_p->motor == ELEVATION_STEPPER) {
-					ElevationStepper.moveTo(degrees_to_elevation_steps(set_position_p->degrees));
-					send_ack(ACK_STATUS_SUCCESS, __LINE__);
-				}
-				else if (set_position_p->motor == AZIMUTH_STEPPER) {
-					AzimuthStepper.moveTo(degrees_to_azimuth_steps(set_position_p->degrees));
+			if (CT_SET_POSITION == type) {
+				set_position_packet_t* position_p = (set_position_packet_t*)m_rx_buffer;
+				if (position_p->motor == ELEVATION_STEPPER) {
+					if (position_p->is_absolute) {
+						ElevationStepper.moveTo(degrees_to_elevation_steps(position_p->degrees));
+					}
+					else {
+						ElevationStepper.move(degrees_to_elevation_steps(position_p->degrees));
+					}
+					send_ack(ACK_STATUS_SUCCESS, __LINE__);
+				}
+				else if (position_p->motor == AZIMUTH_STEPPER) {
+					if (position_p->is_absolute) {
+						AzimuthStepper.moveTo(degrees_to_azimuth_steps(position_p->degrees));
+					}
+					else {
+						AzimuthStepper.move(degrees_to_azimuth_steps(position_p->degrees));
+					}
+					send_ack(ACK_STATUS_SUCCESS, __LINE__);
+				}
+				else {
+					send_ack(ACK_STATUS_FAIL, __LINE__);
+				}
+			}
+			else if (CT_SET_MAX_SPEED == type) {
+				set_max_speed_packet_t* max_speed_p = (set_max_speed_packet_t*)m_rx_buffer;
+				if (max_speed_p->motor == ELEVATION_STEPPER) {
+					ElevationStepper.setMaxSpeed(max_speed_p->maxspeed);
+					send_ack(ACK_STATUS_SUCCESS, __LINE__);
+				}
+				else if (max_speed_p->motor == AZIMUTH_STEPPER) {
+					AzimuthStepper.setMaxSpeed(max_speed_p->maxspeed);
+					send_ack(ACK_STATUS_SUCCESS, __LINE__);
+				}
+				else {
+					send_ack(ACK_STATUS_FAIL, __LINE__);
+				}
+			}
+			else if (CT_SET_ACCEL == type) {
+				set_accel_packet_t* accel_p = (set_accel_packet_t*)m_rx_buffer;
+				if (accel_p->motor == ELEVATION_STEPPER) {
+					ElevationStepper.setAcceleration(accel_p->accel);
+					send_ack(ACK_STATUS_SUCCESS, __LINE__);
+				}
+				else if (accel_p->motor == AZIMUTH_STEPPER) {
+					AzimuthStepper.setAcceleration(accel_p->accel);
+					send_ack(ACK_STATUS_SUCCESS, __LINE__);
+				}
+				else {
+					send_ack(ACK_STATUS_FAIL, __LINE__);
+				}
+			}
+			else if (CT_SET_MOTOR_STATE == type) {
+				set_motor_state_packet_t* state_p = (set_motor_state_packet_t*)m_rx_buffer;
+				if (state_p->motor == ELEVATION_STEPPER) {
+					if (state_p->state == MOTOR_STATE_ON) {
+						digitalWrite(ELEVATION_STEPPER_ENABLE, LOW);
+					}
+					else {
+						digitalWrite(ELEVATION_STEPPER_ENABLE, HIGH);
+					}
+					send_ack(ACK_STATUS_SUCCESS, __LINE__);
+				}
+				else if (state_p->motor == AZIMUTH_STEPPER) {
+					if (state_p->state == MOTOR_STATE_ON) {
+						digitalWrite(AZIMUTH_STEPPER_ENABLE, LOW);
+					}
+					else {
+						digitalWrite(AZIMUTH_STEPPER_ENABLE, HIGH);
+					}
 					send_ack(ACK_STATUS_SUCCESS, __LINE__);
 				}
 				else {
@@ -183,8 +247,7 @@
 		}
 	}

-	//ElevationStepper.moveTo(degrees_to_steps(m_degrees));
+	//ElevationStepper.runSpeed(); // for const speed
 	ElevationStepper.run(); // for accel/deccel
-	//ElevationStepper.runSpeed(); // for const speed
 	AzimuthStepper.run();
 }


Add sensor test file

Add sensor test file