Adafruit I2C 7 segment displays

Posted on
  • For displays like this: https://www.adafruit.com/products/881

    Using the HT16K33 chip. This one will also interface to the alphanumeric displays like these: https://www.adafruit.com/products/1912

    But it won't display anything useful, since you need to send 16 bit values to the controller (in ledShow we just send 0 for the top 8 bits)

    Just thought I'd post this up:

    var table = {
      " ":0,
      0:0x3F, /* 0 */
      1:0x06, /* 1 */
      2:0x5B, /* 2 */
      3:0x4F, /* 3 */
      4:0x66, /* 4 */
      5:0x6D, /* 5 */
      6:0x7D, /* 6 */
      7:0x07, /* 7 */
      8:0x7F, /* 8 */
      9:0x6F, /* 9 */
      "A":0x77, /* A */
      "B":0x7C, /* b */
      "C":0x39, /* C */
      "D":0x5E, /* d */
      "E":0x79, /* E */
      "F":0x71  /* F */
    };
    
    function ledInit() {
     I2C1.setup({scl:B6, sda:B7});
     I2C1.writeTo(0x70, 0x21); // clock on
     I2C1.writeTo(0x70, 0x81); // flash
     I2C1.writeTo(0x70, 0xE0 | 15); // brightness 15
    }
    
    function ledShow(n) {
     n="    "+n;
     N = n.substr(-4);
     I2C1.writeTo(0x70, [0,table[n[0]],0,table[n[1]],0,0,0,table[n[2]],0,table[n[3]],0]);
    }
    
    function ledFlash(isFlashing) {
      // different numbers give different flash speeds
      I2C1.writeTo(0x70, isFlashing ? 0x83 : 0x81);
    }
    
    ledInit();
    ledShow("0000"); // or just ledShow(0) to have '0', not '0000'
    

    I did it a while ago and didn't have time to make a module - thought it might help someone.


    1 Attachment

    • 881-00.jpg
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Adafruit I2C 7 segment displays

Posted by Avatar for Gordon @Gordon

Actions