NJU6063 http://www.njr.com/semicon/products/NJU6063.html
Dependencies: NJU6063 Switch mbed
main.cpp
- Committer:
- og
- Date:
- 2015-12-26
- Revision:
- 0:37f6feae4997
- Child:
- 1:ca6bb775aa5b
File content as of revision 0:37f6feae4997:
#include "mbed.h" I2C i2c(dp5, dp27); //sda scl DigitalOut NJU6063_rst(dp14); const int NJU6063_addr = 0x40; void NJU6063_cmd(char chip, char reg, char* data, int length){ char data0[10]; data[0] = chip; data[1] = reg; memcpy(&data0[2], data, length); i2c.write(NJU6063_addr, data0, length+2); } void NJU6063_set_multi_device(char n){ char data[3]; data[0] = 0x00; // Initial chip addres data[1] = 0x0d; // multi device address for (char i=1; i<=n; i++){ data[2] = i; i2c.write(NJU6063_addr, data, 3); } } void NJU6063_dim_start(char chip_addr) { char data[3]; data[0] = chip_addr; data[1] = 0x07; // reg addres data[2] = 0x01; // start i2c.write(NJU6063_addr, data, 3); } void NJU6063_init(char chip_addr, char d) { char data[3]; data[0] = chip_addr; data[1] = 0x00; data[2] = d; i2c.write(NJU6063_addr, data, 3); } void NJU6063_set_iled(char chip_addr, char d1, char d2, char d3) { char data[3]; data[0] = chip_addr; data[1] = 0x01; data[2] = (0x03&d1) | (0x03&d2)<<2 | (0x03&d3) <<4; i2c.write(NJU6063_addr, data, 3); } void NJU6063_set_pwm(char chip_addr, char d1, char d2, char d3, char loop=0x5f, char son=0x00) { char data[7]; data[0] = chip_addr; data[1] = 0x02; data[2] = d1; data[3] = d2; data[4] = d3; data[5] = loop; data[6] = son; i2c.write(NJU6063_addr, data, 7); } char NJU6063_chkdim() { char ACK; char data[3]; data[0] = 0xff; data[1] = 0x0b; data[2] = 0x00; do { ACK = i2c.write(NJU6063_addr, data, 3); } while(!ACK); return(ACK); } void nju6063() { char init_array0[] = { 0xff, // chip address 0x00, // reg address 0x01, // init 0x3f // LED current }; char set_led_data[] = { 0xff, // chip adress 0x02, // reg addres 0x3f, // led1 0x3f, // led2 0x3f, // led3 0x00, // loop 0x00 // son }; char dim_start[] = { 0xff, // chip addres 0x07, // reg addres 0x01 // strat }; i2c.write(NJU6063_addr, init_array0, sizeof(init_array0)); i2c.write(NJU6063_addr, set_led_data, sizeof(set_led_data)); i2c.write(NJU6063_addr, dim_start, sizeof(dim_start)); } #define MAXCHIP 5 #define CHIP1 1 #define DIMPATMAX 4 #define MAXPAT 24 #define DIMLOOP 0x5f #define WAITE __delay_ms(1000) const char PAT[DIMPATMAX][MAXPAT][4] = { { {0xff, 0x00, 0xff, 0x5f}, {0xbf, 0x00, 0xff, 0x5f}, {0x7f, 0x00, 0xff, 0x5f}, {0x3f, 0x00, 0xff, 0x5f}, {0x00, 0x00, 0xff, 0x5f}, {0x00, 0x3f, 0xff, 0x5f}, {0x00, 0x7f, 0xff, 0x5f}, {0x00, 0xbf, 0xff, 0x5f}, {0x00, 0xff, 0xff, 0x5f}, {0x00, 0xff, 0xbf, 0x5f}, {0x00, 0xff, 0x7f, 0x5f}, {0x00, 0xff, 0x3f, 0x5f}, {0x00, 0xff, 0x00, 0x5f}, {0x3f, 0xff, 0x00, 0x5f}, {0x7f, 0xff, 0x00, 0x5f}, {0xbf, 0xff, 0x00, 0x5f}, {0xff, 0xff, 0x00, 0x5f}, {0xff, 0xbf, 0x00, 0x5f}, {0xff, 0x7f, 0x00, 0x5f}, {0xff, 0x3f, 0x00, 0x5f}, {0xff, 0x00, 0x00, 0x5f}, {0xff, 0x00, 0x3f, 0x5f}, {0xff, 0x00, 0x7f, 0x5f}, {0xff, 0x00, 0xbf, 0x5f} }, { {0xff, 0x00, 0xff, 0x50}, {0xbf, 0x00, 0xff, 0x50}, {0x7f, 0x00, 0xff, 0x50}, {0x3f, 0x00, 0xff, 0x50}, {0x00, 0x00, 0xff, 0x50}, {0x00, 0x3f, 0xff, 0x50}, {0x00, 0x7f, 0xff, 0x50}, {0x00, 0xbf, 0xff, 0x50}, {0x00, 0xff, 0xff, 0x50}, {0x00, 0xff, 0xbf, 0x50}, {0x00, 0xff, 0x7f, 0x50}, {0x00, 0xff, 0x3f, 0x50}, {0x00, 0xff, 0x00, 0x50}, {0x3f, 0xff, 0x00, 0x50}, {0x7f, 0xff, 0x00, 0x50}, {0xbf, 0xff, 0x00, 0x50}, {0xff, 0xff, 0x00, 0x50}, {0xff, 0xbf, 0x00, 0x50}, {0xff, 0x7f, 0x00, 0x50}, {0xff, 0x3f, 0x00, 0x50}, {0xff, 0x00, 0x00, 0x50}, {0xff, 0x00, 0x3f, 0x50}, {0xff, 0x00, 0x7f, 0x50}, {0xff, 0x00, 0xbf, 0x50} }, { {0xff, 0x00, 0x00, 0x00}, {0x00, 0xff, 0x00, 0x00}, {0x00, 0x00, 0xff, 0x00}, {0xff, 0x00, 0x00, 0x00}, {0x00, 0xff, 0x00, 0x00}, {0x00, 0x00, 0xff, 0x00}, {0xff, 0x00, 0x00, 0x00}, {0x00, 0xff, 0x00, 0x00}, {0x00, 0x00, 0xff, 0x00}, {0xff, 0x00, 0x00, 0x00}, {0x00, 0xff, 0x00, 0x00}, {0x00, 0x00, 0xff, 0x00}, {0xff, 0x00, 0x00, 0x00}, {0x00, 0xff, 0x00, 0x00}, {0x00, 0x00, 0xff, 0x00}, {0xff, 0x00, 0x00, 0x00}, {0x00, 0xff, 0x00, 0x00}, {0x00, 0x00, 0xff, 0x00}, {0xff, 0x00, 0x00, 0x00}, {0x00, 0xff, 0x00, 0x00}, {0x00, 0x00, 0xff, 0x00}, {0xff, 0x00, 0x00, 0x00}, {0x00, 0xff, 0x00, 0x00}, {0x00, 0x00, 0xff, 0x00} }, { {0xff, 0x00, 0x00, 0x0f}, {0x00, 0xff, 0x00, 0x0f}, {0x00, 0x00, 0xff, 0x0f}, {0xff, 0x00, 0x00, 0x0f}, {0x00, 0xff, 0x00, 0x0f}, {0x00, 0x00, 0xff, 0x0f}, {0xff, 0x00, 0x00, 0x0f}, {0x00, 0xff, 0x00, 0x0f}, {0x00, 0x00, 0xff, 0x0f}, {0xff, 0x00, 0x00, 0x0f}, {0x00, 0xff, 0x00, 0x0f}, {0x00, 0x00, 0xff, 0x0f}, {0xff, 0x00, 0x00, 0x0f}, {0x00, 0xff, 0x00, 0x0f}, {0x00, 0x00, 0xff, 0x0f}, {0xff, 0x00, 0x00, 0x0f}, {0x00, 0xff, 0x00, 0x0f}, {0x00, 0x00, 0xff, 0x0f}, {0xff, 0x00, 0x00, 0x0f}, {0x00, 0xff, 0x00, 0x0f}, {0x00, 0x00, 0xff, 0x0f}, {0xff, 0x00, 0x00, 0x0f}, {0x00, 0xff, 0x00, 0x0f}, {0x00, 0x00, 0xff, 0x0f} } }; int i; char step_color0; void color0(char no, char loop){ char n; char pat_no; pat_no = no % DIMPATMAX; NJU6063_chkdim(); for (n = 0; n < MAXCHIP; n++) { step_color0 = i + n; if (step_color0 >= MAXPAT) { step_color0 = step_color0 - MAXPAT; } NJU6063_set_pwm( CHIP1 + n, PAT[pat_no][step_color0][0], PAT[pat_no][step_color0][1], PAT[pat_no][step_color0][2], PAT[pat_no][step_color0][3] ); } NJU6063_dim_start(0xff); i++; if (i >= MAXPAT) { i = 0; } } int main () { NJU6063_rst = 0; wait(0.01); NJU6063_rst = 1; NJU6063_set_multi_device(5); NJU6063_init(0xff, 0x01); NJU6063_set_iled(0xff, 1,1,1); NJU6063_set_pwm(0xff, 0x7f,0x7f,0x7f); NJU6063_dim_start(0xff); //nju6063(); while(1){ color0(0, 0x5f); /* NJU6063_set_iled(0xff, 1,0,0); wait(1); NJU6063_set_iled(0xff, 0,1,0); wait(1); NJU6063_set_iled(0xff, 0,0,1); wait(1); NJU6063_set_iled(0xff, 2,0,0); wait(1); NJU6063_set_iled(0xff, 0,2,0); wait(1); NJU6063_set_iled(0xff, 0,0,2); wait(1); NJU6063_set_iled(0xff, 3,0,0); wait(1); NJU6063_set_iled(0xff, 0,3,0); wait(1); NJU6063_set_iled(0xff, 0,0,3); wait(1); NJU6063_set_iled(0xff, 4,0,0); wait(1); NJU6063_set_iled(0xff, 0,4,0); wait(1); NJU6063_set_iled(0xff, 0,0,4); wait(1); */ } }