Removed old source code

Removed old source code

--- space/space.ino
+++ space/space.ino
@@ -1,897 +0,0 @@
-#include <avr/pgmspace.h>
-#include <EEPROM.h>
-
-#if !defined(__INT_MAX__) || (__INT_MAX__ > 0xFFFF)
- #define pgm_read_pointer(addr) ((void *)pgm_read_dword(addr))
-#else
- #define pgm_read_pointer(addr) ((void *)pgm_read_word(addr))
-#endif
-
-#define IR1 2
-#define IG1 3
-#define IB1 4
-#define IR2 5
-#define IG2 6
-#define IB2 7
-#define CLK 8  // MUST be on PORTB! (Use pin 11 on Mega)
-#define LAT 10
-#define OE  9
-#define A   A0
-#define B   A1
-#define C   A2
-#define D   A3
-
-#define BUTTON_SW 11
-#define BUTTON_NW A4
-#define BUTTON_SE 12
-#define BUTTON_NE 13
-
-#define LEFT BUTTON_SW
-#define RIGHT BUTTON_NW
-#define FIRE BUTTON_SE
-#define PAUSE BUTTON_NE
-
-#define WIDTH 64
-
-#define DATAPORT PORTD
-#define DATADIR  DDRD
-#define SCLKPORT PORTB
-
-#define GREEN 2
-#define CYAN  6
-#define WHITE 7
-
-volatile uint8_t
-    *latport, *oeport, *addraport, *addrbport, *addrcport, *addrdport,
-    *leftport, *rightport, *fireport, *pauseport;
-uint8_t
-    sclkpin, latpin, oepin, addrapin, addrbpin, addrcpin, addrdpin,
-    leftpin, rightpin, firepin, pausepin;
-
-int16_t hiscore;
-int16_t score;
-
-void setup()
-{
-  sclkpin   = digitalPinToBitMask(CLK);
-  latport   = portOutputRegister(digitalPinToPort(LAT));
-  latpin    = digitalPinToBitMask(LAT);
-  oeport    = portOutputRegister(digitalPinToPort(OE));
-  oepin     = digitalPinToBitMask(OE);
-  addraport = portOutputRegister(digitalPinToPort(A));
-  addrapin  = digitalPinToBitMask(A);
-  addrbport = portOutputRegister(digitalPinToPort(B));
-  addrbpin  = digitalPinToBitMask(B);
-  addrcport = portOutputRegister(digitalPinToPort(C));
-  addrcpin  = digitalPinToBitMask(C);
-  addrdport = portOutputRegister(digitalPinToPort(D));
-  addrdpin  = digitalPinToBitMask(D);
-
-  leftport = portInputRegister(digitalPinToPort(LEFT));
-  leftpin  = digitalPinToBitMask(LEFT);
-  rightport = portInputRegister(digitalPinToPort(RIGHT));
-  rightpin  = digitalPinToBitMask(RIGHT);
-  fireport = portInputRegister(digitalPinToPort(FIRE));
-  firepin  = digitalPinToBitMask(FIRE);
-  pauseport = portInputRegister(digitalPinToPort(PAUSE));
-  pausepin  = digitalPinToBitMask(PAUSE);
-
-  // put your setup code here, to run once:
-  pinMode(CLK , OUTPUT);
-  pinMode(LAT, OUTPUT);
-  pinMode(OE, OUTPUT);
-  pinMode(A, OUTPUT);
-  pinMode(B, OUTPUT);
-  pinMode(C, OUTPUT);
-  pinMode(D, OUTPUT);
-
-  pinMode(IR1, OUTPUT);
-  pinMode(IG1, OUTPUT);
-  pinMode(IB1, OUTPUT);
-  pinMode(IR2, OUTPUT);
-  pinMode(IG2, OUTPUT);
-  pinMode(IB2, OUTPUT);
-
-  pinMode(LEFT, INPUT);
-  pinMode(RIGHT, INPUT);
-
-  SCLKPORT   &= ~sclkpin;
-  *latport   &= ~latpin;
-  *oeport    &= ~oepin;
-  *addraport &= ~addrapin;
-  *addrbport &= ~addrbpin;
-  *addrcport &= ~addrcpin;
-  *addrdport &= ~addrdpin;
-
-  //DATADIR  = B11111100;
-  //DATAPORT = 0;
-
-  digitalWrite(IR1, HIGH);
-  digitalWrite(IG1, HIGH);
-  digitalWrite(IB1, HIGH);
-  digitalWrite(IR2, HIGH);
-  digitalWrite(IG2, HIGH);
-  digitalWrite(IB2, HIGH);
-
-  //EEPROM.write(0, 0);
-  //EEPROM.write(1, 0);
-  hiscore = (EEPROM.read(1) << 8) + EEPROM.read(0);
-}
-
-////////////////////////////////////////////////////////////
-// Sprite structure and functions
-////////////////////////////////////////////////////////////
-
-struct Sprite
-{
-  uint8_t width;
-  uint8_t height;
-  uint8_t lineSize;
-  const uint8_t *lines;
-};
-
-// need to have 'struct' here because of some compiler bug
-uint8_t sprite_width(const struct Sprite *s)
-{
-  return pgm_read_byte(&s->width);
-}
-
-uint8_t sprite_height(const Sprite *s)
-{
-  return pgm_read_byte(&s->height);
-}
-
-const uint8_t *sprite_line(const Sprite *s, int line)
-{
-  return pgm_read_byte(&s->lineSize) * line + (const uint8_t*)pgm_read_pointer(&s->lines);
-}
-
-void sprite_render_line(const Sprite *s, int x, int line, uint8_t *buf, uint8_t color)
-{
-  uint8_t mask = 0x80;
-  uint8_t width = sprite_width(s);
-  const uint8_t *ptr = sprite_line(s, line);
-  uint8_t spr = pgm_read_byte(ptr);
-  for (uint8_t dx = 0 ; dx < width ; ++dx)
-  {
-    int xx = x + dx;
-    if (xx >= 0 && xx < WIDTH)
-    {
-      if (spr & mask)
-        buf[xx] = color;
-    }
-    mask >>= 1;
-    if (!mask)
-    {
-      mask = 0x80;
-      ++ptr;
-      spr = pgm_read_byte(ptr);
-    }
-  }
-}
-
-void sprite_render(const Sprite *s, int x, int y, uint8_t *buf, int line, uint8_t color)
-{
-  uint8_t height = sprite_height(s);
-  if (line >= y && line < y + height)
-  {
-    sprite_render_line(s, x, line - y, buf, color);
-  }
-}
-
-////////////////////////////////////////////////////////////
-// Invaders data and functions
-////////////////////////////////////////////////////////////
-
-const uint8_t invader1lines[] PROGMEM = {
-    B00011000,
-    B00111100,
-    B01111110,
-    B11011011,
-    B01111110,
-    B10000001,
-    B01000010
-};
-
-const uint8_t invader2lines[] PROGMEM = {
-  B00100000, B10000000,
-  B00010001, B00000000,
-  B00111111, B10000000,
-  B01101110, B11000000,
-  B11111111, B11100000,
-  B10111111, B10100000,
-  B10100000, B10100000,
-  B00011011, B00000000
-};
-
-const uint8_t invader3lines[] PROGMEM = {
-  B00010000, B01000000,
-  B00001000, B10000000,
-  B00000101, B00000000,
-  B00111111, B11100000,
-  B01111111, B11110000,
-  B11100111, B00111000,
-  B01111111, B11110000,
-  B00111111, B11100000,
-  B00001010, B10000000,
-  B00010000, B01000000
-};
-
-const uint8_t invader4lines[] PROGMEM = {
-  B11100111,
-  B00111100,
-  B01111110,
-  B01011010,
-  B11111111,
-  B10111101,
-  B00111100,
-  B01111110,
-};
-
-#define INVADER_TYPES 4
-const Sprite invaders[INVADER_TYPES] PROGMEM = {
-  {8, 8, 1, invader1lines}, {11, 8, 2, invader2lines},
-  {13, 10, 2, invader3lines}, {8, 8, 1, invader4lines}
-};
-
-uint8_t invader_width(int type)
-{
-  return sprite_width(&invaders[type - 1]);
-}
-
-uint8_t invader_height(int type)
-{
-  return sprite_height(&invaders[type - 1]);
-}
-
-const Sprite *invader_sprite(int type)
-{
-  return &invaders[type - 1];
-}
-
-////////////////////////////////////////////////////////////
-// Cannon data
-////////////////////////////////////////////////////////////
-
-const uint8_t cannonLines[] PROGMEM = {
-  B00000010, B00000000,
-  B00000111, B00000000,
-  B00000111, B00000000,
-  B01111111, B11110000,
-  B11111111, B11111000,
-  B11111111, B11111000,
-  B11111111, B11111000,
-  B11111111, B11111000
-};
-
-const Sprite cannon PROGMEM = {
-  13, 8, 2, cannonLines
-};
-
-////////////////////////////////////////////////////////////
-// Game over data
-////////////////////////////////////////////////////////////
-
-#define GAMEOVER_X 16
-#define GAMEOVER_Y 24
-
-const uint8_t gameOverLines[] PROGMEM = {
-  B00111110, B00111000, B11000110, B11111110,
-  B01100000, B01101100, B11101110, B11000000,
-  B11000000, B11000110, B11111110, B11000000,
-  B11001110, B11000110, B11111110, B11111100,
-  B11000110, B11111110, B11010110, B11000000,
-  B01100110, B11000110, B11000110, B11000000,
-  B00111110, B11000110, B11000110, B11111110,
-  B00000000, B00000000, B00000000, B00000000,
-  B01111100, B11000110, B11111110, B11111100,
-  B11000110, B11000110, B11000000, B11000110,
-  B11000110, B11000110, B11000000, B11000110,
-  B11000110, B11000110, B11111100, B11001110,
-  B11000110, B01101100, B11000000, B11111000,
-  B11000110, B00111000, B11000000, B11011100,
-  B01111100, B00010000, B11111110, B11001110
-};
-
-const Sprite gameOver PROGMEM = {
-  31, 15, 4, gameOverLines
-};
-
-////////////////////////////////////////////////////////////
-// Lives data
-////////////////////////////////////////////////////////////
-
-#define LIFE_X 1
-#define LIFE_Y 2
-const uint8_t lifeLines[] PROGMEM = {
-  B01000000,
-  B11100000,
-  B11100000
-};
-
-const Sprite life PROGMEM = {
-  3, 3, 1, lifeLines
-};
-
-////////////////////////////////////////////////////////////
-// Hiscore data
-////////////////////////////////////////////////////////////
-
-#define HISCORE_LABEL_X 40
-#define HISCORE_LABEL_Y 1
-const uint8_t hiLines[] PROGMEM = {
-  B10101110,
-  B10100100,
-  B11100100,
-  B10100100,
-  B10101110
-};
-
-const Sprite hiLabel PROGMEM = {
-  8, 5, 1, hiLines
-};
-
-////////////////////////////////////////////////////////////
-// Wave data
-////////////////////////////////////////////////////////////
-
-const uint8_t waveLines[] PROGMEM = {
-  B10100100, B10101110,
-  B10101010, B10101000,
-  B11101110, B10101110,
-  B11101010, B10101000,
-  B10101010, B01001110
-};
-
-#define WAVE_X 14
-#define WAVE_Y 1
-const Sprite waveSprite PROGMEM = {
-  15, 5, 2, waveLines
-};
-
-////////////////////////////////////////////////////////////
-// Logo data
-////////////////////////////////////////////////////////////
-
-const uint8_t logoLines[] PROGMEM = {
-  B11111011, B11101111, B10100010, B11111011, B11101111, B10111110, B11111000,
-  B10001000, B00001000, B00100010, B10000010, B00100000, B00100000, B00000000,
-  B11111011, B11101000, B00111100, B11111010, B00101111, B10100000, B11111000,
-  B10001010, B00101000, B00100010, B00001010, B00101000, B10100000, B00000000,
-  B11111011, B11101111, B10100010, B11111011, B11101111, B10111110, B11111000,
-  B00000000, B00000000, B00000000, B00000010, B00000000, B00000000, B00000000,
-  B00000000, B00000000, B00000000, B00000010, B00000000, B00000000, B00000000,
-  B00000010, B11111010, B00101111, B10111110, B11111011, B11101111, B10000000,
-  B00000010, B10001010, B00100000, B00100010, B00000010, B00001000, B00000000,
-  B00000010, B10001010, B00101111, B10100010, B11111010, B00001111, B10000000,
-  B00000010, B10001001, B01001000, B10100010, B00000010, B00000000, B10000000,
-  B00000010, B10001000, B10001111, B10111110, B11111010, B00001111, B10000000,
-};
-
-const Sprite logo PROGMEM = {
-  53, 12, 7, logoLines
-};
-
-////////////////////////////////////////////////////////////
-// Pause data
-////////////////////////////////////////////////////////////
-
-#define PAUSE_X 14
-#define PAUSE_Y 29
-
-const uint8_t pauseLines[] PROGMEM = {
-  B01111000,B11100100,B01001111,B01111101,B11100000,
-  B01000101,B00010100,B01010000,B01000001,B00010000,
-  B01111001,B11110100,B01011111,B01111101,B00010000,
-  B01000001,B00010100,B01000001,B01000001,B00010000,
-  B01000001,B00010011,B10011110,B01111101,B11100000,
-};
-
-const Sprite pause PROGMEM = {
-  36, 5, 5, pauseLines
-};
-
-////////////////////////////////////////////////////////////
-// Digits data
-////////////////////////////////////////////////////////////
-
-#define DIGIT_H 5
-const uint8_t digitLines[] PROGMEM = {
-   B01100000, // 0
-   B10100000,
-   B10100000,
-   B10100000,
-   B11000000,
-   B01000000, // 1
-   B11000000,
-   B01000000,
-   B01000000,
-   B01000000,
-   B11000000, // 2
-   B00100000,
-   B01000000,
-   B10000000,
-   B11100000,
-   B11000000, // 3
-   B00100000,
-   B01000000,
-   B00100000,
-   B11000000,
-   B10100000, // 4
-   B10100000,
-   B11100000,
-   B00100000,
-   B00100000,
-   B11100000, // 5
-   B10000000,
-   B11000000,
-   B00100000,
-   B11000000,
-   B01100000, // 6
-   B10000000,
-   B11100000,
-   B10100000,
-   B11100000,
-   B11100000, // 7
-   B00100000,
-   B01000000,
-   B10000000,
-   B10000000,
-   B11100000, // 8
-   B10100000,
-   B11100000,
-   B10100000,
-   B11100000,
-   B11100000, // 9
-   B10100000,
-   B11100000,
-   B00100000,
-   B11000000
-};
-
-const Sprite digits[10] PROGMEM = {
-  {3, 5, 1, digitLines},
-  {3, 5, 1, digitLines + DIGIT_H},
-  {3, 5, 1, digitLines + DIGIT_H * 2},
-  {3, 5, 1, digitLines + DIGIT_H * 3},
-  {3, 5, 1, digitLines + DIGIT_H * 4},
-  {3, 5, 1, digitLines + DIGIT_H * 5},
-  {3, 5, 1, digitLines + DIGIT_H * 6},
-  {3, 5, 1, digitLines + DIGIT_H * 7},
-  {3, 5, 1, digitLines + DIGIT_H * 8},
-  {3, 5, 1, digitLines + DIGIT_H * 9},
-};
-
-////////////////////////////////////////////////////////////
-// Trajectory data
-////////////////////////////////////////////////////////////
-
-#define T_LENGTH 64
-#define T_WIDTH 49
-const uint8_t trajectory[T_LENGTH] PROGMEM = {24, 26, 28, 30, 33, 35, 37, 39, 40, 42, 43, 45, 46, 46, 47, 47, 48, 47, 47, 46, 46, 45, 43, 42, 40, 39, 37, 35, 33, 30, 28, 26, 23, 21, 19, 17, 14, 12, 10, 8, 7, 5, 4, 2, 1, 1, 0, 0, 0, 0, 0, 1, 1, 2, 4, 5, 7, 8, 10, 12, 14, 17, 19, 21};
-
-////////////////////////////////////////////////////////////
-// Phases
-////////////////////////////////////////////////////////////
-
-enum Phases
-{
-  PHASE_LOGO,
-  PHASE_GAME,
-  PHASE_NEXT_WAVE,
-  PHASE_GAMEOVER,
-  PHASE_PAUSED
-};
-uint8_t phase = PHASE_LOGO;
-
-////////////////////////////////////////////////////////////
-// Variables
-////////////////////////////////////////////////////////////
-
-#define INVADERS 10
-int invaderX[INVADERS];
-int invaderY[INVADERS];
-int invaderType[INVADERS];
-int invaderColor[INVADERS];
-int invaderSpeedX[INVADERS];
-int invaderSpeedY[INVADERS];
-int invaderPhase[INVADERS];
-
-int cannonX = (WIDTH - sprite_width(&cannon)) / 2;
-int cannonY = WIDTH - sprite_height(&cannon);
-
-#define SHOOTS 4
-#define SHOOT_H 4
-int shootX[SHOOTS];
-int shootY[SHOOTS];
-
-#define MAX_WAVE INVADERS
-int wave;
-int waveInvaders;
-
-#define SCORE_X 48
-#define HISCORE_Y HISCORE_LABEL_Y
-#define SCORE_Y HISCORE_Y + DIGIT_H + 1
-#define SCORE_DIGITS 4
-
-unsigned long frameTime;
-unsigned long invadeTime;
-unsigned long moveTime;
-unsigned long shootTime;
-unsigned long phaseTime;
-
-#define MAX_LIVES 3
-int lives;
-bool started;
-
-void render_digits(uint16_t num, int len, int x, int y, uint8_t *buf, int line, uint8_t color)
-{
-  uint8_t d[8] = {0};
-  int i = len - 1;
-  uint16_t s = num;
-  while (i >= 0 && s)
-  {
-    d[i--] = s % 10;
-    s /= 10;
-  }
-  for (int i = 0 ; i < len ; ++i)
-  {
-    sprite_render(&digits[d[i]], x, y, buf, line, color);
-    x += sprite_width(&digits[d[i]]) + 1;
-  }
-}
-
-void renderLine(uint8_t *buf, int y)
-{
-  for (int i = 0 ; i < WIDTH ; ++i)
-    buf[i] = 0;
-
-  // draw invaders
-  for (int i = 0 ; i < wave ; ++i)
-  {
-    if (invaderType[i])
-    {
-      sprite_render(invader_sprite(invaderType[i]), invaderX[i], invaderY[i], buf, y, invaderColor[i]);
-    }
-  }
-
-  // draw cannon
-  if (lives && phase == PHASE_GAME || phase == PHASE_NEXT_WAVE || phase == PHASE_PAUSED)
-    sprite_render(&cannon, cannonX, cannonY, buf, y, GREEN);
-
-  // draw shoots
-  if (phase == PHASE_GAME || phase == PHASE_NEXT_WAVE || phase == PHASE_PAUSED)
-    for (int i = 0 ; i < SHOOTS ; ++i)
-    {
-      if (shootY[i] >= 0)
-      {
-        if (y >= shootY[i] && y < shootY[i] + SHOOT_H)
-          buf[shootX[i]] = WHITE;
-      }
-    }
-
-  // draw gameover
-  if (phase == PHASE_GAMEOVER)
-    sprite_render(&gameOver, GAMEOVER_X, GAMEOVER_Y, buf, y, WHITE);
-
-  if (phase == PHASE_PAUSED)
-    sprite_render(&pause, PAUSE_X, PAUSE_Y, buf, y, WHITE);
-
-  // draw lives
-  int lifeWidth = sprite_width(&life);
-  for (int i = 0 ; i < lives ; ++i)
-    sprite_render(&life, LIFE_X + (lifeWidth + 1) * i, LIFE_Y, buf, y, GREEN);
-
-  // draw wave
-  if (phase == PHASE_GAME || phase == PHASE_NEXT_WAVE || phase == PHASE_PAUSED)
-  {
-    sprite_render(&waveSprite, WAVE_X, WAVE_Y, buf, y, CYAN);
-    render_digits(wave, 2, WAVE_X + 1 + sprite_width(&waveSprite), WAVE_Y, buf, y, WHITE);
-  }
-
-  // draw score
-  sprite_render(&hiLabel, HISCORE_LABEL_X, HISCORE_Y, buf, y, CYAN);
-  render_digits(hiscore, SCORE_DIGITS, SCORE_X, HISCORE_Y, buf, y, WHITE);
-  if (started)
-    render_digits(score, SCORE_DIGITS, SCORE_X, SCORE_Y, buf, y, WHITE);
-
-  // draw logo
-  if (phase == PHASE_LOGO)
-    sprite_render(&logo, (WIDTH - sprite_width(&logo)) / 2, (WIDTH - sprite_height(&logo)) / 2, buf, y, rand() % 6 + 1);
-
-  // there is broken LED here:
-  if (y == 63)
-    buf[63] = 0;
-}
-
-bool intersectRect(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)
-{
-  int xl = max(x1, x2);
-  int xr = min(x1 + w1, x2 + w2);
-  int yl = max(y1, y2);
-  int yr = min(y1 + h1, y2 + h2);
-  return xr > xl && yr > yl;
-}
-
-int step;
-int frame;
-unsigned long pauseTime = 0;
-int pauseTimeout = 500;
-
-void loop() {
-
-//  /----1111< - 16x64
-//  |    1111
-//  | /--2222<
-//  | |  2222
-//  | \---------\
-//  \---------\ |
-//       1111</ |
-//       1111   |
-//       2222<--/
-//       2222
-// По вертикали - поле 1 - биты BGR1
-//                поле 2 - биты BGR2
-//                координата - биты ABCD
-// По горизонтали - задвигаем 128 пикселей
-
-  int tock;
-  int tick;
-  tock = SCLKPORT;
-  tick = tock | sclkpin;
-
-  *oeport |= oepin;
-  *latport   |= latpin;
-  *latport   &= ~latpin;
-
-  if (step & 1)
-    *addraport |= addrapin;
-  else
-    *addraport &= ~addrapin;
-  if (step & 2)
-    *addrbport |= addrbpin;
-  else
-    *addrbport &= ~addrbpin;
-  if (step & 4)
-    *addrcport |= addrcpin;
-  else
-    *addrcport &= ~addrcpin;
-  if (step & 8)
-    *addrdport |= addrdpin;
-  else
-    *addrdport &= ~addrdpin;
-  step = (step + 1) & 0xf;
-
-  *oeport &= ~oepin;
-
-  int y1 = step;
-  int y2 = (step + 16);
-  int y3 = (step + 32);
-  int y4 = (step + 48);
-
-  uint8_t lines[4][WIDTH];
-  renderLine(lines[0], y1);
-  renderLine(lines[1], y2);
-  renderLine(lines[2], y3);
-  renderLine(lines[3], y4);
-
-// DATAPORT : BGR2 BGR1 00
-
-  for (int i = 0 ; i < WIDTH ; ++i)
-  {
-    DATAPORT = (lines[3][i] << 5) | (lines[2][i] << 2);//B01001100;
-    SCLKPORT = tick; // Clock lo
-    SCLKPORT = tock; // Clock hi
-  }
-  for (int i = 0 ; i < WIDTH ; ++i)
-  {
-    DATAPORT = (lines[1][i] << 5) | (lines[0][i] << 2);//B01001100;
-    SCLKPORT = tick; // Clock lo
-    SCLKPORT = tock; // Clock hi
-  }
-
-  unsigned long curTime = millis();
-  if (step == 0 && curTime - frameTime >= 160)
-  {
-    frameTime = curTime;
-
-    // moving invaders
-    if (phase != PHASE_PAUSED)
-    {
-      for (int i = 0 ; i < wave ; ++i)
-      {
-        if (invaderType[i])
-        {
-          int x = invaderX[i];
-          int y = invaderY[i];
-          y += invaderSpeedY[i];
-          if (y < WIDTH - 18)
-          {
-            x -= pgm_read_byte(&trajectory[invaderPhase[i]]);
-            invaderPhase[i] = (invaderPhase[i] + invaderSpeedX[i]) % T_LENGTH;
-            x += pgm_read_byte(&trajectory[invaderPhase[i]]);
-          }
-          else
-          {
-            invaderSpeedY[i] = 5;
-          }
-          invaderX[i] = x;
-          invaderY[i] = y;
-
-          if (y > WIDTH)
-          {
-            invaderType[i] = 0;
-            if (lives)
-            {
-              if (score >= 5)
-                score -= 5;
-              else
-                score = 0;
-            }
-          }
-        }
-      }
-    }
-
-    // new invader
-    if (phase == PHASE_GAME && curTime - invadeTime >= 500)
-    {
-      for (int i = 0 ; i < wave ; ++i)
-        if (!invaderType[i] && waveInvaders)
-        {
-          if (lives)
-            --waveInvaders;
-          invadeTime = curTime;
-          invaderType[i] = rand() % INVADER_TYPES + 1;
-          int offs = rand() % (WIDTH - T_WIDTH - invader_width(invaderType[i]));
-          invaderPhase[i] = rand() % T_LENGTH;
-          invaderX[i] = offs + pgm_read_byte(&trajectory[invaderPhase[i]]);
-          invaderY[i] = 0;
-          const int colors[5] = {4, 1, 5, 6, 3};
-          invaderColor[i] = colors[rand() % 5];
-          invaderSpeedY[i] = rand() % 2 + 1;
-          invaderSpeedX[i] = rand() % 4 + 1;
-          break;
-        }
-    }
-  }
-
-  // pause
-  if (step == 0 && ((*pauseport & pausepin) == 0) && (curTime >= pauseTime))
-  {
-    pauseTime = curTime + pauseTimeout;
-    if (phase == PHASE_PAUSED)
-    {
-      phase = PHASE_GAME;
-    }
-    else if ((phase == PHASE_GAME) || (phase == PHASE_NEXT_WAVE))
-    {
-      phase = PHASE_PAUSED;
-    }
-  }
-
-  if (step == 0 && (phase == PHASE_GAME || phase == PHASE_NEXT_WAVE) && curTime - moveTime >= 20)
-  {
-    moveTime = curTime;
-
-    // intersections
-    // shoot enemy
-    for (int s = 0 ; s < SHOOTS ; ++s)
-    {
-      if (shootY[s] >= 0)
-      {
-        shootY[s] -= 3;
-        for (int i = 0 ; i < wave ; ++i)
-        {
-          if (invaderType[i]
-            && intersectRect(shootX[s], shootY[s], 1, SHOOT_H, invaderX[i], invaderY[i], invader_width(invaderType[i]), invader_height(invaderType[i])))
-          {
-            invaderType[i] = 0;
-            shootY[s] = -1;
-
-            score += 1;//wave;
-            break;
-          }
-        }
-      }
-    }
-    if (lives)
-    {
-      // next wave
-      bool haveInvaders = false;
-      for (int i = 0 ; i < wave ; ++i)
-        if (invaderType[i])
-          haveInvaders = true;
-      if (!haveInvaders && !waveInvaders && phase == PHASE_GAME)
-      {
-        phase = PHASE_NEXT_WAVE;
-        ++wave;
-        invaderType[wave - 1] = 0;
-        waveInvaders = wave * 10;
-        // Impossible mission
-        if (wave == MAX_WAVE)
-          waveInvaders = 9999;
-        phaseTime = curTime;
-      }
-
-      // kill cannon
-      for (int i = 0 ; i < wave ; ++i)
-      {
-        if (invaderType[i]
-          && intersectRect(cannonX, cannonY, sprite_width(&cannon), sprite_height(&cannon), invaderX[i], invaderY[i], invader_width(invaderType[i]), invader_height(invaderType[i])))
-        {
-          --lives;
-          if (lives)
-          {
-            for (int j = 0 ; j < wave ; ++j)
-              invaderType[j] = 0;
-          }
-          else
-          {
-            phase = PHASE_GAMEOVER;
-            phaseTime = curTime;
-            if (score > hiscore)
-            {
-              hiscore = score;
-              EEPROM.write(0, hiscore & 0xff);
-              EEPROM.write(1, (hiscore >> 8) & 0xff);
-            }
-          }
-          break;
-        }
-      }
-
-      // move cannon
-      int cannonW = sprite_width(&cannon);
-      int step = 2;
-      if ((*rightport & rightpin) == 0 && cannonX + step + cannonW <= WIDTH)
-      {
-        cannonX = cannonX + step;
-      }
-      else if ((*leftport & leftpin) == 0 && cannonX - step >= 0)
-      {
-        cannonX = cannonX - step;
-      }
-      if (((*fireport & firepin) == 0)
-        && curTime - shootTime >= 500) // shoot
-      {
-        shootTime = curTime;
-        for (int i = 0 ; i < SHOOTS ; ++i)
-        {
-          if (shootY[i] < 0)
-          {
-            shootY[i] = cannonY - SHOOT_H;
-            shootX[i] = (cannonX + cannonW / 2) % WIDTH;
-            break;
-          }
-        }
-      }
-    }
-  }
-
-  if (step == 0 && phase == PHASE_LOGO
-      && ((*fireport & firepin) == 0))
-  {
-    started = true;
-    phase = PHASE_GAME;
-    lives = MAX_LIVES;
-    wave = 0;
-    waveInvaders = 0;
-    score = 0;
-    cannonX = (WIDTH - sprite_width(&cannon)) / 2;
-    cannonY = WIDTH - sprite_height(&cannon);
-    for (int i = 0 ; i < SHOOTS ; ++i)
-      shootY[i] = -1;
-  }
-
-  if (step == 0 && phase == PHASE_NEXT_WAVE && curTime - phaseTime > 2000)
-  {
-    phase = PHASE_GAME;
-  }
-
-  if (step == 0 && phase == PHASE_GAMEOVER && curTime - phaseTime > 3000)
-  {
-    phase = PHASE_LOGO;
-  }
-}
-


Setting a more accurate percent battery figure

--- DigitalVFO.ino
+++ DigitalVFO.ino
@@ -38,13 +38,13 @@
 #define DEBUG_BATT    (1 << 8)  // battery

 // DEBUG word for debugging program - bitmask values
-//#define DEBUG         (DEBUG_BATT)
-#define DEBUG         0
+#define DEBUG         (DEBUG_BATT)
+//#define DEBUG         0

 // Digital VFO program name & version
 const char *ProgramName = "DigitalVFO";
 const char *Version = "1.4";
-const char *MinorVersion = ".4";
+const char *MinorVersion = ".5";
 const char *Callsign = "AC3DN";

 // display constants - below is for ubiquitous small HD44780 16x2 display
@@ -219,7 +219,7 @@

 // battery voltage limits
 const float OverVoltage = 8.35;   // battery voltage for CHARGING & FULL
-const float MaxVoltage = 7.8;     // battery voltage for "100% full"
+const float MaxVoltage = 8.0;     // battery voltage for "100% full"
 const float MinVoltage = 6.48;    // battery voltage for "0% full"
                                   // BMS disconnects at around 6.40v
 const float NoBattVoltage = 5.5;  // if at or below this, no battery
@@ -2708,7 +2708,7 @@
 #if (DEBUG & DEBUG_BATT)
   if (++batt_report_count > 0)
   {
-    Serial.printf(F("raw volts=%d, %.2fv, %d%%, "), measured, AverageVoltage, percent);
+    Serial.printf(F("volts: average=%.2fv, value=%d%%, "), AverageVoltage, percent);
   }
 #endif


another small profile adjustment - brake earlier for smooth ending

--- GeheimTuer.ino
+++ GeheimTuer.ino
@@ -112,7 +112,7 @@
     brake: false
   },
   { // accelerate and keep running
-    maxMillis: 2300,
+    maxMillis: 2000,
     stepMillis: 5,
     factor: 1,
     add: 1,
@@ -362,12 +362,12 @@
         Serial.println(currentMillis); break;
     case 'h':
       motorDisable();
-      doorState = doorError; break;
+      doorState = doorError;
+      break;
     case 'r':
       motorEnable();
-      doorState = doorBlocked; break;
-    case '\n':
-      Serial.print(F("\r\n")); break;
+      doorState = doorBlocked;
+      break;
   }
 }


branch on short enum motorDir instead of int dir

--- GeheimTuer.ino
+++ GeheimTuer.ino
@@ -671,7 +671,7 @@
   drivePWM = accelProfile[0].startPWM;
   driveMillis = driveStepMillis = driveTotalMillis = 0;

-  switch(dir) {
+  switch(motorDir) {
     case forward:
       motorForward(); break;
     case backward:


1.0 RC3

1.0 RC3

- Revert wirings to Protonerd's original
- Several bug fixes

--- Lightsaber.ino
+++ Lightsaber.ino
@@ -16,6 +16,7 @@
 #include <SoftwareSerial.h>
 #include <EEPROMex.h>
 #include <OneButton.h>
+#include <TimerOne.h>
 #include "SoundFont.h"
 #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
 #include <Wire.h>
@@ -24,8 +25,8 @@
 /*
  * DO NOT MODIFY
  */
-#define CONFIG_VERSION "LS01"
-
+#define CONFIG_VERSION 		"LS01"
+#define MEMORYBASE 			32

 #define LEDSTRINGS  // Comment this RGB users
 #ifndef LEDSTRINGS
@@ -43,29 +44,28 @@
  * Spare :
  * A2,13,D11
  */
-#ifdef LEDSTRINGS
+
 #define LEDSTRING1 			3
-#define LEDSTRING2 			4
-#define LEDSTRING3 			5
-#define LEDSTRING4 			6
-#define LEDSTRING5 			7
-#define LEDSTRING6 			8
-#endif
+#define LEDSTRING2 			5
+#define LEDSTRING3 			6
+#define LEDSTRING4 			9
+#define LEDSTRING5 			10
+#define LEDSTRING6 			11

 #ifdef LUXEON
 #define COLORS		 		54   // Number of RGB (not RGBW) colors in our array. Do we need that much ?
 #define LED_RED 			3
-#define LED_GREEN 			4
-#define LED_BLUE 			5
-//#define LED_WHITE 			6   //Not used right now
-#endif
-
-#define DFPLAYER_RX			13
-#define DFPLAYER_TX			12
+#define LED_GREEN 			5
+#define LED_BLUE 			6
+//#define LED_WHITE 			9   //Not used right now
+#endif
+
+#define DFPLAYER_RX			8
+#define DFPLAYER_TX			7
 #define SPK1				A0
 #define SPK2				A1
-#define MAIN_BUTTON			9
-#define LOCKUP_BUTTON		10
+#define MAIN_BUTTON			12
+#define LOCKUP_BUTTON		4

 /*
  * DEFAULT CONF PARAMETERS
@@ -81,11 +81,18 @@
 /*
  * OTHER PARAMETERS
  */
+#define CLICK				5
+#define PRESS_ACTION		150
+#define PRESS_CONFIG		500
 #define SWING_SUPPRESS 		110
 #define CLASH_SUPPRESS 		60
-#define MEMORYBASE 			32
 #define CLASH_PASSES 		10
-#define MAX_BRIGHTNESS		255
+/* MAX_BRIGHTNESS
+ * Maximum output voltage to apply to LEDS
+ * Default = 200 (78,4%) Max=255 Min=0(Off)
+ * WARNING ! A too high value may burn your leds. Please make your maths !
+ */
+#define MAX_BRIGHTNESS		200

 /* For daily use I recommend you comment LS_INFO
  * When you plug your device to USB uncomment LS_INFO !
@@ -128,11 +135,11 @@
  * LED String variables
  */
 #ifdef LEDSTRINGS
-int ledPins[] = {LEDSTRING1, LEDSTRING2, LEDSTRING3, LEDSTRING4, LEDSTRING5,
-	LEDSTRING6};
+int ledPins[] = { LEDSTRING1, LEDSTRING2, LEDSTRING3, LEDSTRING4, LEDSTRING5,
+LEDSTRING6 };
 #endif
 #ifdef LUXEON
-int ledPins[] = { LED_RED, LED_GREEN, LED_BLUE /*,LED_WHITE*/};
+int ledPins[] = {LED_RED, LED_GREEN, LED_BLUE /*,LED_WHITE*/};

 // byte color => {R,G,B,ColorNumber}
 byte currentColor[3];
@@ -158,7 +165,9 @@
 DFPlayer mp3;
 SoundFont soundFont;
 int lastPlayed = 0;
-int lastPlayed2 = 0;
+//int lastPlayed2 = 0;
+long value = 0;
+long lastValue = 0;
 bool repeat = false;
 bool changePlayMode = false;
 uint8_t hum[] = { 0x7E, 0xFF, 0x06, 0x0F, 0x00, 0x01, 0x05, 0xFE, 0xE6, 0xEF };
@@ -174,9 +183,20 @@
 bool changeMenu = false;
 bool ok = true;
 int configAdress = 0;
-long lastValue = 0;
 bool play = false;
 #ifdef LEDSTRINGS
+struct StoreStruct {
+	// This is for mere detection if they are our settings
+	char version[5];
+	// The settings
+	int volume; // 0 to 30
+	int soundFont; // as many as Sound font you have defined in Soundfont.h
+	long swingTreshold; // treshold acceleration for Swing
+	long clashAccelTreshold; // treshold acceleration for Swing
+	long clashBrakeTreshold; // treshold acceleration for Swing
+} storage;
+#endif
+#ifdef LUXEON
 struct StoreStruct {
 	// This is for mere detection if they are our settings
 	char version[5];
@@ -186,29 +206,16 @@
 	long swingTreshold;// treshold acceleration for Swing
 	long clashAccelTreshold;// treshold acceleration for Swing
 	long clashBrakeTreshold;// treshold acceleration for Swing
-}storage;
-#endif
-#ifdef LUXEON
-struct StoreStruct {
-	// This is for mere detection if they are our settings
-	char version[5];
-	// The settings
-	int volume;		// 0 to 30
-	int soundFont;		// as many as Sound font you have defined in Soundfont.h
-	long swingTreshold;		// treshold acceleration for Swing
-	long clashAccelTreshold;		// treshold acceleration for Swing
-	long clashBrakeTreshold;		// treshold acceleration for Swing
 	byte mainColor[4];
 	byte clashColor[4];
-	byte soundFontColorPreset[SOUNDFONT_QUANTITY+2][2];
-} storage;
+	byte soundFontColorPreset[SOUNDFONT_QUANTITY + 2][2];
+}storage;
 #endif

 // ================================================================
 // ===               	   SETUP ROUTINE  	 	                ===
 // ================================================================
 void setup() {
-	lightOff(ledPins);

 	// join I2C bus (I2Cdev library doesn't do this automatically)
 #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
@@ -262,7 +269,7 @@

 #ifdef LUXEON
 	//initialise start color
-	lightChangeColor(storage.mainColor,false);
+	lightChangeColor(storage.mainColor, false);
 #endif

 	/***** LOAD CONFIG *****/
@@ -348,26 +355,34 @@
 	pinMode(ledPins[4], OUTPUT);
 	pinMode(ledPins[5], OUTPUT);
 #endif
+	// For "security" we shutoff all pins wearing leds
+	analogWrite(LEDSTRING1, 0);
+	analogWrite(LEDSTRING2, 0);
+	analogWrite(LEDSTRING3, 0);
+	analogWrite(LEDSTRING4, 0);
+	analogWrite(LEDSTRING5, 0);
+	analogWrite(LEDSTRING6, 0);
+
 	/***** LED SEGMENT INITIALISATION  *****/

 	/***** BUTTONS INITIALISATION  *****/
 	// link the Main button functions.
-	mainButton.setClickTicks(5);
-	mainButton.setPressTicks(400);
+	mainButton.setClickTicks(CLICK);
+	mainButton.setPressTicks(PRESS_CONFIG);
 	mainButton.attachClick(mainClick);
-	mainButton.attachDoubleClick(mainDoubleClick);
+//	mainButton.attachDoubleClick(mainDoubleClick);
 	mainButton.attachLongPressStart(mainLongPressStart);
 	mainButton.attachLongPressStop(mainLongPressStop);
 	//mainButton.attachDuringLongPress(mainLongPress);

 	// link the Lockup button functions.
-	lockupButton.setClickTicks(5);
-	lockupButton.setPressTicks(400);
+	lockupButton.setClickTicks(CLICK);
+	lockupButton.setPressTicks(PRESS_CONFIG);
 	lockupButton.attachClick(lockupClick);
-	lockupButton.attachDoubleClick(lockupDoubleClick);
+//	lockupButton.attachDoubleClick(lockupDoubleClick);
 	lockupButton.attachLongPressStart(lockupLongPressStart);
 	lockupButton.attachLongPressStop(lockupLongPressStop);
-	lockupButton.attachDuringLongPress(lockupLongPress);
+//	lockupButton.attachDuringLongPress(lockupLongPress);
 	/***** BUTTONS INITIALISATION  *****/

 	/***** DF PLAYER INITIALISATION  *****/
@@ -415,6 +430,9 @@
 			/*
 			 *  This is the very first loop after Action Mode has been turned on
 			 */
+
+			// Reduce lockup trigger time
+			lockupButton.setPressTicks(PRESS_ACTION);
 #ifdef LS_INFO
 			Serial.println(F("START ACTION"));
 #endif
@@ -433,8 +451,6 @@
 			changePlayMode = false;
 			isBigAcceleration = false;
 			isBigBrake = false;
-			//reduce lockup trigger time
-			lockupButton.setPressTicks(200);
 		}

 		// Do we want next soundfile to be play continuously ?
@@ -632,7 +648,7 @@
 					 * We relaunch the hum !
 					 */
 #ifdef LUXEON
-					lightChangeColor(storage.mainColor,true);
+					lightChangeColor(storage.mainColor, true);
 #endif
 #ifdef LS_RELAUNCH_DEBUG
 					Serial.print(F("MP3 stopped :"));
@@ -672,35 +688,36 @@
 	 * CONFIG MODE HANDLER
 	 */
 	else if (configMode) {
-		long value = 0;
+
 #ifdef LUXEON
 		byte rgbArray[COLORS][3] = {
-				// RGB Array 3 wide 54 tall, stores RGB values
-				// (There's gotta be a prettier way to do this!)
-				{ 100, 0, 0 }, /*Red*/
-				{ 100, 15, 0 }, { 100, 40, 0 }, { 100, 60, 0 }, { 100, 100, 0 },
-				{ 60, 100, 0 }, { 40, 100, 0 }, { 15, 100, 0 },
-				{ 0, 100, 0 } /*Green*/, { 0, 100, 15 }, { 0, 100, 40 }, { 0,
-						100, 60 }, { 0, 100, 100 }, { 0, 60, 100 },
-				{ 0, 40, 100 }, { 0, 15, 100 }, { 0, 0, 100 }, /*Blue*/
-				{ 15, 0, 100 }, { 40, 0, 100 }, { 60, 0, 100 }, { 100, 0, 100 },
-				{ 100, 0, 60 }, { 100, 0, 40 }, { 100, 0, 15 },
-				//Hue one, a lighter starts at Array pointer 40100
-				{ 100, 15, 15 }, { 100, 40, 15 }, { 100, 60, 15 }, { 100, 100,
-						15 }, { 60, 100, 15 }, { 40, 100, 15 }, { 15, 100, 15 },
-				{ 15, 100, 40 }, { 15, 100, 60 }, { 15, 100, 100 }, { 15, 60,
-						100 }, { 15, 40, 100 }, { 15, 15, 100 },
-				{ 40, 15, 100 }, { 60, 15, 100 }, { 100, 15, 100 }, { 100, 15,
-						60 }, { 100, 15, 40 },
-				//Hue two, Lightest starts at Array pointer 10040
-				{ 100, 40, 40 }, { 100, 60, 40 }, { 100, 100, 40 }, { 60, 100,
-						40 }, { 40, 100, 40 }, { 40, 100, 60 },
-				{ 40, 100, 100 }, { 40, 60, 100 }, { 40, 40, 100 }, { 60, 40,
-						100 }, { 100, 40, 100 }, { 100, 40, 60 }, };
+			// RGB Array 3 wide 54 tall, stores RGB values
+			// (There's gotta be a prettier way to do this!)
+			{	100, 0, 0}, /*Red*/
+			{	100, 15, 0}, {100, 40, 0}, {100, 60, 0}, {100, 100, 0},
+			{	60, 100, 0}, {40, 100, 0}, {15, 100, 0},
+			{	0, 100, 0} /*Green*/, {0, 100, 15}, {0, 100, 40}, {0,
+				100, 60}, {0, 100, 100}, {0, 60, 100},
+			{	0, 40, 100}, {0, 15, 100}, {0, 0, 100}, /*Blue*/
+			{	15, 0, 100}, {40, 0, 100}, {60, 0, 100}, {100, 0, 100},
+			{	100, 0, 60}, {100, 0, 40}, {100, 0, 15},
+			//Hue one, a lighter starts at Array pointer 40100
+			{	100, 15, 15}, {100, 40, 15}, {100, 60, 15}, {100, 100,
+				15}, {60, 100, 15}, {40, 100, 15}, {15, 100, 15},
+			{	15, 100, 40}, {15, 100, 60}, {15, 100, 100}, {15, 60,
+				100}, {15, 40, 100}, {15, 15, 100},
+			{	40, 15, 100}, {60, 15, 100}, {100, 15, 100}, {100, 15,
+				60}, {100, 15, 40},
+			//Hue two, Lightest starts at Array pointer 10040
+			{	100, 40, 40}, {100, 60, 40}, {100, 100, 40}, {60, 100,
+				40}, {40, 100, 40}, {40, 100, 60},
+			{	40, 100, 100}, {40, 60, 100}, {40, 40, 100}, {60, 40,
+				100}, {100, 40, 100}, {100, 40, 60},};
 #endif

 		if (!browsing) {
-			//mp3.playTrackFromDir(1, 1/*,false*/);
+			mp3.playTrackFromDir(3, 1/*,false*/);
+			delay(500);
 #ifdef LS_INFO
 			Serial.println(F("START CONF"));
 #endif
@@ -722,68 +739,31 @@

 		switch (menu) {
 		case 0:
-			if (enterMenu) {
-				mp3.playTrackFromDir(4, 1/*, false*/);
-#ifdef LS_INFO
-				Serial.print(F("VOLUME\nCur:"));
-				Serial.println(storage.volume);
-#endif
-				enterMenu = false;
-			}
-			lastValue = storage.volume;
-			value = storage.volume + modification;
-			modification = 0;
-			if (value < 0) {
-				value = 30;
-			} else if (value > 30) {
-				value = 0;
-			} else if (value == 0 and play) {
-				play = false;
-				mp3.playTrackFromDir(15, 1/*, false*/);
-			} else if (value == 30 and play) {
-				play = false;
-				mp3.playTrackFromDir(14, 1/*, false*/);
-			}
+			confMenuStart(4);
+
+			confParseValue(storage.volume, 0, 30, 1);
+
 			if (value != lastValue) {
 				storage.volume = value;
 				mp3.setVolume(storage.volume);
+				delay(10);
 #ifdef LS_INFO
 				Serial.println(storage.volume);
 #endif
 			}
+
 			break;
 		case 1:
-			if (enterMenu) {
-				mp3.playTrackFromDir(5, 1);
-#ifdef LS_INFO
-				Serial.println(F("SOUNDFONT\nCur:"));
-				Serial.println(soundFont.getFolder());
-#endif
-				enterMenu = false;
-				delay(500);
-			}
-			lastValue = soundFont.getFolder();
-			value = soundFont.getFolder() + modification;
-			modification = 0;
-			if (value < 2) {
-				value = SOUNDFONT_QUANTITY + 1;
-			} else if (value > SOUNDFONT_QUANTITY + 1) {
-				value = 2;
-			} else if (value == 2 and play) {
-				play = false;
-				mp3.playTrackFromDir(15, 1/*, false*/);
-				delay(500);
-			} else if (value == SOUNDFONT_QUANTITY + 1 and play) {
-				play = false;
-				mp3.playTrackFromDir(14, 1/*, false*/);
-				delay(500);
-			}
+			confMenuStart(5);
+
+			confParseValue(storage.soundFont, 2, SOUNDFONT_QUANTITY + 1, 1);
+
 			if (value != lastValue) {
 				storage.soundFont = value;
 				soundFont.setFolder(value);
-				mp3.playTrackFromDir(soundFont.getBoot(), soundFont.getFolder()/*, false*/);
+				mp3.playTrackFromDir(soundFont.getBoot(),
+						soundFont.getFolder()/*, false*/);
 				delay(500);
-				//mp3.playTrackFromDir(soundFont.getBoot(),soundFont.getFolder()/*, false*/);
 #ifdef LUXEON
 				storage.mainColor[3] = storage.soundFontColorPreset[value][0];
 				storage.mainColor[0] = rgbArray[storage.mainColor[3]][0];
@@ -801,100 +781,50 @@
 			}
 			break;
 #ifdef LUXEON
-		case 2:
-			if (enterMenu) {
-				mp3.playTrackFromDir(9, 1);
-				ledOff(ledPins);
-				lightChangeColor(storage.mainColor,true);
-#ifdef LS_INFO
-				Serial.print(F("COLOR1\nCur:"));
-				Serial.println(storage.mainColor[3]);
-#endif
-				enterMenu = false;
-				delay(500);
-			}
-			lastValue = storage.mainColor[3];
-			value = storage.mainColor[3] + modification;
-			modification = 0;
-			if (value < 0) {
-				value = COLORS;
-			} else if (value > COLORS) {
-				value = 0;
-			} else if (value == 0 and play) {
-				play = false;
-				mp3.playTrackFromDir(15, 1/*, false*/);
-			} else if (value == COLORS and play) {
-				play = false;
-				mp3.playTrackFromDir(14, 1/*, false*/);
-			}
+			case 2:
+			confMenuStart(9);
+
+			confParseValue(storage.mainColor[3], 0, COLORS, 1);
+
 			if (value != lastValue) {
 				storage.mainColor[0] = rgbArray[value][0];
 				storage.mainColor[1] = rgbArray[value][1];
 				storage.mainColor[2] = rgbArray[value][2];
 				storage.mainColor[3] = value;
-				lightChangeColor(storage.mainColor,true);
+				lightChangeColor(storage.mainColor, true);
 #ifdef LS_INFO
 				Serial.println(storage.mainColor[3]);
 #endif
 			}
 			break;
-		case 3:
-			if (enterMenu) {
-				mp3.playTrackFromDir(10, 1);
-				ledOff(ledPins);
-				lightChangeColor(storage.clashColor,true);
-#ifdef LS_INFO
-				Serial.print(F("COLOR2\nCur:"));
-				Serial.println(storage.clashColor[3]);
-#endif
-				enterMenu = false;
-				delay(500);
-			}
-			lastValue = storage.clashColor[3];
-			value = storage.clashColor[3] + modification;
-			modification = 0;
-			if (value < 0) {
-				value = COLORS;
-			} else if (value > COLORS) {
-				value = 0;
-			} else if (value == 0 and play) {
-				play = false;
-				mp3.playTrackFromDir(15, 1/*, false*/);
-			} else if (value == COLORS and play) {
-				play = false;
-				mp3.playTrackFromDir(14, 1/*, false*/);
-			}
+			case 3:
+			confMenuStart(10);
+
+			confParseValue(storage.clashColor[3], 0, COLORS, 1);
+
 			if (value != lastValue) {
 				storage.clashColor[0] = rgbArray[value][0];
 				storage.clashColor[1] = rgbArray[value][1];
 				storage.clashColor[2] = rgbArray[value][2];
 				storage.clashColor[3] = value;
-				lightChangeColor(storage.clashColor,true);
+				lightChangeColor(storage.clashColor, true);
 #ifdef LS_INFO
 				Serial.println(storage.clashColor[3]);
 #endif
 			}
 			break;
-		case 4:
-			if (enterMenu) {
-				mp3.playTrackFromDir(11, 1);
-				ledOff(ledPins);
-#ifdef LS_INFO
-				Serial.print(
-						F(
-								"SAVE TO SOUNDFONT?\nMain :Yes/Lockup: No"));
-#endif
-				enterMenu = false;
-				delay(500);
-			}
+			case 4:
+			confMenuStart(11);
+
 			if (modification > 0) {
 				//Yes
 				//We save color values to this Soundfount
+				Serial.println(F("Yes"));
 				mp3.playTrackFromDir(12, 1/*, false*/);
 				storage.soundFontColorPreset[storage.soundFont][0] =
-						storage.mainColor[3];
+				storage.mainColor[3];
 				storage.soundFontColorPreset[storage.soundFont][1] =
-						storage.clashColor[3];
+				storage.clashColor[3];
 				menu++;
 				changeMenu = true;
 				enterMenu = true;
@@ -902,39 +832,21 @@
 			} else if (modification < 0) {
 				//No
 				// we do nothing and leave this menu
+				Serial.println(F("No"));
 				mp3.playTrackFromDir(13, 1/*, false*/);
 				menu++;
 				changeMenu = true;
 				enterMenu = true;
-				delay(500);
+				delay(20);
 			}
 			modification = 0;
 			break;
 #endif
 		case 5:
-			if (enterMenu) {
-				mp3.playTrackFromDir(6, 1);
-#ifdef LS_INFO
-				Serial.print(F("SWING\nCur:"));
-				Serial.print(storage.swingTreshold);
-#endif
-				enterMenu = false;
-				delay(500);
-			}
-			lastValue = storage.swingTreshold;
-			value = storage.swingTreshold + 100 * modification;
-			modification = 0;
-			if (value < 500) {
-				value = 2000;
-			} else if (value > 2000) {
-				value = 500;
-			} else if (value == 500 and play) {
-				play = false;
-				mp3.playTrackFromDir(15, 1/*, false*/);
-			} else if (value == 2000 and play) {
-				play = false;
-				mp3.playTrackFromDir(14, 1/*, false*/);
-			}
+			confMenuStart(6);
+
+			confParseValue(storage.swingTreshold, 500, 2000, 100);
+
 			if (value != lastValue) {
 				storage.swingTreshold = value;
 #ifdef LS_INFO
@@ -943,28 +855,10 @@
 			}
 			break;
 		case 6:
-			if (enterMenu) {
-				mp3.playTrackFromDir(7, 1);
-#ifdef LS_INFO
-				Serial.print(F("CLASH1\nCur:"));
-				Serial.print(storage.clashAccelTreshold);
-#endif
-				enterMenu = false;
-			}
-			lastValue = storage.clashAccelTreshold;
-			value = storage.clashAccelTreshold + 250 * modification;
-			modification = 0;
-			if (value < 8000) {
-				value = 15000;
-			} else if (value > 15000) {
-				value = 8000;
-			} else if (value == 8000 and play) {
-				play = false;
-				mp3.playTrackFromDir(15, 1/*, false*/);
-			} else if (value == 15000 and play) {
-				play = false;
-				mp3.playTrackFromDir(14, 1/*, false*/);
-			}
+			confMenuStart(7);
+
+			confParseValue(storage.clashAccelTreshold, 8000, 15000, 250);
+
 			if (value != lastValue) {
 				storage.clashAccelTreshold = value;
 #ifdef LS_INFO
@@ -973,29 +867,10 @@
 			}
 			break;
 		case 7:
-			if (enterMenu) {
-				mp3.playTrackFromDir(8, 1);
-#ifdef LS_INFO
-				Serial.print(F("CLASH2\nCur:"));
-				Serial.print(storage.clashBrakeTreshold);
-#endif
-				enterMenu = false;
-				delay(500);
-			}
-			lastValue = storage.clashBrakeTreshold;
-			value = storage.clashBrakeTreshold + 250 * modification;
-			modification = 0;
-			if (value < 1000) {
-				value = 5000;
-			} else if (value > 5000) {
-				value = 1000;
-			} else if (value == 1000 and play) {
-				mp3.playTrackFromDir(15, 1/*, false*/);
-				play = false;
-			} else if (value == 5000 and play) {
-				mp3.playTrackFromDir(14, 1/*, false*/);
-				play = false;
-			}
+			confMenuStart(8);
+
+			confParseValue(storage.clashBrakeTreshold, 1000, 5000, 250);
+
 			if (value != lastValue) {
 				storage.clashBrakeTreshold = value;
 #ifdef LS_INFO
@@ -1019,6 +894,7 @@
 #ifdef LS_INFO
 			Serial.println(F("END ACTION"));
 #endif
+			lockupButton.setPressTicks(PRESS_CONFIG);
 			lastPlayed = mp3.playTrackFromDir(soundFont.getPowerOff(),
 					soundFont.getFolder());
 			changeMenu = false;
@@ -1049,9 +925,8 @@
 			modification = 0;
 			lightOff(ledPins);
 			menu = 0;
-			lockupButton.setPressTicks(400);
 #ifdef LUXEON
-			lightChangeColor(storage.mainColor,false);
+			lightChangeColor(storage.mainColor, false);
 #endif
 #ifdef LS_INFO
 			Serial.println(F("END CONF"));
@@ -1117,8 +992,8 @@
 		menu++;
 #ifdef LEDSTRINGS
 		lightOff(ledPins);
-		if (menu==2) {
-			menu=5;
+		if (menu == 2) {
+			menu = 5;
 		}
 		analogWrite(ledPins[menu], 160);
 #endif
@@ -1168,10 +1043,10 @@
 	if (actionMode) {
 		// Blaster
 #ifdef LEDSTRINGS
-		analogWrite(random(0, 5), 0); //momentary shut off one led segment
+		analogWrite(ledPins[random(6)], LOW); //momentary shut off one led segment
 #endif
 #ifdef LUXEON
-		lightChangeColor(storage.clashColor,true);
+		lightChangeColor(storage.clashColor, true);
 #endif
 		if (soundFont.getBlaster()) {
 			// Some Soundfont may not have Blaster sounds
@@ -1220,7 +1095,7 @@
 	if (actionMode) {
 		//Lockup Start
 #ifdef LUXEON
-		lightChangeColor(storage.clashColor,true);
+		lightChangeColor(storage.clashColor, true);
 #endif
 		//		Serial.println(soundFont.getLockup());
 		//		if (soundFont.getLockup()) {
@@ -1269,7 +1144,7 @@
 	if (actionMode) {
 		//Lockup Stop
 #ifdef LUXEON
-		lightChangeColor(storage.mainColor,true);
+		lightChangeColor(storage.mainColor, true);
 #endif
 		lastPlayed = mp3.playTrackFromDir(4, soundFont.getFolder());
 		repeat = true;
@@ -1327,28 +1202,29 @@
 void lightOn(int ledPins[]) {

 // Light up the leds
-	for (int fadeIn = 6; fadeIn > 0; fadeIn--) {
+	for (int fadeIn = 255; fadeIn > 0; fadeIn--) {
 		for (int i = 0; i <= 2; i++) {
 			analogWrite(ledPins[i],
 					(MAX_BRIGHTNESS / fadeIn) * currentColor[i] / 100);
 		}
-		delay(85);
+		delay(2);
 	}
 } //lightOn

 void lightOff(int ledPins[]) {
 // Light off the leds
 // Fade out
-	for (int fadeOut = 6; fadeOut >= 1; fadeOut--) {
+	for (int fadeOut = 255; fadeOut >= 1; fadeOut--) {
 		for (int i = 2; i >= 0; i--) {
 			analogWrite(ledPins[i],
-					(MAX_BRIGHTNESS / fadeOut) * currentColor[i] / 100);
-		}
-		delay(85);
+					(MAX_BRIGHTNESS - (MAX_BRIGHTNESS / fadeOut))
+					* currentColor[i] / 100);
+		}
+		delay(2);
 	}
 // shut Off
 	for (int i = 0; i <= 2; i++) {
-		digitalWrite(ledPins[i], LOW);
+		analogWrite(ledPins[i], LOW);
 	}
 } //lightOff

@@ -1359,12 +1235,11 @@
 	}
 } //lightFlicker

-void lightChangeColor(byte color[],bool lightup) {
+void lightChangeColor(byte color[], bool lightup) {
 // lightFlicker the leds
 	for (int i = 0; i <= 2; i++) {
 		currentColor[i] = color[i];
-		if (lightup)
-		{
+		if (lightup) {
 			analogWrite(ledPins[i], MAX_BRIGHTNESS * currentColor[i] / 100);
 		}
 	}
@@ -1482,6 +1357,74 @@
 #endif

 // ================================================================
+// ===           	  	 CONFIG MODE FUNCTIONS	                ===
+// ================================================================
+
+void confParseValue(int variable, int min, int max, int multiplier) {
+	lastValue = variable;
+	value = variable + multiplier * modification;
+	modification = 0;
+	if (value < min) {
+		value = max;
+	} else if (value > max) {
+		value = min;
+	} else if (value == min and play) {
+		play = false;
+		mp3.playTrackFromDir(15, 1/*, false*/);
+		delay(50);
+	} else if (value == max and play) {
+		play = false;
+		mp3.playTrackFromDir(14, 1/*, false*/);
+		delay(50);
+	}
+}
+
+void confMenuStart(int sound) {
+	if (enterMenu) {
+		mp3.playTrackFromDir(sound, 1);
+#ifdef LS_INFO
+		switch (sound) {
+		case 4:
+			Serial.print(F("VOLUME\nCur:"));
+			Serial.println(storage.volume);
+			break;
+		case 5:
+			Serial.println(F("SOUNDFONT\nCur:"));
+			Serial.println(soundFont.getFolder());
+			break;
+		case 6:
+			Serial.print(F("SWING\nCur:"));
+			Serial.println(storage.swingTreshold);
+			break;
+#ifdef LUXEON
+			case 9:
+			Serial.print(F("COLOR1\nCur:"));
+			Serial.println(storage.mainColor[3]);
+			break;
+			case 10:
+			Serial.print(F("COLOR2\nCur:"));
+			Serial.println(storage.clashColor[3]);
+			break;
+			case 11:
+			Serial.println(F("SAVE TO SOUNDFONT?\nMain :Yes/Lockup: No"));
+			break;
+#endif
+		case 7:
+			Serial.print(F("CLASH1\nCur:"));
+			Serial.println(storage.clashAccelTreshold);
+			break;
+		case 8:
+			Serial.print(F("CLASH2\nCur:"));
+			Serial.println(storage.clashBrakeTreshold);
+			break;
+		}
+#endif
+		enterMenu = false;
+		delay(500);
+	}
+}
+
+// ================================================================
 // ===           	  EEPROM MANIPULATION FUNCTIONS	            ===
 // ================================================================


Update LightTrain.ino

Update LightTrain.ino

Spelfout verbeterd

--- LightTrain.ino
+++ LightTrain.ino
@@ -38,7 +38,7 @@
   while (sensor1 > SENSOR_THRESHOLD) {
     ms++;
     sensor2 = analogRead(A1);
-    if(sensor2 < SENSOR_TRESHOLD) break;
+    if(sensor2 < SENSOR_THRESHOLD) break;
     delay(1);
   }
   snelheid = AFSTAND_TRAJECT/(float)ms;


Big clean up and added functionality

Big clean up and added functionality

Now it sends the following 16-bit values:
[0]..[2]: Raw AxAyAz
[3]..[5]: Raw GxGyGz
[6]: Movement Intensity
[7]: Milliseconds dice has been motionless.
[8]: DiceId (does not change for each die)
[9]: Sequence #; increments by 1 on every BLE packet sent.


Make teensy work a bit better (player 4+ is broken, player 3 is dubious)


Fix to allow 5 digit 'mqtt_port'

Fix to allow 5 digit 'mqtt_port'

'WiFiManagerParameter custom_mqtt_port' made consistent with declaration of 'mqtt_port'

--- examples/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino
+++ examples/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino
@@ -74,7 +74,7 @@
   // After connecting, parameter.getValue() will get you the configured value
   // id/name placeholder/prompt default length
   WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 40);
-  WiFiManagerParameter custom_mqtt_port("port", "mqtt port", mqtt_port, 5);
+  WiFiManagerParameter custom_mqtt_port("port", "mqtt port", mqtt_port, 6);
   WiFiManagerParameter custom_blynk_token("blynk", "blynk token", blynk_token, 32);

   //WiFiManager


Not for standard

Not for standard

--- espLightServerRGB.ino
+++ espLightServerRGB.ino
@@ -1,359 +0,0 @@
-#include <ESP8266WiFi.h>
-#include <DNSServer.h>
-#include <ESP8266WebServer.h>
-#include <WiFiManager.h>
-#include <ESP8266HTTPClient.h>
-#include <Ticker.h>
-#include <ESP8266mDNS.h>
-#include <OneWire.h>
-#include <DallasTemperature.h>
-#define ONE_WIRE_BUS D4
-String resetpass = "YourResetPassword"; // password to reset wifimanager when allready connected
-const String thingkey = "YOURTHINGSPEKKEY"; //your thingspeak API key
-String dernadd = "Fraichement booté"; //variable for ip logging (you can put your fresh boot mesage here in text/html)
-int pinRouge = D1; // pin for red leds
-int pinVerte = D7; // pin for green leds
-int pinBleu = D5; // pin for blue leds
-const long interval = 60000; // interval in ms for sending temperature data to thingspeak
-const String liens = "Acceuil - Température - Version - Reset - Temp stats\n"; // html/links shown at bottom of pages
-ESP8266WebServer server(80);
-String derncoul;
-long r;
-long g;
-long b;
-int rouge = 0;
-int vert = 0;
-int bleu = 0;
-unsigned long previousMillis = 0;
-OneWire oneWire(ONE_WIRE_BUS);
-DallasTemperature sensors(&oneWire);
-int roulepastusuite = 0;
-Ticker tiqueFade;
-
-const String css = "\n";
-
-void fadeRGB() {
-  if (r == rouge && g == vert && b == bleu) {
-    tiqueFade.detach();
-//    Serial.println("Stopping");
-  }
-  for (int i = 0; i <= 2; i++) {
-    int couleur;
-    int tc;
-    int pinouche;
-    switch (i) {
-      case 0:
-        pinouche = pinRouge;
-        tc = r;
-        couleur = rouge;
-        break;
-      case 1:
-        pinouche = pinVerte;
-        tc = g;
-        couleur = vert;
-        break;
-      case 2:
-        pinouche = pinBleu;
-        tc = b;
-        couleur = bleu;
-        break;
-    }
-    if (couleur < tc) {
-      couleur++;
-      analogWrite(pinouche, couleur);
-    } else if (couleur > tc) {
-      couleur--;
-      analogWrite(pinouche, couleur);
-    }
-    switch (i) {
-      case 0:
-        rouge = couleur;
-        break;
-      case 1:
-        vert = couleur;
-        break;
-      case 2:
-        bleu = couleur;
-        break;
-    }
-  }
-}
-
-void handleRoot() {
-  String addy = server.client().remoteIP().toString();
-  //  Serial.println("");
-  //  Serial.println(addy);
-  String testteu = server.arg("COULEUR");
-  //  Serial.println(testteu);
-  if (testteu != 0) {
-    derncoul = testteu;
-    long number = strtol( &testteu[1], NULL, 16);
-    // Split them up into r, g, b values
-    r = number >> 16;
-    g = number >> 8 & 0xFF;
-    b = number & 0xFF;
-    if (r != rouge) {
-      //      Serial.print("Rouge = ");
-      //      Serial.println(r);
-      tiqueFade.attach_ms(40, fadeRGB);
-      dernadd = addy;
-      delay(5);
-    }
-    if (g != vert) {
-      //      Serial.print("Vert = ");
-      //      Serial.println(g);
-      tiqueFade.attach_ms(40, fadeRGB);
-      dernadd = addy;
-      delay(5);
-    }
-    if (b != bleu) {
-      //      Serial.print("Bleu = ");
-      //      Serial.println(b);
-      tiqueFade.attach_ms(40, fadeRGB);
-      dernadd = addy;
-    }
-  }
-  String contenu = "<!DOCTYPE html>\n\n\n";
-  if (server.args()) { // recharge la page / pour permetre d'appuyer refresh sans re-poster la form
-    contenu += "<meta http-equiv=\"refresh\" content=\"0;url=/\" />\n";
-  }
-  contenu += "<meta charset=\"UTF-8\" />\n<title>Que la lumiere soit</title>\n"
-             "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n";
-  contenu += css;
-  contenu += "\n\n"
-             "
\n"
-             "<form action=\"/\" method=\"post\">\n"
-             "
Change la couleur de mon bureau:
"
-             "<input type=\"color\" name=\"COULEUR\" value=\"" + derncoul + "\">
\n"
-             "<input type=\"submit\" class=\"button1\" value=\"Changer\">\n"
-             "</form>\n
Dernier IP à avoir changé la couleur : ";
-  contenu += dernadd;
-  contenu += "
\n";
-  contenu += liens;
-  contenu += "
\n";
-  server.send(200, "text/html", contenu);
-}
-
-void handleReset() {
-  int ouireset = 0;
-  String addy = server.client().remoteIP().toString();
-  //  Serial.println("");
-  //  Serial.println(addy);
-  //  Serial.println("!!! RESET PAGE !!!");
-  String testteu = server.arg("RESET");
-  String passme = server.arg("PASSME");
-  if (testteu == "OUI") {
-    if (passme == resetpass) {
-      ouireset = 1;
-    } else {
-      ouireset = 2;
-    }
-  }
-  String contenu = "<!DOCTYPE html>\n\n\n";
-  contenu += "<meta charset=\"UTF-8\" />\n<title>Que la lumiere se RESET</title>\n"
-             "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n";
-  contenu += css;
-  contenu += "\n\n"
-             "
\n";
-  if (!ouireset) {
-    contenu += "<form action=\"/reset\" method=\"post\">\n"
-               "
Tu veux resetter le wifi network pour reconfigurer ?
"
-               "<input type=\"hidden\" name=\"RESET\" value=\"OUI\">
\n"
-               "<input type=\"password\" name=\"PASSME\" value=\"password\">
\n"
-               "<input type=\"submit\" class=\"button1\" value=\"Reset Wifi Network\">\n"
-               "</form>\n";
-  } else if (ouireset != 1) {
-    contenu += "<form action=\"/reset\" method=\"post\">\n"
-               "
Tu veux resetter le wifi network pour reconfigurer ?
"
-               "<input type=\"hidden\" name=\"RESET\" value=\"OUI\">
\n"
-               "<input type=\"password\" name=\"PASSME\" value=\"password\">
\n"
-               "
!!! MAUVAIS PASSWORD !!!

\n"
-               "<input type=\"submit\" class=\"button1\" value=\"Reset Wifi Network\">\n"
-               "</form>\n";
-    //    Serial.print("BAD PASSWORD : ");
-    //    Serial.println(passme);
-  } else if (ouireset == 1) {
-    contenu += "
Reset Dans 10 Secondes
\n";
-  }
-  contenu += "
Dernier IP à avoir changé la couleur :";
-  contenu += dernadd;
-  contenu += "\n
";
-  contenu += liens;
-  contenu += "\n

\n";
-  server.send(200, "text/html", contenu);
-  if (ouireset == 1) {
-    //    Serial.println("Reset dans 10 secondes");
-    delay(10000);
-    WiFiManager wifiManager;
-    wifiManager.resetSettings();
-    ESP.restart();
-  }
-}
-
-void handleNotFound() {
-  String addy = server.client().remoteIP().toString();
-  //  Serial.println("");
-  //  Serial.println(addy);
-  String htmlmessage = "<!DOCTYPE html>\n\n\n";
-  htmlmessage += "<meta charset=\"UTF-8\" />\n<title>404 Not found</title>\n"
-                 "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n";
-  htmlmessage += css;
-  htmlmessage += "\n\n"
-                 "
\n";
-  htmlmessage += "
404 File Not Found

\n";
-  htmlmessage += "URI: ";
-  htmlmessage += server.uri();
-  htmlmessage += "
\nMethod: ";
-  htmlmessage += (server.method() == HTTP_GET) ? "GET" : "POST";
-  htmlmessage += "
\nArguments: ";
-  htmlmessage += server.args();
-  htmlmessage += "
\n";
-  for (uint8_t i = 0; i < server.args(); i++) {
-    htmlmessage += " " + server.argName(i) + ": " + server.arg(i) + "
\n";
-  }
-  htmlmessage += "
\n";
-  htmlmessage += liens;
-  htmlmessage += "
\n
\n";
-  server.send(404, "text/html", htmlmessage);
-  String message = "404 File Not Found\n";
-  message += "URI: ";
-  message += server.uri();
-  message += "\nMethod: ";
-  message += (server.method() == HTTP_GET) ? "GET" : "POST";
-  message += "\nArguments: ";
-  message += server.args();
-  message += "\n";
-  for (uint8_t i = 0; i < server.args(); i++) {
-    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
-  }
-  //  Serial.print(message);
-}
-
-void updateTemp(String tempe) {
-  if (tempe != "-127.00") {
-    //    Serial.print("Sending temp : ");
-    //    Serial.println(tempe);
-    HTTPClient http;
-    String webadd = "http://api.thingspeak.com/update?key=";
-    webadd += thingkey;
-    webadd += "&field1=";
-    webadd += tempe;
-    http.begin(webadd);
-    int httpCode = http.GET();//Send the request
-    if (httpCode > 0) { //Check the returning code
-      String payload = http.getString();   //Get the request response payload
-      //      Serial.println(payload);                     //Print the response payload
-    }
-    http.end();   //Close connection
-  }
-}
-
-void latemp() {
-  sensors.requestTemperatures();
-  float thetemp = sensors.getTempCByIndex(0);// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
-  char buffer[10];
-  String tempF = dtostrf(thetemp, 5, 2, buffer);
-  updateTemp(tempF);
-}
-
-void handleTemp() {
-  sensors.requestTemperatures();
-  float latemp = sensors.getTempCByIndex(0);
-  while (latemp == -127.00) {
-    sensors.requestTemperatures();
-    latemp = sensors.getTempCByIndex(0);
-  }
-  String addy = server.client().remoteIP().toString();
-  //  Serial.println("");
-  //  Serial.println(addy);
-  //  Serial.print("Temperature : ");
-  //  Serial.println(latemp);
-  String contenu = "<!DOCTYPE html>\n\n\n";
-  contenu += "<meta charset=\"UTF-8\" />\n<title>Quel chaleur</title>\n"
-             "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n";
-  contenu += css;
-  contenu += "\n\n"
-             "
\n";
-  contenu += "<form action=\"/\" method=\"get\">\n"
-             "
Voici la temperature
"
-             "
";
-  contenu += latemp;
-  contenu += "°C

\n<input type=\"submit\" class=\"button1\" value=\"Go Home\">\n"
-             "</form>\n"
-             "
Dernier IP à avoir changé la couleur :";
-  contenu += dernadd;
-  contenu += "\n
";
-  contenu += liens;
-  contenu += "\n

\n";
-  server.send(200, "text/html", contenu);
-}
-
-void setup() {
-  analogWriteRange(255);
-  //  analogWriteFreq(500);
-  //  Serial.begin(9600);
-  pinMode(pinRouge, OUTPUT);
-  pinMode(pinVerte, OUTPUT);
-  pinMode(pinBleu, OUTPUT);
-  digitalWrite(pinRouge, LOW);
-  digitalWrite(pinBleu, LOW);
-  digitalWrite(pinVerte, LOW);
-  WiFiManager wifiManager;
-  wifiManager.autoConnect();
-  delay(500);
-  if (!MDNS.begin("esp8266")) {
-    //Serial.println("Error setting up MDNS responder!");
-    while (1) {
-      delay(1000);
-    }
-  }
-  server.on("/", handleRoot);
-  server.on("/reset", handleReset);
-  server.on("/temp", handleTemp);
-  server.on("/version", []() {
-    String addy = server.client().remoteIP().toString();
-    //Serial.println("");
-    //Serial.println(addy);
-    //Serial.println("Version request");
-    server.send(200, "text/html", "V1.7, Steve Olmstead sansillusion@gmail.com\n\n

"
-                "Added fader function\nRemoved connection watchdog (better have good signal)\n
"
-                "Removed mDns (did not work anyway)\n\n

"
-                "Added smoother fading\n\n

"
-                "Added AutoConect WifiManager !\n\n

"
-                "Added basic last IP logging\n
"
-                "Added /reset page to reset wifiManager connection settings\n\n

"
-                "Added /temp (temperature sensor read of ky-001)\n\n

"
-                "Added thingspeak support to send temperature each minute
\n\n
"
-                "Major rewrite for RGB led trip usin mosfet
\n"
-                "Removed serial to free resources for software pwm (still flikers but less than before)
\n" + liens);
-  });
-  server.onNotFound(handleNotFound);
-  server.begin();
-  //Serial.println("HTTP server started");
-  MDNS.addService("http", "tcp", 80);
-  sensors.begin();
-}
-
-void loop() {
-  server.handleClient();
-  unsigned long currentMillis = millis();
-  if (currentMillis - previousMillis >= interval) {
-    previousMillis = currentMillis;
-    latemp();
-  }
-}
-


Delete RGB_Sensor.ino

Delete RGB_Sensor.ino

--- RGB_Sensor.ino
+++ RGB_Sensor.ino
@@ -1,68 +0,0 @@
-#include <Wire.h>
-#include "Adafruit_TCS34725.h"
-
-Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X);
-
-struct Features {
-  bool lt_10in;
-  uint16_t red;
-  uint16_t green;
-  uint16_t blue;
-};
-
-Features Feature_Extraction() {
-  Features features;
-  //Need a fourth value for getRawData()
-  uint16_t hold;
-
-  tcs.getRawData(&features.red, &features.green, &features.blue, &hold);
-
-  //Delete later, use for testing
-  Serial.print("R: "); Serial.print(features.red, DEC); Serial.print(" ");
-  Serial.print("G: "); Serial.print(features.green, DEC); Serial.print(" ");
-  Serial.print("B: "); Serial.print(features.blue, DEC); Serial.print(" ");
-  Serial.println(" ");
-
-  return features;
-}
-
-String Pattern_Recognition(Features features) {
-  String fruit;
-
-  //FIXME: k nearest neighbor algorithm
-
-  return fruit;
-}
-
-void Actuation(String box_size) {
-
-}
-
-void setup() {
-
-  Serial.begin(9600);
-
-  if(tcs.begin()) {
-    Serial.println("Found sensor");
-  }
-  else {
-    Serial.println("No TCS34725 found ... check your connections");
-    while (1);
-  }
-}
-
-void loop() {
-
-  //Should put feature extraction and pattern recognition in one multi-second for loop to
-    //give the box time to go through the sensors.
-  Features feature_states;
-  feature_states = Feature_Extraction();
-
-  String fruit;
-  fruit = Pattern_Recognition(feature_states);
-
-  Actuation(fruit);
-
-  delay(1000);
-
-}


Tweaked demo

Tweaked demo

--- Synthduino.ino
+++ Synthduino.ino
@@ -33,7 +33,7 @@

 #define TEMPO 120   // Tempo in bpm
 #define BASS 12  		// Bass will be output on pin 12
-#define MELODY 12
+#define MELODY 13

 Note bassLine[] = { {NOTE_C3, 2}, {NOTE_DS3, 2}, {NOTE_F3, 1} }; // The actual bass part
 Note melody[] = { {NOTE_E4,4}, {NOTE_D4,4}, {NOTE_C4,4}, {NOTE_D4,4}, {NOTE_E4,4}, {NOTE_E4,4}, {NOTE_E4,4} };
@@ -47,7 +47,8 @@
 }

 void loop() {
-  for(int i=0; i<3; i++){
+  for(int i=0; i<MELODY_LENGTH; i++){
     melody[i].play(MELODY);
   }
+  delay(5000);
 }


fixed drawFrame error

fixed drawFrame error

order of drawFrame functions to fix compile error

--- Huzzah-Weather-Display/Huzzah-Weather-Display.ino
+++ Huzzah-Weather-Display/Huzzah-Weather-Display.ino
@@ -54,6 +54,34 @@
 SSD1306 display(I2C, SDA, SCL);
 WeatherClient weather;
 Ticker ticker;
+
+void drawFrame1(int x, int y) {
+  display.setFontScale2x2(false);
+  display.drawString(65 + x, 8 + y, "Now");
+  display.drawXbm(x + 7, y + 7, 50, 50, getIconFromString(weather.getCurrentIcon()));
+  display.setFontScale2x2(true);
+  display.drawString(64 + x, 20 + y, String(weather.getCurrentTemp()) + "F");
+  display.setFontScale2x2(false);
+  display.drawString(64 + x, 40 + y, String(weather.getCurrentSummary()));
+}
+
+void drawFrame2(int x, int y) {
+  display.setFontScale2x2(false);
+  display.drawString(65 + x, 0 + y, "Today");
+  display.drawXbm(x, y, 60, 60, xbmtemp);
+  display.setFontScale2x2(true);
+  display.drawString(64 + x, 14 + y, String(weather.getCurrentTemp()) + "F");
+  display.setFontScale2x2(false);
+  display.drawString(66 + x, 40 + y, String(weather.getMinTempToday()) + "F/" + String(weather.getMaxTempToday()) + "F");
+}
+
+void drawFrame3(int x, int y) {
+  display.drawXbm(x + 7, y + 7, 50, 50, getIconFromString(weather.getIconTomorrow()));
+  display.setFontScale2x2(false);
+  display.drawString(65 + x, 7 + y, "Tomorrow");
+  display.setFontScale2x2(true);
+  display.drawString(64 + x, 20 + y, String(weather.getMaxTempTomorrow()) + "F");
+}

 // this array keeps function pointers to all frames
 // frames are the single views that slide from right to left
@@ -179,34 +207,6 @@
   return cloudy_bits;
 }

-void drawFrame1(int x, int y) {
-  display.setFontScale2x2(false);
-  display.drawString(65 + x, 8 + y, "Now");
-  display.drawXbm(x + 7, y + 7, 50, 50, getIconFromString(weather.getCurrentIcon()));
-  display.setFontScale2x2(true);
-  display.drawString(64 + x, 20 + y, String(weather.getCurrentTemp()) + "F");
-  display.setFontScale2x2(false);
-  display.drawString(64 + x, 40 + y, String(weather.getCurrentSummary()));
-}
-
-void drawFrame2(int x, int y) {
-  display.setFontScale2x2(false);
-  display.drawString(65 + x, 0 + y, "Today");
-  display.drawXbm(x, y, 60, 60, xbmtemp);
-  display.setFontScale2x2(true);
-  display.drawString(64 + x, 14 + y, String(weather.getCurrentTemp()) + "F");
-  display.setFontScale2x2(false);
-  display.drawString(66 + x, 40 + y, String(weather.getMinTempToday()) + "F/" + String(weather.getMaxTempToday()) + "F");
-}
-
-void drawFrame3(int x, int y) {
-  display.drawXbm(x + 7, y + 7, 50, 50, getIconFromString(weather.getIconTomorrow()));
-  display.setFontScale2x2(false);
-  display.drawString(65 + x, 7 + y, "Tomorrow");
-  display.setFontScale2x2(true);
-  display.drawString(64 + x, 20 + y, String(weather.getMaxTempTomorrow()) + "F");
-}
-
 void drawSpinner(int count, int active) {
   for (int i = 0; i < count; i++) {
     const char *xbm;


wip: dummy tx included; is compiling

wip: dummy tx included; is compiling

--- TreibBoje1.ino
+++ TreibBoje1.ino
@@ -1,7 +1,7 @@
 //
 // File   : TreibBoje1.ino
 //
-// Purpose: Frame for experimental 'Treibbojen' project
+// Purpose: Frame for fun project 'Treibbojen' (experimental)
 //
 // $Id$
 //
@@ -22,6 +22,10 @@
  #include <Flash.h>
 #endif // DEBUG

+#ifdef SEND_DATA
+ #include <RCSwitch.h>
+#endif // SEND_DATA
+
 // http://www.pjrc.com/teensy/td_libs_OneWire.html
 #include <OneWire.h>

@@ -39,6 +43,13 @@
 //              GND Dq  Vdd
 //
 #include <DallasTemperature.h>
+
+#ifdef SEND_DATA
+
+#define TX_PIN     10
+RCSwitch theSender = RCSwitch();
+
+#endif // SEND_DATA

 // UART baud rate
 #define UART_BAUD_RATE  9600
@@ -83,6 +94,17 @@
   // Start up the library
   sensors.begin();

+#ifdef SEND_DATA
+  // Transmitter is connected to Arduino Pin #10 (TX_PIN)
+  theSender.enableTransmit(TX_PIN);
+
+  // Optional set pulse length.
+  theSender.setPulseLength(200);
+
+  // Optional set protocol (default is 1, will work for most outlets)
+  //theSender.setProtocol(1);  // -> setPulseLength(350); '0' = 1,3
+#endif // SEND_DATA
+
 #ifdef SCAN_SENSORS
   // locate devices on the bus
   Serial.print(F("Locating devices..."));
@@ -118,16 +140,16 @@
 #endif // SCAN_SENSORS
 }

-int getRawTemperature(float temp) {
-  switch (TEMPERATURE_PRECISION) {
+int getRawTemperature(float temp,int precision=12) {
+  switch (precision) {
     case 12:
-      return (int)(temp / 0.0625);
+      return ((int)(temp / 0.0625)) & 0x0fff;
     case 11:
-      return (int)(temp / 0.125);
+      return ((int)(temp / 0.125)) & 0x07ff;
     case 10:
-      return (int)(temp / 0.25);
+      return ((int)(temp / 0.25)) & 0x03ff;
     case 9:
-      return (int)(temp / 0.5);
+      return ((int)(temp / 0.5)) & 0x01ff;
   }

   return 0;
@@ -137,6 +159,12 @@
  * Main loop
  */
 void loop() {
+
+#ifdef SEND_DATA
+  // send dumy telegram
+  theSender.send(0, 12);
+  theSender.send(4095, 12);
+#endif // SEND_DATA

 #ifdef READ_SENSORS
   if ( sensors.getDeviceCount() > 0 ) {
@@ -150,23 +178,28 @@
     // alternative printout, only known sensors correctly prefixed
     if ( sensors.isConnected( gSensor1 ) ) {
       temp = sensors.getTempC( gSensor1 );
-      Serial << "T1: " << temp << " " << getRawTemperature(temp);
+      Serial << "T1: " << temp << " "
+             << getRawTemperature(temp, TEMPERATURE_PRECISION);
     }
     if ( sensors.isConnected( gSensor2 ) ) {
       temp = sensors.getTempC( gSensor2 );
-      Serial << "T2: " << temp << " " << getRawTemperature(temp);
+      Serial << "T2: " << temp << " "
+             << getRawTemperature(temp, TEMPERATURE_PRECISION);
     }
     if ( sensors.isConnected( gSensor3 ) ) {
       temp = sensors.getTempC( gSensor3 );
-      Serial << "T3: " << temp << " " << getRawTemperature(temp);
+      Serial << "T3: " << temp << " "
+             << getRawTemperature(temp, TEMPERATURE_PRECISION);
     }
     if ( sensors.isConnected( gSensor4 ) ) {
       temp = sensors.getTempC( gSensor4 );
-      Serial << "T4: " << temp << " " << getRawTemperature(temp);
+      Serial << "T4: " << temp << " "
+             << getRawTemperature(temp, TEMPERATURE_PRECISION);
     }
     if ( sensors.isConnected( gSensor5 ) ) {
       temp = sensors.getTempC( gSensor5 );
-      Serial << "T5: " << temp << " " << getRawTemperature(temp);
+      Serial << "T5: " << temp << " "
+             << getRawTemperature(temp, TEMPERATURE_PRECISION);
     }
     Serial.println();
 #endif // DEBUG
@@ -208,4 +241,4 @@
   Serial.println();
 }

-
+


disable wifi on default

disable wifi on default

--- DiscoJar/DiscoJar.ino
+++ DiscoJar/DiscoJar.ino
@@ -1,5 +1,5 @@
 // If you want to control the DiscoJar via WIFI using an ESP8266, uncomment this:
-#define USE_WIFI
+//#define USE_WIFI

 /*
 This is the code for the instructable DiscoJar, done by Florian Link (at) gmx.de
@@ -38,9 +38,7 @@
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

-#ifdef USE_WIFI
 #include "WIFIControl.h"
-#endif

 //----- Global state -----------------------------------------------------------------------
 State _myState;
@@ -269,6 +267,9 @@

 #ifdef USE_WIFI
   setupWebServer();
+#else
+  // show rainbow for three seconds
+  delay(3000);
 #endif
 }


first shot at a api for a lego nxt motor

--- prototype/prototype-3/prototype-3.ino
+++ prototype/prototype-3/prototype-3.ino
@@ -1,33 +1,79 @@
-void setup() {
+enum Turning_Direction {
+  CLOCKWISE        = -1,
+  COUNTERCLOCKWISE = 1
+};
+
+struct Motor {
+  int pin = 0;
+  volatile int deg = 0;
+  Turning_Direction dir = CLOCKWISE;
+};
+
+Motor motor1;
+
+void setup() {
+  motor1.pin = 12;
+
   // put your setup code here, to run once:
   Serial.begin(9200);

   pinMode(2, INPUT);
-
   pinMode(3, INPUT);
+  pinMode(18, INPUT);

-  pinMode(12, OUTPUT);
+  pinMode(motor1.pin, OUTPUT);

-  attachInterrupt(0, int2, CHANGE); // 0 is interrupt number, listens at pin 2
-  attachInterrupt(1, int3, CHANGE); // 1 is interrupt number, listens at pin 3
+  //attachInterrupt(digitalPinToInterrupt(2), int2, CHANGE); // 0 is interrupt number, listens at pin 2
+  attachInterrupt(digitalPinToInterrupt(3), motor1_interrupt, CHANGE); // 1 is interrupt number, listens at pin 3
+  //attachInterrupt(digitalPinToInterrupt(18), button_clicked, CHANGE);

-  digitalWrite(12, HIGH);
+  //motor_turn(&motor1, CLOCKWISE);
+  //motor_stop(&motor1);
+  motor_turn_deg(&motor1, 360, CLOCKWISE);
 }

-int count = 0;
+void button_clicked() {
+  Serial.println("I was clicked!");
+  motor_stop(&motor1);
+}
+
 void int2() {
   // Serial.println("Int2");
 }

-void int3() {
-  count++;
-  if (count == 360) {
-    count = 0;
-    digitalWrite(12, LOW);
+void motor1_interrupt() {
+  motor1.deg += motor1.dir;
+}
+
+void motor_turn_deg(Motor* motor, int deg, Turning_Direction dir)
+{
+  int goal = motor->deg + (deg * dir);
+
+  motor_turn(motor, dir);
+
+  switch (motor->dir) {
+    case CLOCKWISE:
+      while (goal <= motor->deg) ;
+      break;
+    case COUNTERCLOCKWISE:
+      while (goal >= motor->deg) ;
+      break;
   }
+
+  motor_stop(motor);
+}
+
+void motor_stop(Motor* motor)
+{
+  digitalWrite(motor->pin, LOW);
+}
+
+void motor_turn(Motor* motor, Turning_Direction dir)
+{
+  motor->dir = dir;
+  digitalWrite(motor->pin, HIGH);
 }

 void loop() {
   // put your main code here, to run repeatedly:
-  Serial.println(count);
 }


Tweak RGB calibrate types

Tweak RGB calibrate types

--- firmware/examples/RGBCalibrate/RGBCalibrate.ino
+++ firmware/examples/RGBCalibrate/RGBCalibrate.ino
@@ -38,25 +38,25 @@
    	delay(2000);

       // Uncomment one of the following lines for your leds arrangement.
-      // FastLED.addLeds<TM1803, DATA_PIN, RGB>(leds, NUM_LEDS);
-      // FastLED.addLeds<TM1804, DATA_PIN, RGB>(leds, NUM_LEDS);
-      // FastLED.addLeds<TM1809, DATA_PIN, RGB>(leds, NUM_LEDS);
-      // FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
-      // FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
+      // FastLED.addLeds<TM1803, DATA_PIN, NSFastLED::RGB>(leds, NUM_LEDS);
+      // FastLED.addLeds<TM1804, DATA_PIN, NSFastLED::RGB>(leds, NUM_LEDS);
+      // FastLED.addLeds<TM1809, DATA_PIN, NSFastLED::RGB>(leds, NUM_LEDS);
+      // FastLED.addLeds<WS2811, DATA_PIN, NSFastLED::RGB>(leds, NUM_LEDS);
+      // FastLED.addLeds<WS2812, DATA_PIN, NSFastLED::RGB>(leds, NUM_LEDS);
       // FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
       // FastLED.setBrightness(CRGB(255,255,255));
-      // FastLED.addLeds<GW6205, DATA_PIN, RGB>(leds, NUM_LEDS);
-      // FastLED.addLeds<GW6205_400, DATA_PIN, RGB>(leds, NUM_LEDS);
-      // FastLED.addLeds<UCS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
-      // FastLED.addLeds<UCS1903B, DATA_PIN, RGB>(leds, NUM_LEDS);
+      // FastLED.addLeds<GW6205, DATA_PIN, NSFastLED::RGB>(leds, NUM_LEDS);
+      // FastLED.addLeds<GW6205_400, DATA_PIN, NSFastLED::RGB>(leds, NUM_LEDS);
+      // FastLED.addLeds<UCS1903, DATA_PIN, NSFastLED::RGB>(leds, NUM_LEDS);
+      // FastLED.addLeds<UCS1903B, DATA_PIN, NSFastLED::RGB>(leds, NUM_LEDS);

-      // FastLED.addLeds<WS2801, RGB>(leds, NUM_LEDS);
-      // FastLED.addLeds<SM16716, RGB>(leds, NUM_LEDS);
-      FastLED.addLeds<LPD8806, 9, 10, RGB>(leds, NUM_LEDS);
+      // FastLED.addLeds<WS2801, NSFastLED::RGB>(leds, NUM_LEDS);
+      // FastLED.addLeds<SM16716, NSFastLED::RGB>(leds, NUM_LEDS);
+      FastLED.addLeds<LPD8806, 9, 10, NSFastLED::RGB>(leds, NUM_LEDS);

-      // FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
-      // FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
-      // FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
+      // FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, NSFastLED::RGB>(leds, NUM_LEDS);
+      // FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, NSFastLED::RGB>(leds, NUM_LEDS);
+      // FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, NSFastLED::RGB>(leds, NUM_LEDS);
 }

 void loop() {
@@ -66,9 +66,7 @@
    leds[3] = CRGB(0,0,255);
    leds[4] = CRGB(0,0,255);
    leds[5] = CRGB(0,0,255);
-   leds[random8()%NUM_LEDS] = CRGB(0,0,0);
    // leds[10] = CRGB(0,0,0);
    FastLED.show();
-   // delay(1000);
-   FastLED.showColor(CRGB::Black);
+   delay(1000);
 }


Fixed forgotten OLED_ADDRESS.

Fixed forgotten OLED_ADDRESS.

--- aquacontrol32.ino
+++ aquacontrol32.ino
@@ -153,7 +153,7 @@

 OneWire  ds( ONEWIRE_PIN );  /* a 4.7K pull-up resistor is necessary */

-SSD1306  OLED( 0x3c, I2C_SDA_PIN, I2C_SCL_PIN );
+SSD1306  OLED( OLED_ADDRESS, I2C_SDA_PIN, I2C_SCL_PIN );

 AsyncWebServer server(80);


Show output on displays on FFat errors.

Show output on displays on FFat errors.

--- aquacontrol32.ino
+++ aquacontrol32.ino
@@ -363,9 +363,17 @@
     }
     ESP_LOGI( TAG, "%s", formatStr );
     FFat.format( true, (char*)"ffat" );
-    if (!FFat.begin()) {
-      ESP_LOGI( TAG, "FFat not mounted after formatting. Halting." );
-      while (true) delay(1000); /* system is halted */;
+    if (!FFat.format( true, (char*)"ffat" ) || !FFat.begin()) {
+      ESP_LOGI( TAG, "FFat error while formatting. Halting." );
+      const char * errorffatStr = "FFat error.";
+      if ( xTftTaskHandle ) {
+        tft.println( errorffatStr );
+      }
+      if ( xOledTaskHandle ) {
+        OLED.drawString( 64, 20, errorffatStr );
+        OLED.display();
+      }
+    while (true) delay(1000); /* system is halted */;
     }
   }


Add support for Throttle position and clutch lever position.


Added response messages to commands for positive ACKs

--- MagnusCoreNeoPixel_v1.ino
+++ MagnusCoreNeoPixel_v1.ino
@@ -115,16 +115,19 @@
     case 'e':
       owner = enlightened;
       percent = getPercent(&command[1]);
+      Serial.println("OK");
       break;
     case 'R':
     case 'r':
       owner = resistance;
       percent = getPercent(&command[1]);
+      Serial.println("OK");
       break;
     case 'n':
     case 'N':
       owner = neutral;
       percent = 100;
+      Serial.println("OK");
       break;
     default:
     Serial.println("?");


irrecv.disableIRIn

irrecv.disableIRIn


Added Serial.flush()
Refresh status after subscribe
byte instead of unsigned int
removed "arduino ready" output on boot

Signed-off-by: Suxsem <ffd6300eb7bdb77a8898cee133390f47c44c6773@live.com>

--- Domo.ino
+++ Domo.ino
@@ -36,17 +36,18 @@
 dht DHT;
 SimpleTimer timer;

-unsigned int touchCount = 0;
+byte touchCount = 0;
 boolean alarmOn = false;
 boolean alarmScattato = false;
 boolean alarmInserito = false;
 volatile boolean rumoreRilevato = false;
 boolean movimentoRilevato = false;
 boolean connected = false;
-unsigned int skip = 0;
+byte skip = 0;
 unsigned long epoch = 0;
 unsigned long lastEpoch = 0;
 unsigned int lastPhoto;
+char lastLed[7] = "000000";

 // #################### esp8266 ####################

@@ -76,6 +77,8 @@
   mqttSubscribe(String(MQTTid) + "/Led/c");
   mqttSubscribe(String(MQTTid) + "/Allarme/c");
   mqttSubscribe("time");
+  mqttPublish(String(MQTTid) + "/Allarme", String(alarmOn), 1);
+  mqttPublish(String(MQTTid) + "/Led", lastLed, 1);
 }

 void onDisconnected() {
@@ -106,15 +109,18 @@
                 onDisconnected();
             }
             lastAliveCheck = millis();
-            Serial.println("startAlive(" + String(esp8266alive) + ")");
+            Serial.println("startAlive(" + String(esp8266alive) + ")");
+            Serial.flush();
             Serial.println("connectAP(\"" + String(APssid) + "\", \"" + String(APpsw) + "\")");
+            Serial.flush();
         } else if (cb[0] == 'a') {
             lastAliveCheck = millis();
             checkComm();
         } else if (cb[0] == 'w') {
             //wifi connected
             Serial.println("mqttInit(\"" + String(MQTTid) + "\", \"" + String(MQTTip) + "\", " + MQTTport + ", \"" + String(MQTTuser)
-                            + "\", \"" + String(MQTTpsw) + "\", " + MQTTalive + ", " + MQTTretry + ")");
+                            + "\", \"" + String(MQTTpsw) + "\", " + MQTTalive + ", " + MQTTretry + ")");
+            Serial.flush();
         } else if (cb[0] == 'c') {
             //mqtt connected
             connected = true;
@@ -152,11 +158,12 @@
         checkComm();
     }
 }
-void mqttPublish(String topic, String message, unsigned int retain) {
+void mqttPublish(String topic, String message, byte retain) {
     if (!connected)
         return;
     success = false;
     Serial.println("mqttPublish(\"" + topic + "\", \"" + message + "\",  " + MQTTqos + ", " + retain + ")");
+    Serial.flush();
     waitForSuccess();
 }
 void mqttSubscribe(String topic) {
@@ -164,6 +171,7 @@
         return;
     success = false;
     Serial.println("mqttSubscribe(\"" + String(topic) + "\", " + MQTTqos + ")");
+    Serial.flush();
     waitForSuccess();
 }

@@ -202,7 +210,7 @@

 #define R 31.8975139158 //https://diarmuid.ie/blog/post/pwm-exponential-led-fading-on-arduino-or-other-platforms
 void setLed(String mRgb) {
-  // Convert it to long
+  // Convert it to long
   long number = strtol(&mRgb[0], NULL, 16);
   // Split them up into r, g, b values
   int r = number >> 16;
@@ -211,6 +219,7 @@
   analogWrite(rgbrPin, pow (2, (r / R)) - 1);
   analogWrite(rgbgPin, pow (2, (g / R)) - 1);
   analogWrite(rgbbPin, pow (2, (b / R)) - 1);
+  mRgb.toCharArray(lastLed, 7);
 }

 void faiBeep(unsigned int millis) {
@@ -234,14 +243,10 @@

 void setup() {
   Serial.begin(9600);
-  Serial.println("print(\"arduino ready\")");
   Serial.setTimeout(500);

   while(!connected)
-    checkComm();
-
-  mqttPublish(String(MQTTid) + "/Led", "000000", 1);
-  mqttPublish(String(MQTTid) + "/Allarme", "0", 1);
+    checkComm();

   pinMode(buzzPin, OUTPUT);
   pinMode(statusPin, OUTPUT);


Made scrolling smoother (Scott's suggestion)

--- examples/DrawSprites/DrawSprites.ino
+++ examples/DrawSprites/DrawSprites.ino
@@ -9,7 +9,8 @@

 // Number of 8x8 segments you are connecting
 const int LEDMATRIX_SEGMENTS = 4;
-const int LEDMATRIX_WIDTH    = LEDMATRIX_SEGMENTS * 8;
+const int SEGMENT_WIDTH = 8;
+const int LEDMATRIX_WIDTH    = LEDMATRIX_SEGMENTS * SEGMENT_WIDTH;

 // The LEDMatrixDriver class instance
 LEDMatrixDriver lmd(LEDMATRIX_SEGMENTS, LEDMATRIX_CS_PIN);
@@ -17,11 +18,12 @@
 void setup() {
   // init the display
   lmd.setEnabled(true);
-  lmd.setIntensity(2);   // 0 = low, 10 = high
+  lmd.setIntensity(2);   // 0 = low, 15 = high
 }

-int x=-1, y=0;   // start top left
-bool s = true;  // start with led on
+int x = -SEGMENT_WIDTH; // start off to the left
+int y = 0;              // start top left
+bool s = true;          // start with led on

 byte a[8]={ B00011000,
             B00100100,
@@ -112,7 +114,7 @@
   delay(ANIM_DELAY);

   if( x > LEDMATRIX_WIDTH )
-    x= -1;
+    x = -SEGMENT_WIDTH;
 }

 void drawSprite( byte* sprite, int x, int y, int width, int height )


fixes a typo

fixes a typo

--- tactA_single/tactA_single.ino
+++ tactA_single/tactA_single.ino
@@ -145,7 +145,7 @@
           sendInt(bias);
           break;

-        case STATE_TRASMIT_BIAS_PEAK:
+        case STATE_TRANSMIT_BIAS_PEAK:
           // send data_type for data to be transmitted
           sendInt( 1088 + 3 );
           // Tell client how many data values are going to be sent


Send a response after the Arduino has completed its work.

--- Watering/Watering.ino
+++ Watering/Watering.ino
@@ -16,6 +16,8 @@
   if ( Serial.available() ) {

     byte command = Serial.read();
+    byte output[4];
+    byte numBytes = 0;

     switch( command ) {

@@ -25,13 +27,27 @@
           break;
       case RELAY_ON:
           digitalWrite(LED_PIN, HIGH);
+
+          // Prepping to send a response
+          output[0] = command;
+          output[1] = 0;
+          numBytes = 2;
           break;
       case RELAY_OFF:
           digitalWrite(LED_PIN, LOW);
+
+          // Prepping to send a response
+          output[0] = command;
+          output[1] = 0;
+          numBytes = 2;
           break;
       default:
           break;

     }
+
+    //Sending a response after the command has completed
+    Serial.write(output, numBytes);
+
   }
 }


Change sodaq binary example to use new txBytes function.

--- examples/TTN-Mapper-SodaqOne-binary/TTN-Mapper-SodaqOne-binary.ino
+++ examples/TTN-Mapper-SodaqOne-binary/TTN-Mapper-SodaqOne-binary.ino
@@ -152,7 +152,7 @@

   SerialUSB.println(toLog);
   digitalWrite(LED_BLUE, LOW);
-  myLora.txData(toLog, false); //already encoded data
+  myLora.txBytes(txBuffer, sizeof(txBuffer)); //already encoded data
   digitalWrite(LED_BLUE, HIGH);
   SerialUSB.println("TX done");
 }


Modifying WeatherStationDemoExtended to work on ESP32

--- examples/WeatherStationDemoExtended/WeatherStationDemoExtended.ino
+++ examples/WeatherStationDemoExtended/WeatherStationDemoExtended.ino
@@ -23,11 +23,17 @@
 See more at http://blog.squix.org
 */

-#include <ESP8266WiFi.h>
+#include <ESPWiFi.h>
+#if defined(ESP8266)
 #include <Ticker.h>
+#endif
 #include <JsonListener.h>
 #include <ArduinoOTA.h>
+#if defined(ESP8266)
 #include <ESP8266mDNS.h>
+#else
+#include <ESPmDNS.h>
+#endif

 #include <DNSServer.h>
 #include <ESP8266WebServer.h>
@@ -57,8 +63,13 @@

 // Display Settings
 const int I2C_DISPLAY_ADDRESS = 0x3c;
-const int SDA_PIN = 0;
-const int SDC_PIN = 2;
+#if defined(ESP8266)
+const int SDA_PIN = D3;
+const int SDC_PIN = D4;
+#else
+const int SDA_PIN = 5; //D3;
+const int SDC_PIN = 4; //D4;
+#endif

 // TimeClient settings
 const float UTC_OFFSET = 2;
@@ -95,7 +106,11 @@

 String lastUpdate = "--";

+#if defined(ESP8266)
 Ticker ticker;
+#else
+long timeSinceLastWUpdate = 0;
+#endif

 //declaring prototypes
 void configModeCallback (WiFiManager *myWiFiManager);
@@ -121,6 +136,17 @@
 OverlayCallback overlays[] = { drawHeaderOverlay };
 int numberOfOverlays = 1;

+String ESPChipID(void) {
+#if defined(ESP8266)
+  return String(ESP.getChipId(), HEX);
+#else
+  uint64_t EspChipID = ESP.getEfuseMac();
+  char chipID[14];
+  sprintf(chipID, "%04X%08X", (uint16_t)(EspChipID >> 32), (uint32_t)EspChipID);
+  return chipID;
+
+#endif
+}
 void setup() {
     // Turn On VCC
   //pinMode(D4, OUTPUT);
@@ -150,8 +176,12 @@
   //Manual Wifi
   //WiFi.begin(WIFI_SSID, WIFI_PWD);
   String hostname(HOSTNAME);
-  hostname += String(ESP.getChipId(), HEX);
+  hostname += ESPChipID();
+#if defined(ESP8266)
   WiFi.hostname(hostname);
+#else
+  MDNS.begin((char *)&hostname);
+#endif

   int counter = 0;
@@ -195,12 +225,21 @@
   ArduinoOTA.begin();

   updateData(&display);
-
+
+#if defined(ESP8266)
   ticker.attach(UPDATE_INTERVAL_SECS, setReadyForWeatherUpdate);
+#endif

 }

 void loop() {
+
+#if !defined(ESP8266)
+  if (millis() - timeSinceLastWUpdate > (1000L*UPDATE_INTERVAL_SECS)) {
+    setReadyForWeatherUpdate();
+    timeSinceLastWUpdate = millis();
+  }
+#endif

   if (readyForWeatherUpdate && ui.getUiState()->frameState == FIXED) {
     updateData(&display);
@@ -379,3 +418,4 @@
   Serial.println("Setting readyForUpdate to true");
   readyForWeatherUpdate = true;
 }
+


10 byte savings

10 byte savings

--- arduboy-game/arduboy-game.ino
+++ arduboy-game/arduboy-game.ino
@@ -628,11 +628,13 @@
         playerY++;
       }
       if (every9Frames) {
-        playerFrame++;
-      }
-      if (playerFrame > 4) {
-        playerFrame = 4;
-      }
+        if (playerFrame < 4) {
+          playerFrame++;
+        }
+      }
+//      if (playerFrame > 4) {
+//        playerFrame = 4;
+//      }
     }

     if (arduboy.pressed(A_BUTTON)) {


Variable type changes for credits.

Variable type changes for credits.

--- arduboy-game/arduboy-game.ino
+++ arduboy-game/arduboy-game.ino
@@ -32,7 +32,7 @@

 Player spaceShip;

-void printText(char *message, int x, int y, int textSize) {
+void printText(char *message, byte x, byte y, byte textSize) {
   arduboy.setCursor(x, y);
   arduboy.setTextSize(textSize);
   arduboy.print(message);
@@ -51,6 +51,7 @@
   byte selectedItem = TITLE_PLAY_GAME;
   unsigned short totalDelay = 0;
   long lastDebounceTime = 0;  // the last time the button was pressed
+
   arduboy.clear();
   printText("TITLE", 25, 20, 2);
   arduboy.drawRect(2, 47, 26, 13, 1);
@@ -58,7 +59,6 @@
   printText("CREDITS", 32, 50, 1);
   printText("SETTINGS", 78, 50, 1);

-  // TODO DRAW RECT
   arduboy.display();

   while (totalDelay < ATTRACT_MODE_TIMEOUT) {
@@ -67,14 +67,14 @@
     }

     if (arduboy.pressed(LEFT_BUTTON)) {
-      if ( (millis() - lastDebounceTime) > DEBOUNCE_DELAY) {
+      if ((millis() - lastDebounceTime) > DEBOUNCE_DELAY) {
         selectedItem = titleMenuLeftButton(selectedItem);
         lastDebounceTime = millis(); //set the current time
       }
     }

     if (arduboy.pressed(RIGHT_BUTTON)) {
-      if ( (millis() - lastDebounceTime) > DEBOUNCE_DELAY) {
+      if ((millis() - lastDebounceTime) > DEBOUNCE_DELAY) {
         selectedItem = titleMenuRightButton(selectedItem);
         lastDebounceTime = millis(); //set the current time
       }
@@ -148,23 +148,22 @@

 void creditsScreen() {
   // TODO, this is placeholder
-  char* credits[] = {"CREDITS", "p1", "p2", "p3", "p4", "p5", "p6"};
-  int arrsize = sizeof(credits) / sizeof(int);
-  int num_pass = 10;
-  int start = 5;
-  scrollCredits(start, arrsize, credits, false);
+  const char* credits[] = {"CREDITS", "p1", "p2", "p3", "p4", "p5", "p6"};
+  unsigned short arrsize = sizeof(credits) / sizeof(int);
+  scrollCredits(5, arrsize, credits, false);
   delay(1000);
 }

-void scrollCredits(int y, int arrsize, char* credits[], bool quit) {
+void scrollCredits(int y, unsigned short arrsize, char* credits[], bool quit) {
   /**
    * Recursive function for scrolling
    * creddits up screen
    */
-  int padding = 7;
-  int textSize = 1;
-  arduboy.clear();
-  for (int i; i < arrsize; i++) {
+  byte padding = 7;
+  byte textSize = 1;
+
+  arduboy.clear();
+  for (unsigned short i = 0; i < arrsize; i++) {
     if (i == 0) {
       textSize = 2;
     } else {


[SSD1306BareBack] tidy code

[SSD1306BareBack] tidy code

--- playground/OLED/SSD1306BareBack/SSD1306BareBack.ino
+++ playground/OLED/SSD1306BareBack/SSD1306BareBack.ino
@@ -103,16 +103,6 @@
   OledWrite(cmd,HIGH);
 }

-void OledResetHorizontalAddressing() {
-  OledWriteCmd(SSD1306_ADDRESSING); OledWriteCmd(SSD1306_ADDRESSING_HORIZONTAL);
-  OledWriteCmd(SSD1306_SET_COLUMN);
-  OledWriteCmd(0);
-  OledWriteCmd(SSD1306_PIXEL_WIDTH - 1);
-  OledWriteCmd(SSD1306_SET_PAGE);
-  OledWriteCmd(0);
-  OledWriteCmd(SSD1306_PAGE_HEIGHT - 1);
-}
-
 void OledClear() {
   OledXY(0,0);
   for(int i=0; i<SSD1306_SEGMENT_COUNT; i++) OledWriteData(0x00);
@@ -159,6 +149,7 @@

   OledWriteCmd(SSD1306_ADDRESSING); OledWriteCmd(SSD1306_ADDRESSING_HORIZONTAL);

+  // setting seg and com scan reverse means our x,y origin is top left of the screen
   OledWriteCmd(SSD1306_SET_SEG_SCAN_REVERSE);
   OledWriteCmd(SSD1306_SET_COM_SCAN_REVERSE);


trimmed bp180 exmaple

trimmed bp180 exmaple

--- src/bmp180-example/bmp180-example.ino
+++ src/bmp180-example/bmp180-example.ino
@@ -17,17 +17,6 @@
     Serial.println("BMP180 init success");
   else
   {
-    // If you want sea-level-compensated pressure, as used in weather reports,
-    // you will need to know the altitude at which your measurements are taken.
-    // We're using a constant called ALTITUDE in this sketch:
-
-    Serial.println();
-    Serial.print("provided altitude: ");
-    Serial.print(ALTITUDE, 0);
-    Serial.print(" meters, ");
-    Serial.print(ALTITUDE * 3.28084, 0);
-    Serial.println(" feet");
-
     Serial.println("BMP180 init fail\n\n");
     while (1); // Pause forever.
   }
@@ -37,9 +26,6 @@
 {
   char status;
   double T, P, p0, a;
-
-  // If you want to measure altitude, and not pressure, you will instead need
-  // to provide a known baseline pressure. This is shown at the end of the sketch.

   // You must first get a temperature measurement to perform a pressure reading.

@@ -70,7 +56,7 @@
       // If request is successful, the number of ms to wait is returned.
       // If request is unsuccessful, 0 is returned.

-      status = pressure.startPressure(3);
+      status = pressure.startPressure(0);
       if (status != 0)
       {
         // Wait for the measurement to complete:


Fixes MAC to name conversion for leading 0 in address

--- src/arduino101/science-journal-arduino/science-journal-arduino.ino
+++ src/arduino101/science-journal-arduino/science-journal-arduino.ino
@@ -30,7 +30,7 @@
 BLECharacteristic valueCharacteristic( "555a0003-0aaa-467a-9538-01f0652c74e8", BLENotify, value);
 BLECharacteristic configCharacteristic("555a0010-0aaa-467a-9538-01f0652c74e8", BLEWrite, config);

-String BleLongName = "Sci";
+char BleLongName[8];
 bool serialConnected = false;
 extern PinType pin_type;
 extern int pin;
@@ -90,11 +90,10 @@
   ble_addr_t _local_bda;
   char       _device_name[BLE_MAX_DEVICE_NAME+1];
   ble_client_get_factory_config(&_local_bda, _device_name);
-  BleLongName += String(_local_bda.addr[0], HEX);
-  BleLongName += String(_local_bda.addr[1], HEX);
+  sprintf(BleLongName, "Sci%02x%02x", _local_bda.addr[0], _local_bda.addr[1]);
   DEBUG_PRINT("Address is: ");
   DEBUG_PRINTLN(BleLongName);
-  blePeripheral.setLocalName(BleLongName.c_str());
+  blePeripheral.setLocalName(BleLongName);

   // advertise the service
   blePeripheral.begin();


edited text locations

edited text locations

text locations moved, removed minTempTomorrow

--- Huzzah-Weather-Display/Huzzah-Weather-Display.ino
+++ Huzzah-Weather-Display/Huzzah-Weather-Display.ino
@@ -186,7 +186,7 @@
   display.setFontScale2x2(true);
   display.drawString(64 + x, 20 + y, String(weather.getCurrentTemp()) + "F");
   display.setFontScale2x2(false);
-  display.drawString(50 + x, 40 + y, String(weather.getCurrentSummary()));
+  display.drawString(64 + x, 40 + y, String(weather.getCurrentSummary()));
 }

 void drawFrame2(int x, int y) {
@@ -204,9 +204,7 @@
   display.setFontScale2x2(false);
   display.drawString(65 + x, 7 + y, "Tomorrow");
   display.setFontScale2x2(true);
-  display.drawString(64 + x, 20 + y, String(weather.getMaxTempTomorrow()) + "F max");
-   display.setFontScale2x2(false);
-  display.drawString(66 + x, 40 + y, String(weather.getMinTempTomorrow()) + "F min");
+  display.drawString(64 + x, 20 + y, String(weather.getMaxTempTomorrow()) + "F");
 }

 void drawSpinner(int count, int active) {


a bit less info feedback

a bit less info feedback

--- longhand_firmware_due/longhand_firmware_due.ino
+++ longhand_firmware_due/longhand_firmware_due.ino
@@ -10,7 +10,7 @@

  LONGHAND DRAWING MACHINE firmware

- last update 24/10/2014
+ last update 25/10/2014
  by Tim Knapen
  http://www.longhand.cc/

@@ -206,11 +206,14 @@
 	print(current_pos.y);
 	print(", ");
 	println(current_pos.z);
-	print(" Circle resolution (x10): ");
-	println(10 * circleRes);
-
-	print(" Bezier resolution: ");
-	print( bezierResolution);
+
+	/*
+	 print(" Circle resolution (x10): ");
+	 println(10 * circleRes);
+
+	 print(" Bezier resolution: ");
+	 print( bezierResolution);
+	 */

 	/*
      // Just for documentation
@@ -264,3 +267,4 @@
 	print(" ");
 	println(z);
 }
+


Update base2clock.ino

Update base2clock.ino

Fix for time set at quater past, half past, quarter of, and hour. Time set adding two minutes when only one is required to increment at these particular times.

--- base2clock.ino
+++ base2clock.ino
@@ -34,7 +34,7 @@
 int p1,p2,p3,p4,p5,p6,p7,p8 = 0;

 //booleans for time setting purposes.
-boolean time_set,add_2_mins,reset_slow,reset_fast = false;
+boolean time_set,add_2_mins,subtract_1_min,reset_slow,reset_fast = false;

 //call this function if a time set button is pressed.
 void reset_init(){
@@ -52,6 +52,9 @@
   if(p6 == 1) min_init += 8;
   if(p7 == 1) min_init += 4;
   if(p8 == 1) min_init += 2;
+
+  if(p6 == 1 && p7 == 1 && p8 == 1)
+    subtract_1_min = true;
 }

 void setup(){
@@ -76,6 +79,7 @@
   reset_fast = false;
   reset_slow = false;
   add_2_mins = false;
+  subtract_1_min = false;

   //get the time that the program has been running, to calculate time.
   mil = millis();
@@ -153,6 +157,8 @@
     mins = sec/60;
     if(add_2_mins)
       min_init += 2;
+    if(subtract_1_min)
+      min_init -= 1;
     mins += min_init;
     hr = mins/60;
     mins -= (hr*60);


Remove rogue debug thing

Remove rogue debug thing

--- software/firmware/LogoBotEsp8266/LogoBotEsp8266.ino
+++ software/firmware/LogoBotEsp8266/LogoBotEsp8266.ino
@@ -19,8 +19,6 @@

 DNSServer dnsServer;
 ESP8266WebServer server(80);
-
-unsigned long debugTimer = millis();

 IPAddress localIP(0,0,0,0);


modified Sample

modified Sample

--- examples/temperature/temperature.ino
+++ examples/temperature/temperature.ino
@@ -1,5 +1,7 @@
 #include <Wire.h>
 #include "fabo-adt7410.h"
+
+FaBoTemperature faboTemperature;

 void setup() {
   Serial.begin(9600);


Wow, am I a moron...

Wow, am I a moron...

Hint - don't target the LED status of the taps to the same port being
used for the serial link to the Wifi device....

--- RightpointLabs.Pourcast.Arduino/RightpointLabs.Pourcast.Arduino.ino
+++ RightpointLabs.Pourcast.Arduino/RightpointLabs.Pourcast.Arduino.ino
@@ -109,9 +109,9 @@
   Serial << F("Free: ") << freeMemory() << endl;
   http = new NetworkRequester(&wifi, "pourcast.labs.rightpoint.com", 9);
   http->LogMessage("Initializing");
-  tap1 = new Tap(new MultiReporter(new LEDReporter(4), new LEDReporter(10), new NetworkReporter(http, "535c61a951aa0405287989ec")));
+  tap1 = new Tap(new MultiReporter(new LEDReporter(6), new LEDReporter(10), new NetworkReporter(http, "535c61a951aa0405287989ec")));
   attachInterrupt(0, tap1Pulse, RISING);
-  tap2 = new Tap(new MultiReporter(new LEDReporter(5), new LEDReporter(11), new NetworkReporter(http, "537d28db51aa04289027cde5")));
+  tap2 = new Tap(new MultiReporter(new LEDReporter(7), new LEDReporter(11), new NetworkReporter(http, "537d28db51aa04289027cde5")));
   attachInterrupt(1, tap2Pulse, RISING);
   http->LogMessage("DoneInitializing");
   Serial << F("Setup complete") << endl;