Skip to content

Instantly share code, notes, and snippets.

@Happsson
Last active November 8, 2016 23:12
Show Gist options
  • Save Happsson/e0148dcbe355edb1e5d24df88f553df1 to your computer and use it in GitHub Desktop.
Save Happsson/e0148dcbe355edb1e5d24df88f553df1 to your computer and use it in GitHub Desktop.
IS31fl3731 processing.org driver
import processing.io.*;
byte addr = 0x74;
I2C i2c;
byte ISSI_ADDR_DEFAULT = 0x74;
byte ISSI_REG_CONFIG = 0x00;
byte ISSI_REG_CONFIG_PICTUREMODE = 0x00;
byte ISSI_REG_CONFIG_AUTOPLAYMODE = 0x08;
byte ISSI_REG_CONFIG_AUDIOPLAYMODE = 0x18;
byte ISSI_CONF_PICTUREMODE = 0x00;
byte ISSI_CONF_AUTOFRAMEMODE = 0x04;
byte ISSI_CONF_AUDIOMODE = 0x08;
byte ISSI_REG_PICTUREFRAME = 0x01;
byte ISSI_REG_SHUTDOWN = 0x0A;
byte ISSI_REG_AUDIOSYNC = 0x06;
byte ISSI_COMMANDREGISTER = (byte) 0xFD;
byte ISSI_BANK_FUNCTIONREG = (byte) 0x0B;
void setup(){
printArray(I2C.list());
i2c = new I2C(I2C.list()[0]);
initI2C();
}
void setLed(int led, int pwm, byte bank){
writeRegister(bank, (0x24+led), pwm);
}
void initI2C(){
writeRegister(ISSI_BANK_FUNCTIONREG, ISSI_REG_SHUTDOWN,(byte) 0x0);
delay(10);
writeRegister(ISSI_BANK_FUNCTIONREG, ISSI_REG_SHUTDOWN, (byte) 0x1);
writeRegister(ISSI_BANK_FUNCTIONREG, ISSI_REG_CONFIG, ISSI_REG_CONFIG_PICTUREMODE);
displayFrame((byte) 0);
clearF();
for(int f = 0; f < 8; f++){
for(int i = 0; i < 0x11; i++){
writeRegister((byte) f, (byte) i, (byte) 0xff);
}
}
setAudioFalse();
}
void setAudioFalse(){
writeRegister(ISSI_BANK_FUNCTIONREG, ISSI_REG_AUDIOSYNC, (byte) 0x0);
}
void clearF(){
selectBank((byte) 0);
for(int i = 0; i < 6; i++){
i2c.beginTransmission(addr);
i2c.write((byte) 0x24 + i * 24);
for(int j= 0; j< 24;j++){
i2c.write((byte) 0);
}
i2c.endTransmission();
}
}
void displayFrame(byte f){
f = f > 7 ? 0 : f;
writeRegister(ISSI_BANK_FUNCTIONREG, ISSI_REG_PICTUREFRAME, f);
}
void selectBank(byte a){
i2c.beginTransmission(addr);
i2c.write(ISSI_COMMANDREGISTER);
i2c.write(a);
i2c.endTransmission();
}
void writeRegister(byte bank, int reg, int data){
selectBank(bank);
i2c.beginTransmission(addr);
i2c.write(reg);
i2c.write(data);
i2c.endTransmission();
}
int ledId = 0;
int delay = 5;
void draw(){
for(int i = 0; i< 48; i++){
setLixel(i, LED_STATIC_TABLE.RED);
delay(delay);
}
for(int i = 0; i< 48; i++){
setLixel(i, LED_STATIC_TABLE.BLACK);
delay(delay);
}
for(int i = 0; i< 48; i++){
setLixel(i, LED_STATIC_TABLE.GREEN);
delay(delay);
}
for(int i = 0; i< 48; i++){
setLixel(i, LED_STATIC_TABLE.BLACK);
delay(delay);
}
for(int i = 0; i< 48; i++){
setLixel(i, LED_STATIC_TABLE.BLUE);
delay(delay);
}
for(int i = 0; i< 48; i++){
setLixel(i, LED_STATIC_TABLE.BLACK);
delay(delay);
}
for(int i = 0; i< 48; i++){
setLixel(i, LED_STATIC_TABLE.YELLOW);
delay(delay);
}
for(int i = 0; i< 48; i++){
setLixel(i, LED_STATIC_TABLE.BLACK);
delay(delay);
}
for(int i = 0; i< 48; i++){
setLixel(i, LED_STATIC_TABLE.PINK);
delay(delay);
}
for(int i = 0; i< 48; i++){
setLixel(i, LED_STATIC_TABLE.BLACK);
delay(delay);
}
for(int i = 0; i< 48; i++){
setLixel(i, LED_STATIC_TABLE.GREENBLUE);
delay(delay);
}
for(int i = 0; i< 48; i++){
setLixel(i, LED_STATIC_TABLE.BLACK);
delay(delay);
}
for(int i = 0; i< 48; i++){
setLixel(i, LED_STATIC_TABLE.WHITE);
delay(delay);
}
for(int i = 0; i< 48; i++){
setLixel(i, LED_STATIC_TABLE.BLACK);
delay(delay);
}
}
void setLixel(int lixel, int[] _color){
setLed(LED_STATIC_TABLE.lixels[lixel][0], _color[0], (byte) 0);
setLed( LED_STATIC_TABLE.lixels[lixel][1], _color[1], (byte) 0);
setLed( LED_STATIC_TABLE.lixels[lixel][2], _color[2], (byte) 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment