Adventskalender mit Arduino und LED-Matrix

Adventskalender mit Arduino und LED-Matrix

Weihnachten steht vor der Tür, in den Kaufhäusern und Supermärkten ist das Thema sehr präsent und auch wir können uns dem nicht entziehen. Aber wir können es anders angehen.

Wir möchten in diesem Artikel 24 kleine weihnachtliche Animationen für die 16×32 LED-Matrix von Sure Electronics vorstellen. Der Quelltext wird in den kommenden Tagen immer wieder ergänzt.

Nachtrag: Bis zum Nikolaustag gibt es schon was zu sehen.

Download des aktuellen Standes (noch in Entwicklung)

Idee: Wer mag, kann ja eine Echtzeituhr oder einen DCF77-Empfänger anschliessen, um ggf. automatisch auf die neue Animation umzuschalten.

Hardware:

Quelltext:

#include "matrix_32x16xRG.h"

int counter = 0;
int day     = 1;

int dayOfDecember() {
  if (counter>50) {
    day++;
    counter = 0;
    if (day >26) {
      day = 1;
    }
  }
  counter++;
  return day;
}

word ONE_CANDLE[32] = {
  0x7fff, 0x3ffc, 0x0fb0, 0x0ff0, 0x0fb0, 0x0ff0, 0x0fb0, 0x0ff0, 
  0x0fb0, 0x0ff0, 0x0fb0, 0x0ff0, 0x0fb0, 0x0ff0, 0x0fb0, 0x0ff0, 
  0x0fb0, 0x0ff8, 0x0fb8, 0x0ff8, 0x0fb8, 0x0ff8, 0x0fb0, 0x0000, 
  0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
};

word ONE_BRANCH[32] = {
  0x0f00, 0x0300, 0x1d00, 0x0d00, 0x3400, 0x1000, 0x0000, 0x0000, 
  0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
  0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
};

word KERZENSTAENDER[32] = {
  0x0000, 0x7ffe, 0x3ffc, 0x1ff8, 0x0ff0, 0x07e0, 0x03c0, 0x0180, 
  0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x03c0, 0x17e8, 0x27e4, 
  0x27e4, 0x27e4, 0x1ff8, 0x03c0, 0x03c0, 0x03c0, 0x03c0, 0x03c0, 
  0x03c0, 0x03c0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
};

word SCHNEEMANN[32] = {
  0x0000, 0x1f84, 0x2044, 0x4024, 0x4024, 0x4024, 0x2044, 0x1084, 
  0x0f04, 0x1084, 0x2044, 0x2044, 0x2044, 0x1084, 0x0f44, 0x0924, 
  0x109f, 0x109f, 0x1080, 0x0f00, 0x3fc0, 0x0f00, 0x0f00, 0x0f00, 
  0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 
//  0x0008, 0x021c, 0x0708, 0x2200, 0x7002, 0x2087, 0x01c2, 0x0080 
};

word SCHNEEFLOCKEN[32] = {
  0x0000, 0x0000, 0x0000, 0x0000, 0x0200, 0x1540, 0x3260, 0x0a80,
  0x2720, 0x5dd0, 0x2720, 0x0a80, 0x3260, 0x1540, 0x0200, 0x0000, 
  0x0000, 0x0000, 0x0000, 0x0200, 0x1540, 0x3260, 0x0a80, 0x2720, 
  0x5dd0, 0x2720, 0x0a80, 0x3260, 0x1540, 0x0200, 0x0000, 0x0000 
}; 

word EISENBAHN[32] = {
  0x1f00, 0x3100, 0x7900, 0x3100, 0x1100, 0x1100, 0x1100, 0x1100,
  0x3100, 0x7900, 0x3100, 0x1f00, 0x0800, 0x1c00, 0x0c00, 0x1ffc, 
  0x1004, 0x30f4, 0x7894, 0x78f4, 0x3004, 0x1ffc, 0x1081, 0x1083, 
  0x108e, 0x30f4, 0x78f0, 0x7880, 0x3080, 0x1080, 0x1f80, 0x0000 
}; 

word GLOCKE[32] = {
  0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4000, 0x2000, 0x1000,
  0x0c00, 0x4200, 0x6100, 0x70c0, 0x5820, 0x4e18, 0x47c4, 0x41f2, 
  0x583e, 0xdf0f, 0xdf0f, 0x583c, 0x41f0, 0x47c0, 0x4e00, 0x5800, 
  0x7000, 0x6000, 0x4000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 
}; 

word STERNE[32] = {
  0x0000, 0x2008, 0x3018, 0x3838, 0x1ef0, 0x1ff0, 0x0fe0, 0x0fe0,
  0x0fe0, 0x3ff8, 0x7ffc, 0x07c0, 0x0380, 0x0180, 0x0080, 0x0000, 
  0x0000, 0x2008, 0x3018, 0x3838, 0x1ef0, 0x1ff0, 0x0fe0, 0x0fe0, 
  0x0fe0, 0x3ff8, 0x7ffc, 0x07c0, 0x0380, 0x0180, 0x0080, 0x0000 
};  

word SCHLITTEN[32] = {
  0x0000, 0x0000, 0x0000, 0x4200, 0x4200, 0x43e0, 0x43e0, 0x7fe8,
  0x43f0, 0x43f0, 0x43e8, 0x47e0, 0x4200, 0x43fa, 0x43fc, 0x43fc, 
  0x43fa, 0x4200, 0x43f0, 0x43f4, 0x7ff8, 0x43f8, 0x43f4, 0x43f0, 
  0x4200, 0x4300, 0x4180, 0x6080, 0x3180, 0x1f00, 0x0e00, 0x0000 
};  

word HIRSCHE[32] = {
  0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0400, 0x7e00, 0x7e10,
  0x0e20, 0x0f20, 0x7fa0, 0x7ff0, 0x0fd8, 0x00c0, 0x0080, 0x0000, 
  0x0000, 0x0000, 0x0000, 0x0000, 0x0400, 0x7e00, 0x7e10, 0x0e20, 
  0x0f20, 0x7fa0, 0x7ff0, 0x0fd8, 0x00c0, 0x0080, 0x0000, 0x0000 
};  

word NIKOLAUSSTIEFEL[32] = {
  0x0000, 0x7fbe, 0xffff, 0x8001, 0x8001, 0x8001, 0x8081, 0x4101,
  0x3e01, 0x0101, 0x0081, 0x0081, 0x0041, 0x0041, 0x0041, 0x007f, 
  0x0081, 0x0081, 0x0081, 0x0077, 0x0149, 0x0229, 0x0419, 0x0209, 
  0x011f, 0x0ea0, 0x0240, 0x0200, 0x0000, 0x0000, 0x0000, 0x0000 
};

word WEIHNACHTSBAUM[32] = {
  0x0000, 0x03c0, 0x03c0, 0x03c0, 0x03c0, 0x03c0, 0xffff, 0x7ffe,
  0x7ffe, 0x3ffc, 0x1ff8, 0x7ffe, 0x3ffc, 0x1ff8, 0x0ff0, 0x3ffc, 
  0x1ff8, 0x0ff0, 0x07e0, 0x1ff8, 0x0ff0, 0x07e0, 0x03e0, 0x03e0, 
  0x01c0, 0x01c0, 0x0080, 0x0080, 0x0000, 0x0000, 0x0000, 0x0000 
};

word FLAME_PIXELS[] = {
                  0x1e08, 
          0x1d07, 0x1d08,
          0x1c07, 0x1c08,
  0x1b06, 0x1b07, 0x1b08, 0x1b09, 
  0x1a06, 0x1a07, 0x1a08, 0x1a09, 
  0x1906, 0x1907, 0x1908, 0x1909, 
          0x1807, 0x1808,
};

word FLAME_SMALL_PIXELS[] = {
                  0x1e08, 
          0x1d07, 0x1d08,
          0x1c07, 0x1c08,
          0x1b07, 0x1b08, 
          0x1a07 
};

int FLAME_COLORS[] = {
  COLOR_RED,
  COLOR_YELLOW,
  COLOR_YELLOW,
  COLOR_YELLOW,
  COLOR_NONE
};

void drawSprite(word bits32x16[], int offsetX, int offsetY, int color) {
  word bits;
  int  x;
  
  for (int indexX=0; indexX<32; indexX++) {
    bits = bits32x16[indexX];
    x    = indexX + offsetX;
    for (int y=offsetY; y<16+offsetY; y++) {
      if (bits & 0x0001) {
        plot(x, y, color);
      } // no else
      bits = bits >> 1;
    }
  }
} 

void drawRandom(word posXY[], int sizePosXY, int colors[], int sizeColors) {
  int x, y;
  
  for (int index=0; index<sizePosXY; index++) {
    x = (posXY[index] >> 8);
    y = (posXY[index] & 0x00ff);
    plot(x, y, colors[random(sizeColors)]);
  }
} 


void dec01() {
  for(int i=0; i<32; i++) {
    plot( random(32),  random(16), random(4));
  }
}

void dec02() {
  drawSprite(ONE_CANDLE, 0, 0, COLOR_RED);
  drawSprite(ONE_BRANCH, 0, 0, COLOR_GREEN);
  drawRandom(FLAME_PIXELS, sizeof(FLAME_PIXELS)/2, FLAME_COLORS, sizeof(FLAME_COLORS)/2);
}

void dec03() {
  drawSprite(KERZENSTAENDER, 0, 0, COLOR_RED);
  drawRandom(FLAME_SMALL_PIXELS, sizeof(FLAME_SMALL_PIXELS)/2, FLAME_COLORS, sizeof(FLAME_COLORS)/2);
}

void dec04() {
  for(int i=0; i<32; i++) {
    plot( random(32),  random(16), random(4));
  }
  drawSprite(GLOCKE, 0, 0, COLOR_YELLOW);
}

void dec05() {
  drawSprite(SCHNEEMANN, 0, 0, COLOR_YELLOW);
  for(int i=24; i<32; i++) {
    plot( 24+random(8),  random(16), random(4));
  }
}

int offset = -16;

void dec06() {
  drawSprite(NIKOLAUSSTIEFEL, 0, 0, COLOR_RED);
}

void dec07() {
  for(int i=0; i<8; i++) {
    plot( random(32),  random(16), random(4));
  }
  drawSprite(SCHNEEFLOCKEN, random(2), offset, COLOR_RED);
  offset++;
  if (offset>16) {
    offset = -16;
  }
  delay(50);
}

void dec08() {
}

void dec09() {}
void dec10() {}
void dec11() {}
void dec12() {}
void dec13() {}
void dec14() {}
void dec15() {}
void dec16() {}
void dec17() {}
void dec18() {}
void dec19() {}
void dec20() {}
void dec21() {}
void dec22() {}
void dec23() {}
void dec24() {}

void setup() {
  matrixSetup(ATS_CS_PIN, ATS_WRCLK_PIN, ATS_DATA_PIN, ATS_CLK_PIN);
}


void loop() {
  int day;
  
  day = dayOfDecember();
  
  switch (day) {
    case  1: dec01(); break; 
    case  2: dec02(); break; 
    case  3: dec03(); break; 
    case  4: dec04(); break; 
    case  5: dec05(); break; 
    case  6: dec06(); break; 
    case  7: dec07(); break; 
    case  8: dec08(); break; 
    case  9: dec09(); break; 
    case 10: dec10(); break; 
    case 11: dec11(); break; 
    case 12: dec12(); break; 
    case 13: dec13(); break; 
    case 14: dec14(); break; 
    case 15: dec15(); break; 
    case 16: dec16(); break; 
    case 17: dec17(); break; 
    case 18: dec18(); break; 
    case 19: dec19(); break; 
    case 20: dec20(); break; 
    case 21: dec21(); break; 
    case 22: dec22(); break; 
    case 23: dec23(); break; 
    case 24: dec24(); break;
    default : break;// do nothing (except waiting for xmas)
  }
  
  nextImage(10);
}

Tags: