-
• #2
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();
-
• #3
Great! I wonder if this could be a library that used the graphics lib :)
-
• #5
Yes, sorry - saw that. I got a billion e-mails over the weekend so I'm just working through in order :)
Repo is EspruinoDocs - but there's a tutorial on modules here I think...
Hi Guys,
I've been spending the last couple of hours trying to convert some Adafruit code to work with the Espruino, but am struggling to get it to work. Can anyone offer any advice?
The code from adafruit is as follows (just the methods I'm bothered about):
And I have currently got the following javascript for the Espruino:
The problem is, I just don't get any lights lighting up. Have I converted the code incorrectly? Or am I miss-understanding how you work with I2C on the Espruino?
Matt