Dies ist mein erster Test mit dem MAX7219 Chip am Espruino Board. Das Board ist über die 3 Ausgänge B13 bis B15 angeschlossen und steuert eine 8×8 LED Matrix an. Die habe ich für ein paar Euro bei ebay bestellt.

Mit den folgenden Zeilen JavaScript Code kann man das Beispiel aus dem Video nachstellen. Viel Spaß beim basteln :-).

clearInterval();
clearTimeout();

digitalWrite (LED1,0);
digitalWrite (LED2,0);
digitalWrite (LED3,1);

SPI2.setup({mosi:B15, sck:B13});
var disp = require("MAX7219").connect(SPI2,B14);

var stage = 0;
var off = [0,0,0,0,0,0,0,0];
var all = [255,255,255,255,255,255,255,255];
var half1 = [255,0,255,0,255,0,255,0];
var half2 = [0,255,0,255,0,255,0,255];
var diagonale = [1,2,4,8,16,32,64,128];
var smiley = [60,66,153,165,129,165,66,60];
var invertsmiley = [195,189,102,90,126,90,189,195];
var heart = [0,54,127,127,127,62,28,8];

function counter () {
  digitalWrite (LED1, 1);
  clearInterval ();
  var a = new Array(0, 0, 0, 0, 0, 0, 0, 0);
  setInterval(function() {
    disp.raw([a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]]);
    disp.intensity(1);

    a[0]+= 1;
    for (i = 0; i < 7; i++)
    {
      if (a[i] > 255)
      {
        a[i] = 0;
        a[i+1]+=1;
      }
    }
    if (a[7] > 255)
    {
      a = new Array(0, 0, 0, 0, 0, 0, 0, 0);
    }
  }, 5);
}

function showAll () {
  // Alle LEDs einschalten
  disp.raw(off);
  intensity = 0;
  diff = 0.1;
  setInterval(function() {
    disp.intensity(intensity);
    if (intensity > 1 || intensity < 0)
      diff = -diff;
    intensity += diff;
    disp.raw(all);
  }, 100);

}

function showSmiley () {
  // Smiley zeichnen
  disp.intensity(1);
  disp.raw(smiley);
}

function blinkHeart () {
  // Herz blinken lassen  
  intensity = 0;
  diff = 0.1;
  setInterval(function() {
    disp.intensity(intensity);
    if (intensity > 1 || intensity < 0)
      diff = -diff;
    intensity += diff;
    disp.raw(heart);
  }, 100);
}

function showDiagonale () {
  // Diaginale Linie
  disp.intensity(1);
  disp.raw(diagonale);
}

function blinkSmiley () {
    on = 1;
    inv = 1;
    disp.intensity(on);
    setInterval(function() {
      if (inv)
        disp.raw(smiley);
      else
        disp.raw(invertsmiley);
      inv =! inv;
    },500);
}

function run () {
  clearInterval();
  clearTimeout();
  disp = require("MAX7219").connect(SPI2,B14);
  disp.raw(off);
  switch (stage)
  {
    case 0:
      setTimeout(showAll, 100);
      break;
    case 1:
      showDiagonale ();
      break;
    case 2:
      setTimeout(showSmiley, 100);
      break;
    case 3:
      setTimeout(blinkSmiley, 100);
      break;
    case 4:
      setTimeout(blinkHeart, 100);
      break;
    case 5:
      setTimeout(counter,100);
      break;
    default:
      stage = -1;
  }
  stage ++;
}

setWatch(run, BTN1, {repeat:true,edge:"rising", debounce:1/*ms*/});
Meine Apps im Google Play-Strore Jetzt bei Google Play