Avatar for Sigma

Sigma

Member since Jul 2017 • Last active Apr 2021
  • 1 conversations
  • 7 comments

a web frontend developer

Most recent activity

  • in JavaScript
    Avatar for Sigma

    I use timer to flag if action be done.
    I set timer = undefined after clear it.

    Resolved.
    thx!

  • Avatar for Sigma

    After along time exploering, I found when set intensity less than 0.3 , it would be ok.
    it connect v3.3 . it' voltage may be a bit lower .
    amazing...

    demo code :

    SPI2.setup({
      mosi: B15,
      sck: B13
    });
    var disp = require("MAX7219").connect(SPI2, B14, 16);
    
    /** 呼吸灯效 */
    function breath() {
      var light = 0.01;
      var increase = true;
    
      setInterval(function () {
        if (increase) {
          light += 0.01;
        } else {
          light -= 0.01;
        }
    
        if (light > 0.99) {
          increase = false;
        } else if (light < 0.01) {
          increase = true;
        }
        disp.intensity(light);
      }, 30);
    }
    
    var buffers = [
      // 开心家园
      [0, 0, 0, 0, 96, 2, 36, 0, 0, 0, 0, 0, 72, 2, 200, 33, 0, 14, 0, 0, 32, 2, 36, 8, 128, 0, 0, 0, 160, 1, 72, 41, 224, 15, 0, 0, 32, 2, 70, 16, 0, 28, 0, 30, 144, 7, 72, 40, 96, 2, 0, 0, 16, 2, 128, 63, 248, 49, 248, 48, 96, 121, 40, 46, 64, 2, 192, 0, 8, 2, 0, 30, 12, 0, 8, 34, 16, 49, 8, 32, 64, 50, 128, 49, 4, 2, 0, 0, 228, 3, 200, 33, 132, 1, 248, 63, 192, 63, 0, 33, 0, 2, 0, 0, 192, 4, 8, 38, 192, 1, 0, 0, 126, 2, 4, 0, 0, 0, 0, 0, 96, 4, 232, 33, 128, 0, 0, 0],
      // 照片可取
      // [0, 0, 0, 0, 60, 17, 32, 4, 0, 0, 0, 0, 240, 4, 88, 10, 0, 24, 0, 6, 36, 15, 224, 7, 0, 0, 0, 0, 16, 4, 72, 12, 52, 51, 32, 6, 0, 0, 48, 4, 192, 127, 192, 0, 0, 4, 200, 12, 108, 18, 32, 2, 36, 49, 16, 4, 30, 4, 252, 0, 0, 4, 120, 26, 108, 30, 32, 2, 68, 98, 8, 4, 0, 4, 72, 0, 0, 7, 71, 113, 124, 9, 32, 30, 2, 64, 0, 4, 248, 4, 72, 30, 0, 6, 64, 224, 228, 0, 224, 3, 0, 0, 0, 4, 144, 4, 88, 25, 0, 0, 96, 0, 100, 31, 32, 0, 0, 0, 0, 4, 144, 4, 72, 9, 0, 0, 0, 0],
      // 照片打印
      [0, 0, 0, 0, 252, 27, 32, 6, 0, 0, 0, 0, 32, 8, 0, 18, 0, 0, 0, 3, 56, 13, 224, 7, 32, 0, 0, 0, 56, 8, 104, 30, 0, 60, 0, 2, 0, 7, 48, 4, 32, 0, 192, 0, 38, 8, 28, 2, 124, 55, 48, 2, 36, 51, 16, 4, 32, 0, 32, 0, 32, 8, 12, 2, 104, 26, 32, 2, 100, 50, 24, 4, 32, 0, 24, 60, 32, 8, 0, 2, 104, 31, 32, 15, 6, 96, 12, 4, 224, 96, 12, 39, 48, 14, 0, 2, 248, 9, 224, 1, 0, 0, 0, 4, 60, 31, 104, 34, 0, 4, 0, 2, 232, 30, 32, 0, 0, 0, 0, 0, 96, 8, 24, 50, 0, 0, 0, 0],
      // 我还没睡
      [0, 0, 0, 0, 60, 26, 72, 48, 0, 0, 0, 0, 0, 15, 128, 63, 128, 1, 0, 0, 192, 8, 40, 2, 0, 0, 0, 0, 192, 4, 252, 2, 0, 1, 0, 0, 48, 4, 0, 2, 0, 4, 0, 12, 16, 5, 0, 122, 0, 13, 216, 63, 46, 14, 8, 2, 176, 7, 0, 6, 8, 2, 242, 7, 64, 1, 0, 2, 160, 9, 246, 0, 0, 5, 184, 3, 12, 7, 30, 2, 32, 1, 0, 3, 48, 112, 0, 255, 128, 4, 20, 30, 200, 24, 192, 31, 48, 15, 0, 3, 0, 96, 0, 0, 140, 60, 128, 19, 0, 112, 0, 0, 224, 1, 156, 24, 0, 0, 0, 0, 8, 0, 156, 18, 0, 0, 0, 0],
      // 可以取菜
      [0, 0, 0, 0, 208, 4, 216, 8, 0, 0, 0, 0, 120, 12, 128, 0, 0, 0, 0, 0, 48, 4, 120, 12, 0, 0, 32, 6, 200, 4, 252, 15, 0, 0, 0, 0, 0, 4, 24, 30, 0, 0, 96, 18, 120, 10, 224, 1, 240, 127, 0, 48, 0, 4, 24, 51, 252, 1, 252, 15, 78, 49, 176, 2, 12, 6, 128, 17, 0, 6, 136, 97, 72, 8, 0, 0, 64, 64, 152, 12, 0, 4, 24, 19, 0, 7, 192, 0, 72, 31, 128, 3, 64, 0, 132, 120, 248, 5, 24, 24, 0, 2, 0, 0, 88, 9, 96, 12, 0, 0, 192, 0, 144, 4, 152, 24, 0, 0, 0, 0, 72, 10, 144, 2, 0, 0, 0, 0]
    ].map(function (word) {
      return new Uint8Array(word).buffer;
    });
    
    var n = 0;
    
    function getOne() {
      if (n >= buffers.length) {
        n = 0;
      }
      var b = buffers[n];
      n++;
      return b;
    }
    
    // var timer = null;
    /** 开始闪耀 */
    function blink() {
    
      // if (timer) {
      //   clearInterval(timer);
      // }
      // timer =
      setInterval(function () {
        disp.raw(getOne());
      }, 3000);
    
      breath();
    }
    
    blink();
    
  • Avatar for Sigma

    I connect 2 matrix led( 32 x 16 ) into one big (64 x 16).
    It's rendering order :

    and upload code below:

    SPI2.setup({
      mosi: B15,
      sck: B13
    });
    var disp = require("MAX7219").connect(SPI2, B14, 16);
    
    disp.raw(new Uint8Array([0, 0, 0, 0, 96, 2, 36, 0, 0, 0, 0, 0, 72, 2, 200, 33, 0, 14, 0, 0, 32, 2, 36, 8, 128, 0, 0, 0, 160, 1, 72, 41, 224, 15, 0, 0, 32, 2, 70, 16, 0, 28, 0, 30, 144, 7, 72, 40, 96, 2, 0, 0, 16, 2, 128, 63, 248, 49, 248, 48, 96, 121, 40, 46, 64, 2, 192, 0, 8, 2, 0, 30, 12, 0, 8, 34, 16, 49, 8, 32, 64, 50, 128, 49, 4, 2, 0, 0, 228, 3, 200, 33, 132, 1, 248, 63, 192, 63, 0, 33, 0, 2, 0, 0, 192, 4, 8, 38, 192, 1, 0, 0, 126, 2, 4, 0, 0, 0, 0, 0, 96, 4, 232, 33, 128, 0, 0, 0]).buffer);
    

    the first time I upload , it shows right.
    when i do multiple times , it shows wrong.

    I test it by:

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

    it seem has some issues:

    • disp.displayTest(true);

    • disp.displayTest(false);

    What's wrong with it ?

  • in Interfacing
    Avatar for Sigma

    Yeah,I have got it. Thx!
    The long string tells out the order LED Matrix rendering.
    Like this:

    and this:

  • in Interfacing
    Avatar for Sigma

    I got a big Matrix LED : 32 x 16
    Can I draw it use module MAX7219 ?

    How to set the device count ?

    SPI2.setup({mosi:B15, sck:B13});
    var disp = require("MAX7219").connect(SPI2, B14, 8); //  8 seems not work
    
    var g = Graphics.createArrayBuffer(32, 16, 1);
    g.flip = function() { disp.raw(g.buffer); };
    
    g.drawString("Hello!", 0, 0, 1);
    g.flip();
    
  • in JavaScript
    Avatar for Sigma

    I got an error :

    in function called from system
    Uncaught Error: Unknown Timeout
    at line 17 col 31

            clearTimeout(timer);
    
    // 红外移动传感 FIR800 5v
    // http://www.espruino.com/Pyroelectric
    // Relay: low level trigger
    
    function run() {
        var timer;
        var pyreolectric = A0;
        var relay = A1;
        var delay = 20000; // 20 sec
    
        setWatch(function () {
            console.log("Movement detected");
            LED2.write(1);
            digitalWrite(relay, 0);// trigger relay: ON
    
            if (timer !== undefined) {
                clearTimeout(timer); // debounce
            }
    
            timer = setTimeout(function () {// trigger relay: OFF
                LED2.write(0);
                digitalWrite(relay, 1);
            }, delay);
        }, pyreolectric, { repeat: true, edge: "rising" });
    }
    E.on('init', run);
    
    

    Does the code have some mistakes ? Help, thx!

Actions