You are reading a single comment by @mattbrailsford and its replies. Click here to read the full conversation.
  • Typical, write a post and find the answer :) Turns out I needed some other methods to be called first to setup the device. The following works:

    // Variables
    var address = 0x70;
    var displaybuffer = new Uint16Array(8);
    
    var LED_OFF = 0;
    var LED_RED = 1;
    var LED_YELLOW = 2;
    var LED_GREEN = 3;
    
    var HT16K33_BLINK_CMD = 0x80;
    var HT16K33_BLINK_DISPLAYON = 0x01;
    var HT16K33_BLINK_OFF = 0;
    var HT16K33_BLINK_2HZ  = 1;
    var HT16K33_BLINK_HALFHZ  = 3;
    
    // Setup I2C
    I2C1.setup({ scl: B6, sda: B7 });
    
    function clearDisplay(){
     for (var i=0; i<8; i++) {
        displaybuffer[i] = 0;
     } 
    }
    
    function setBrightness(lvl) {
      if (lvl > 15) {
        lvl = 15;
      }
      I2C1.writeTo(address, 0xE0 | lvl);
    }
    
    function blinkRate(b) {
      if (b > 3) b = 0; // turn off if not sure
      I2C1.writeTo(address, HT16K33_BLINK_CMD | HT16K33_BLINK_DISPLAYON | (b << 1));
    }
    
    function drawPixel(x,y,color){
      
      if(x < 4){
        x += 4;
      } else {
        x -= 4;
      }
    
      if(y < 4){
        y += 4;
      } else {
        y -= 4;
      }
      
      if (color == LED_GREEN) {
        displaybuffer[y] |= 1 << x;
      } else if (color == LED_RED) {
        displaybuffer[y] |= 1 << (x+8);
      } else if (color == LED_YELLOW) {
        displaybuffer[y] |= (1 << (x+8)) | (1 << x);
      } else if (color == LED_OFF) {
        displaybuffer[y] &= ~(1 << x) & ~(1 << (x+8));
      }
      
    }
    
    function writeDisplay(){
      var tmp = new Uint8Array(17);
      tmp[0] = 0x00;
      for (var i=0; i<16; i+=2) {
        tmp[i+1] = displaybuffer[i/2] & 0xFF;
        tmp[i+2] = displaybuffer[i/2] >> 8; 
      }
      console.log(tmp);
      I2C1.writeTo(address, tmp);
    }
    
    // Turn on oscillator
    I2C1.writeTo(address, 0x21);
    
    // Set blink rate
    blinkRate(HT16K33_BLINK_OFF);
    
    // Set to full brightness
    setBrightness(15);
    
    // Draw pixels
    drawPixel(0,0,LED_GREEN);
    drawPixel(1,1,LED_RED);
    drawPixel(2,2,LED_YELLOW);
    
    // Update display
    writeDisplay();
    
About