NJU6063 http://www.njr.com/semicon/products/NJU6063.html

Dependencies:   NJU6063 Switch mbed

Committer:
og
Date:
Sat Feb 13 13:23:06 2016 +0000
Revision:
4:be110fd5e6bd
Parent:
3:50741484f1de
NJU6063 demo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
og 0:37f6feae4997 1 #include "mbed.h"
og 1:ca6bb775aa5b 2 #include "NJU6063.h"
og 1:ca6bb775aa5b 3 #include "Switch.h"
og 2:f76f2f14b489 4 /**
og 2:f76f2f14b489 5 * STM32 I2C dont'work after Nack.
og 2:f76f2f14b489 6 */
og 3:50741484f1de 7 //#ifdef TARGET_ARCH_PRO
og 3:50741484f1de 8 #ifdef TARGET_ARCH_PRO
og 3:50741484f1de 9 Serial pc(USBTX, USBRX);
og 3:50741484f1de 10 NJU6063 nju6063(p28, p27, P0_4); // sda scl rst
og 3:50741484f1de 11 Switch sw(P2_0, P2_1); //
og 3:50741484f1de 12 #elif defined TARGET_LPC1768
og 1:ca6bb775aa5b 13 // mbed LPC1114FN28
og 2:f76f2f14b489 14 Serial pc(USBTX, USBRX);
og 2:f76f2f14b489 15 NJU6063 nju6063(p9, p10, p7); // sda scl rst
og 2:f76f2f14b489 16 Switch sw(p15,p16); //
og 3:50741484f1de 17 #elif defined TARGET_LPC1114
og 2:f76f2f14b489 18 // mbed LPC1114FN28
og 2:f76f2f14b489 19 //Serial pc(dp16, dp15);
og 1:ca6bb775aa5b 20 NJU6063 nju6063(dp5, dp27, dp18); // sda scl rst
og 2:f76f2f14b489 21 Switch sw(dp17,dp14); //
og 1:ca6bb775aa5b 22 #elif defined TARGET_LPC11U35_501
og 2:f76f2f14b489 23 //Serial pc(p19, p18);
og 1:ca6bb775aa5b 24 NJU6063 nju6063(p28, p27, p25); // sda scl rst
og 1:ca6bb775aa5b 25 Switch sw(p11,p12); //
og 3:50741484f1de 26 #elif defined TARGET_NUCLEO_F401RE
og 3:50741484f1de 27 NJU6063 nju6063(I2C_SDA, I2C_SCL, PA_10); // sda scl rst
og 3:50741484f1de 28 Switch sw(PA_0, PA_1); //
og 3:50741484f1de 29 Serial pc(SERIAL_TX, SERIAL_RX);
og 2:f76f2f14b489 30 //#elif defined TARGET_NUCLEO_F042K6
og 2:f76f2f14b489 31 //NJU6063 nju6063(PB_7, PB_6, PB_1); // sda scl rst
og 2:f76f2f14b489 32 //Switch sw(PA_0, PA_1); //
og 2:f76f2f14b489 33 //Serial pc(SERIAL_TX, SERIAL_RX);
og 1:ca6bb775aa5b 34 #endif
og 0:37f6feae4997 35
og 1:ca6bb775aa5b 36 #define MAXCHIP 8
og 0:37f6feae4997 37 #define DIMPATMAX 4
og 0:37f6feae4997 38 #define MAXPAT 24
og 1:ca6bb775aa5b 39
og 2:f76f2f14b489 40 const uint8_t PAT[DIMPATMAX][MAXPAT][4] = {
og 0:37f6feae4997 41 {
og 0:37f6feae4997 42 {0xff, 0x00, 0xff, 0x5f},
og 0:37f6feae4997 43 {0xbf, 0x00, 0xff, 0x5f},
og 0:37f6feae4997 44 {0x7f, 0x00, 0xff, 0x5f},
og 0:37f6feae4997 45 {0x3f, 0x00, 0xff, 0x5f},
og 0:37f6feae4997 46 {0x00, 0x00, 0xff, 0x5f},
og 0:37f6feae4997 47 {0x00, 0x3f, 0xff, 0x5f},
og 0:37f6feae4997 48 {0x00, 0x7f, 0xff, 0x5f},
og 0:37f6feae4997 49 {0x00, 0xbf, 0xff, 0x5f},
og 0:37f6feae4997 50 {0x00, 0xff, 0xff, 0x5f},
og 0:37f6feae4997 51 {0x00, 0xff, 0xbf, 0x5f},
og 0:37f6feae4997 52 {0x00, 0xff, 0x7f, 0x5f},
og 0:37f6feae4997 53 {0x00, 0xff, 0x3f, 0x5f},
og 0:37f6feae4997 54 {0x00, 0xff, 0x00, 0x5f},
og 0:37f6feae4997 55 {0x3f, 0xff, 0x00, 0x5f},
og 0:37f6feae4997 56 {0x7f, 0xff, 0x00, 0x5f},
og 0:37f6feae4997 57 {0xbf, 0xff, 0x00, 0x5f},
og 0:37f6feae4997 58 {0xff, 0xff, 0x00, 0x5f},
og 0:37f6feae4997 59 {0xff, 0xbf, 0x00, 0x5f},
og 0:37f6feae4997 60 {0xff, 0x7f, 0x00, 0x5f},
og 0:37f6feae4997 61 {0xff, 0x3f, 0x00, 0x5f},
og 0:37f6feae4997 62 {0xff, 0x00, 0x00, 0x5f},
og 0:37f6feae4997 63 {0xff, 0x00, 0x3f, 0x5f},
og 0:37f6feae4997 64 {0xff, 0x00, 0x7f, 0x5f},
og 0:37f6feae4997 65 {0xff, 0x00, 0xbf, 0x5f}
og 0:37f6feae4997 66 },
og 0:37f6feae4997 67 {
og 0:37f6feae4997 68 {0xff, 0x00, 0xff, 0x50},
og 0:37f6feae4997 69 {0xbf, 0x00, 0xff, 0x50},
og 0:37f6feae4997 70 {0x7f, 0x00, 0xff, 0x50},
og 0:37f6feae4997 71 {0x3f, 0x00, 0xff, 0x50},
og 0:37f6feae4997 72 {0x00, 0x00, 0xff, 0x50},
og 0:37f6feae4997 73 {0x00, 0x3f, 0xff, 0x50},
og 0:37f6feae4997 74 {0x00, 0x7f, 0xff, 0x50},
og 0:37f6feae4997 75 {0x00, 0xbf, 0xff, 0x50},
og 0:37f6feae4997 76 {0x00, 0xff, 0xff, 0x50},
og 0:37f6feae4997 77 {0x00, 0xff, 0xbf, 0x50},
og 0:37f6feae4997 78 {0x00, 0xff, 0x7f, 0x50},
og 0:37f6feae4997 79 {0x00, 0xff, 0x3f, 0x50},
og 0:37f6feae4997 80 {0x00, 0xff, 0x00, 0x50},
og 0:37f6feae4997 81 {0x3f, 0xff, 0x00, 0x50},
og 0:37f6feae4997 82 {0x7f, 0xff, 0x00, 0x50},
og 0:37f6feae4997 83 {0xbf, 0xff, 0x00, 0x50},
og 0:37f6feae4997 84 {0xff, 0xff, 0x00, 0x50},
og 0:37f6feae4997 85 {0xff, 0xbf, 0x00, 0x50},
og 0:37f6feae4997 86 {0xff, 0x7f, 0x00, 0x50},
og 0:37f6feae4997 87 {0xff, 0x3f, 0x00, 0x50},
og 0:37f6feae4997 88 {0xff, 0x00, 0x00, 0x50},
og 0:37f6feae4997 89 {0xff, 0x00, 0x3f, 0x50},
og 0:37f6feae4997 90 {0xff, 0x00, 0x7f, 0x50},
og 0:37f6feae4997 91 {0xff, 0x00, 0xbf, 0x50}
og 0:37f6feae4997 92 },
og 0:37f6feae4997 93 {
og 0:37f6feae4997 94 {0xff, 0x00, 0x00, 0x00},
og 0:37f6feae4997 95 {0x00, 0xff, 0x00, 0x00},
og 0:37f6feae4997 96 {0x00, 0x00, 0xff, 0x00},
og 0:37f6feae4997 97 {0xff, 0x00, 0x00, 0x00},
og 0:37f6feae4997 98 {0x00, 0xff, 0x00, 0x00},
og 0:37f6feae4997 99 {0x00, 0x00, 0xff, 0x00},
og 0:37f6feae4997 100 {0xff, 0x00, 0x00, 0x00},
og 0:37f6feae4997 101 {0x00, 0xff, 0x00, 0x00},
og 0:37f6feae4997 102 {0x00, 0x00, 0xff, 0x00},
og 0:37f6feae4997 103 {0xff, 0x00, 0x00, 0x00},
og 0:37f6feae4997 104 {0x00, 0xff, 0x00, 0x00},
og 0:37f6feae4997 105 {0x00, 0x00, 0xff, 0x00},
og 0:37f6feae4997 106 {0xff, 0x00, 0x00, 0x00},
og 0:37f6feae4997 107 {0x00, 0xff, 0x00, 0x00},
og 0:37f6feae4997 108 {0x00, 0x00, 0xff, 0x00},
og 0:37f6feae4997 109 {0xff, 0x00, 0x00, 0x00},
og 0:37f6feae4997 110 {0x00, 0xff, 0x00, 0x00},
og 0:37f6feae4997 111 {0x00, 0x00, 0xff, 0x00},
og 0:37f6feae4997 112 {0xff, 0x00, 0x00, 0x00},
og 0:37f6feae4997 113 {0x00, 0xff, 0x00, 0x00},
og 0:37f6feae4997 114 {0x00, 0x00, 0xff, 0x00},
og 0:37f6feae4997 115 {0xff, 0x00, 0x00, 0x00},
og 0:37f6feae4997 116 {0x00, 0xff, 0x00, 0x00},
og 0:37f6feae4997 117 {0x00, 0x00, 0xff, 0x00}
og 0:37f6feae4997 118 },
og 0:37f6feae4997 119 {
og 0:37f6feae4997 120 {0xff, 0x00, 0x00, 0x0f},
og 0:37f6feae4997 121 {0x00, 0xff, 0x00, 0x0f},
og 0:37f6feae4997 122 {0x00, 0x00, 0xff, 0x0f},
og 0:37f6feae4997 123 {0xff, 0x00, 0x00, 0x0f},
og 0:37f6feae4997 124 {0x00, 0xff, 0x00, 0x0f},
og 0:37f6feae4997 125 {0x00, 0x00, 0xff, 0x0f},
og 0:37f6feae4997 126 {0xff, 0x00, 0x00, 0x0f},
og 0:37f6feae4997 127 {0x00, 0xff, 0x00, 0x0f},
og 0:37f6feae4997 128 {0x00, 0x00, 0xff, 0x0f},
og 0:37f6feae4997 129 {0xff, 0x00, 0x00, 0x0f},
og 0:37f6feae4997 130 {0x00, 0xff, 0x00, 0x0f},
og 0:37f6feae4997 131 {0x00, 0x00, 0xff, 0x0f},
og 0:37f6feae4997 132 {0xff, 0x00, 0x00, 0x0f},
og 0:37f6feae4997 133 {0x00, 0xff, 0x00, 0x0f},
og 0:37f6feae4997 134 {0x00, 0x00, 0xff, 0x0f},
og 0:37f6feae4997 135 {0xff, 0x00, 0x00, 0x0f},
og 0:37f6feae4997 136 {0x00, 0xff, 0x00, 0x0f},
og 0:37f6feae4997 137 {0x00, 0x00, 0xff, 0x0f},
og 0:37f6feae4997 138 {0xff, 0x00, 0x00, 0x0f},
og 0:37f6feae4997 139 {0x00, 0xff, 0x00, 0x0f},
og 0:37f6feae4997 140 {0x00, 0x00, 0xff, 0x0f},
og 0:37f6feae4997 141 {0xff, 0x00, 0x00, 0x0f},
og 0:37f6feae4997 142 {0x00, 0xff, 0x00, 0x0f},
og 0:37f6feae4997 143 {0x00, 0x00, 0xff, 0x0f}
og 0:37f6feae4997 144 }
og 0:37f6feae4997 145 };
og 1:ca6bb775aa5b 146 #define MAXPAT1 6
og 2:f76f2f14b489 147 const uint8_t PAT1[2][MAXPAT1][3] = {
og 1:ca6bb775aa5b 148 // G R B
og 1:ca6bb775aa5b 149 {{0x00, 0xff, 0xff},
og 1:ca6bb775aa5b 150 {0x00, 0x00, 0xff},
og 1:ca6bb775aa5b 151 {0xff, 0x00, 0xff},
og 1:ca6bb775aa5b 152 {0xff, 0x00, 0x00},
og 1:ca6bb775aa5b 153 {0xff, 0xff, 0x00},
og 1:ca6bb775aa5b 154 {0x00, 0xff, 0x00}},
og 1:ca6bb775aa5b 155 {{0xff, 0x00, 0x00},
og 1:ca6bb775aa5b 156 {0x00, 0xff, 0x00},
og 1:ca6bb775aa5b 157 {0x00, 0x00, 0xff},
og 1:ca6bb775aa5b 158 {0xff, 0x00, 0x00},
og 1:ca6bb775aa5b 159 {0x00, 0xff, 0x00},
og 1:ca6bb775aa5b 160 {0x00, 0x00, 0xff}}
og 1:ca6bb775aa5b 161 };
og 1:ca6bb775aa5b 162
og 0:37f6feae4997 163 int i;
og 1:ca6bb775aa5b 164 int mode;
og 2:f76f2f14b489 165 uint8_t step_color1;
og 2:f76f2f14b489 166 uint8_t dim_pat_no;
og 2:f76f2f14b489 167 uint8_t max_chip;
og 0:37f6feae4997 168
og 2:f76f2f14b489 169 void color0(uint8_t no, uint8_t loop){
og 2:f76f2f14b489 170 uint8_t step_color0;
og 2:f76f2f14b489 171 uint8_t n;
og 2:f76f2f14b489 172 uint8_t pat_no;
og 0:37f6feae4997 173 pat_no = no % DIMPATMAX;
og 1:ca6bb775aa5b 174 nju6063.check_dim();
og 2:f76f2f14b489 175 for (n = 0; n < max_chip; n++) {
og 0:37f6feae4997 176 step_color0 = i + n;
og 0:37f6feae4997 177 if (step_color0 >= MAXPAT) {
og 0:37f6feae4997 178 step_color0 = step_color0 - MAXPAT;
og 0:37f6feae4997 179 }
og 1:ca6bb775aa5b 180 nju6063.set_pwm(
og 1:ca6bb775aa5b 181 n+1,
og 0:37f6feae4997 182 PAT[pat_no][step_color0][0],
og 0:37f6feae4997 183 PAT[pat_no][step_color0][1],
og 0:37f6feae4997 184 PAT[pat_no][step_color0][2],
og 0:37f6feae4997 185 PAT[pat_no][step_color0][3]
og 0:37f6feae4997 186 );
og 0:37f6feae4997 187 }
og 2:f76f2f14b489 188 nju6063.dim_start(NJU6063_ALL);
og 0:37f6feae4997 189 i++;
og 0:37f6feae4997 190 if (i >= MAXPAT) {
og 0:37f6feae4997 191 i = 0;
og 0:37f6feae4997 192 }
og 0:37f6feae4997 193 }
og 1:ca6bb775aa5b 194 void color1(){
og 1:ca6bb775aa5b 195 nju6063.check_dim();
og 1:ca6bb775aa5b 196 nju6063.set_pwm(
og 1:ca6bb775aa5b 197 0xff,
og 1:ca6bb775aa5b 198 PAT1[0][step_color1][0],
og 1:ca6bb775aa5b 199 PAT1[0][step_color1][1],
og 1:ca6bb775aa5b 200 PAT1[0][step_color1][2],
og 1:ca6bb775aa5b 201 0x00
og 1:ca6bb775aa5b 202 );
og 2:f76f2f14b489 203 nju6063.dim_start(NJU6063_ALL);
og 1:ca6bb775aa5b 204 step_color1++;
og 1:ca6bb775aa5b 205 if (step_color1 >= MAXPAT1) {
og 1:ca6bb775aa5b 206 step_color1 = 0;
og 1:ca6bb775aa5b 207 }
og 1:ca6bb775aa5b 208 }
og 1:ca6bb775aa5b 209 void color2(uint8_t pat_no, uint8_t loop){
og 1:ca6bb775aa5b 210 int n;
og 1:ca6bb775aa5b 211 nju6063.check_dim();
og 2:f76f2f14b489 212 for (n = 0; n < max_chip; n++) {
og 2:f76f2f14b489 213 step_color1 = i + n;
og 1:ca6bb775aa5b 214 if (step_color1>= MAXPAT1) {
og 1:ca6bb775aa5b 215 step_color1 = step_color1 - MAXPAT1;
og 1:ca6bb775aa5b 216 }
og 1:ca6bb775aa5b 217 nju6063.set_pwm(
og 1:ca6bb775aa5b 218 n+1,
og 1:ca6bb775aa5b 219 PAT1[pat_no][step_color1][0],
og 1:ca6bb775aa5b 220 PAT1[pat_no][step_color1][1],
og 1:ca6bb775aa5b 221 PAT1[pat_no][step_color1][2],
og 1:ca6bb775aa5b 222 loop
og 1:ca6bb775aa5b 223 );
og 1:ca6bb775aa5b 224 }
og 2:f76f2f14b489 225 nju6063.dim_start(NJU6063_ALL);
og 2:f76f2f14b489 226 i++;
og 2:f76f2f14b489 227 if (i >= MAXPAT1) {
og 2:f76f2f14b489 228 i = 0;
og 1:ca6bb775aa5b 229 }
og 1:ca6bb775aa5b 230 }
og 1:ca6bb775aa5b 231
og 1:ca6bb775aa5b 232 /*
og 1:ca6bb775aa5b 233 SW2 SW1
og 1:ca6bb775aa5b 234 H v dim start
og 1:ca6bb775aa5b 235 L v dimpat inc
og 1:ca6bb775aa5b 236 v H pat inc
og 1:ca6bb775aa5b 237 v L pat group
og 1:ca6bb775aa5b 238 */
og 1:ca6bb775aa5b 239
og 0:37f6feae4997 240
og 0:37f6feae4997 241 int main () {
og 3:50741484f1de 242 pc.printf("NJU6063\r\n");
og 3:50741484f1de 243 sw.begin();
og 1:ca6bb775aa5b 244 dim_pat_no = 0;
og 2:f76f2f14b489 245 mode = 1;
og 1:ca6bb775aa5b 246 i = 0;
og 1:ca6bb775aa5b 247 nju6063.reset();
og 2:f76f2f14b489 248 max_chip=nju6063.set_multi_device(0x08);
og 3:50741484f1de 249 pc.printf("N %d\r\n", max_chip);
og 2:f76f2f14b489 250 //chip = MAXCHIP;
og 2:f76f2f14b489 251 nju6063.init(NJU6063_ALL, NJU6063_EN);
og 2:f76f2f14b489 252 //nju6063.set_iled(NJU6063_ALL, NJU6063_ILED1X1, NJU6063_ILED2X1, NJU6063_ILED3X1);
og 2:f76f2f14b489 253 nju6063.set_iled(NJU6063_ALL, NJU6063_ILED1X025, NJU6063_ILED2X025, NJU6063_ILED3X025);
og 2:f76f2f14b489 254 nju6063.set_pwm(NJU6063_ALL, 0x7f,0x7f,0x7f);
og 2:f76f2f14b489 255 nju6063.dim_start(NJU6063_ALL);
og 2:f76f2f14b489 256 sw.clear(0);
og 2:f76f2f14b489 257 sw.clear(1);
og 2:f76f2f14b489 258 //while(1){};
og 0:37f6feae4997 259 while(1){
og 2:f76f2f14b489 260 //printf("X %d\r\n", mode);
og 2:f76f2f14b489 261 if(sw.negedge(0)){
og 2:f76f2f14b489 262 if (sw.level(1)) {
og 1:ca6bb775aa5b 263 mode = 1;
og 1:ca6bb775aa5b 264 dim_pat_no++;
og 1:ca6bb775aa5b 265 //printf("A %d\r\n", mode);
og 1:ca6bb775aa5b 266 }else{
og 1:ca6bb775aa5b 267 mode++;
og 1:ca6bb775aa5b 268 //printf("B %d\r\n", mode);
og 1:ca6bb775aa5b 269 }
og 2:f76f2f14b489 270 sw.clear(0);
og 0:37f6feae4997 271 }
og 2:f76f2f14b489 272 if(sw.negedge(1)){
og 2:f76f2f14b489 273 if (sw.level(0)) {
og 1:ca6bb775aa5b 274 switch (mode){
og 1:ca6bb775aa5b 275 case 2: color1(); break;
og 1:ca6bb775aa5b 276 case 3: color2(0, 0x00); break;
og 1:ca6bb775aa5b 277 case 4: color2(0, 0x5f); break;
og 1:ca6bb775aa5b 278 case 5: color2(1, 0x00); break;
og 1:ca6bb775aa5b 279 case 6: color2(1, 0x5f); break;
og 1:ca6bb775aa5b 280 default: mode = 2; color1();
og 1:ca6bb775aa5b 281 }
og 1:ca6bb775aa5b 282 //printf("C %d\r\n", mode);
og 1:ca6bb775aa5b 283 }else{
og 1:ca6bb775aa5b 284 mode--;
og 1:ca6bb775aa5b 285 //printf("D %d\r\n", mode);
og 1:ca6bb775aa5b 286 }
og 2:f76f2f14b489 287 sw.clear(1);
og 1:ca6bb775aa5b 288 }
og 1:ca6bb775aa5b 289 if (mode == 1) {
og 1:ca6bb775aa5b 290 color0(dim_pat_no, 0x5f);
og 1:ca6bb775aa5b 291 //wait(0.1);
og 1:ca6bb775aa5b 292 }
og 1:ca6bb775aa5b 293 }
og 1:ca6bb775aa5b 294 }
og 1:ca6bb775aa5b 295