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

Dependencies:   NJU6063 Switch mbed

Committer:
og
Date:
Mon Jan 18 05:07:46 2016 +0000
Revision:
2:f76f2f14b489
Parent:
1:ca6bb775aa5b
Child:
3:50741484f1de
beta;

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