NJU6063 http://www.njr.com/semicon/products/NJU6063.html
Dependencies: NJU6063 Switch mbed
main.cpp
00001 #include "mbed.h" 00002 #include "NJU6063.h" 00003 #include "Switch.h" 00004 /** 00005 * STM32 I2C dont'work after Nack. 00006 */ 00007 //#ifdef TARGET_ARCH_PRO 00008 #ifdef TARGET_ARCH_PRO 00009 Serial pc(USBTX, USBRX); 00010 NJU6063 nju6063(p28, p27, P0_4); // sda scl rst 00011 Switch sw(P2_0, P2_1); // 00012 #elif defined TARGET_LPC1768 00013 // mbed LPC1114FN28 00014 Serial pc(USBTX, USBRX); 00015 NJU6063 nju6063(p9, p10, p7); // sda scl rst 00016 Switch sw(p15,p16); // 00017 #elif defined TARGET_LPC1114 00018 // mbed LPC1114FN28 00019 //Serial pc(dp16, dp15); 00020 NJU6063 nju6063(dp5, dp27, dp18); // sda scl rst 00021 Switch sw(dp17,dp14); // 00022 #elif defined TARGET_LPC11U35_501 00023 //Serial pc(p19, p18); 00024 NJU6063 nju6063(p28, p27, p25); // sda scl rst 00025 Switch sw(p11,p12); // 00026 #elif defined TARGET_NUCLEO_F401RE 00027 NJU6063 nju6063(I2C_SDA, I2C_SCL, PA_10); // sda scl rst 00028 Switch sw(PA_0, PA_1); // 00029 Serial pc(SERIAL_TX, SERIAL_RX); 00030 //#elif defined TARGET_NUCLEO_F042K6 00031 //NJU6063 nju6063(PB_7, PB_6, PB_1); // sda scl rst 00032 //Switch sw(PA_0, PA_1); // 00033 //Serial pc(SERIAL_TX, SERIAL_RX); 00034 #endif 00035 00036 #define MAXCHIP 8 00037 #define DIMPATMAX 4 00038 #define MAXPAT 24 00039 00040 const uint8_t PAT[DIMPATMAX][MAXPAT][4] = { 00041 { 00042 {0xff, 0x00, 0xff, 0x5f}, 00043 {0xbf, 0x00, 0xff, 0x5f}, 00044 {0x7f, 0x00, 0xff, 0x5f}, 00045 {0x3f, 0x00, 0xff, 0x5f}, 00046 {0x00, 0x00, 0xff, 0x5f}, 00047 {0x00, 0x3f, 0xff, 0x5f}, 00048 {0x00, 0x7f, 0xff, 0x5f}, 00049 {0x00, 0xbf, 0xff, 0x5f}, 00050 {0x00, 0xff, 0xff, 0x5f}, 00051 {0x00, 0xff, 0xbf, 0x5f}, 00052 {0x00, 0xff, 0x7f, 0x5f}, 00053 {0x00, 0xff, 0x3f, 0x5f}, 00054 {0x00, 0xff, 0x00, 0x5f}, 00055 {0x3f, 0xff, 0x00, 0x5f}, 00056 {0x7f, 0xff, 0x00, 0x5f}, 00057 {0xbf, 0xff, 0x00, 0x5f}, 00058 {0xff, 0xff, 0x00, 0x5f}, 00059 {0xff, 0xbf, 0x00, 0x5f}, 00060 {0xff, 0x7f, 0x00, 0x5f}, 00061 {0xff, 0x3f, 0x00, 0x5f}, 00062 {0xff, 0x00, 0x00, 0x5f}, 00063 {0xff, 0x00, 0x3f, 0x5f}, 00064 {0xff, 0x00, 0x7f, 0x5f}, 00065 {0xff, 0x00, 0xbf, 0x5f} 00066 }, 00067 { 00068 {0xff, 0x00, 0xff, 0x50}, 00069 {0xbf, 0x00, 0xff, 0x50}, 00070 {0x7f, 0x00, 0xff, 0x50}, 00071 {0x3f, 0x00, 0xff, 0x50}, 00072 {0x00, 0x00, 0xff, 0x50}, 00073 {0x00, 0x3f, 0xff, 0x50}, 00074 {0x00, 0x7f, 0xff, 0x50}, 00075 {0x00, 0xbf, 0xff, 0x50}, 00076 {0x00, 0xff, 0xff, 0x50}, 00077 {0x00, 0xff, 0xbf, 0x50}, 00078 {0x00, 0xff, 0x7f, 0x50}, 00079 {0x00, 0xff, 0x3f, 0x50}, 00080 {0x00, 0xff, 0x00, 0x50}, 00081 {0x3f, 0xff, 0x00, 0x50}, 00082 {0x7f, 0xff, 0x00, 0x50}, 00083 {0xbf, 0xff, 0x00, 0x50}, 00084 {0xff, 0xff, 0x00, 0x50}, 00085 {0xff, 0xbf, 0x00, 0x50}, 00086 {0xff, 0x7f, 0x00, 0x50}, 00087 {0xff, 0x3f, 0x00, 0x50}, 00088 {0xff, 0x00, 0x00, 0x50}, 00089 {0xff, 0x00, 0x3f, 0x50}, 00090 {0xff, 0x00, 0x7f, 0x50}, 00091 {0xff, 0x00, 0xbf, 0x50} 00092 }, 00093 { 00094 {0xff, 0x00, 0x00, 0x00}, 00095 {0x00, 0xff, 0x00, 0x00}, 00096 {0x00, 0x00, 0xff, 0x00}, 00097 {0xff, 0x00, 0x00, 0x00}, 00098 {0x00, 0xff, 0x00, 0x00}, 00099 {0x00, 0x00, 0xff, 0x00}, 00100 {0xff, 0x00, 0x00, 0x00}, 00101 {0x00, 0xff, 0x00, 0x00}, 00102 {0x00, 0x00, 0xff, 0x00}, 00103 {0xff, 0x00, 0x00, 0x00}, 00104 {0x00, 0xff, 0x00, 0x00}, 00105 {0x00, 0x00, 0xff, 0x00}, 00106 {0xff, 0x00, 0x00, 0x00}, 00107 {0x00, 0xff, 0x00, 0x00}, 00108 {0x00, 0x00, 0xff, 0x00}, 00109 {0xff, 0x00, 0x00, 0x00}, 00110 {0x00, 0xff, 0x00, 0x00}, 00111 {0x00, 0x00, 0xff, 0x00}, 00112 {0xff, 0x00, 0x00, 0x00}, 00113 {0x00, 0xff, 0x00, 0x00}, 00114 {0x00, 0x00, 0xff, 0x00}, 00115 {0xff, 0x00, 0x00, 0x00}, 00116 {0x00, 0xff, 0x00, 0x00}, 00117 {0x00, 0x00, 0xff, 0x00} 00118 }, 00119 { 00120 {0xff, 0x00, 0x00, 0x0f}, 00121 {0x00, 0xff, 0x00, 0x0f}, 00122 {0x00, 0x00, 0xff, 0x0f}, 00123 {0xff, 0x00, 0x00, 0x0f}, 00124 {0x00, 0xff, 0x00, 0x0f}, 00125 {0x00, 0x00, 0xff, 0x0f}, 00126 {0xff, 0x00, 0x00, 0x0f}, 00127 {0x00, 0xff, 0x00, 0x0f}, 00128 {0x00, 0x00, 0xff, 0x0f}, 00129 {0xff, 0x00, 0x00, 0x0f}, 00130 {0x00, 0xff, 0x00, 0x0f}, 00131 {0x00, 0x00, 0xff, 0x0f}, 00132 {0xff, 0x00, 0x00, 0x0f}, 00133 {0x00, 0xff, 0x00, 0x0f}, 00134 {0x00, 0x00, 0xff, 0x0f}, 00135 {0xff, 0x00, 0x00, 0x0f}, 00136 {0x00, 0xff, 0x00, 0x0f}, 00137 {0x00, 0x00, 0xff, 0x0f}, 00138 {0xff, 0x00, 0x00, 0x0f}, 00139 {0x00, 0xff, 0x00, 0x0f}, 00140 {0x00, 0x00, 0xff, 0x0f}, 00141 {0xff, 0x00, 0x00, 0x0f}, 00142 {0x00, 0xff, 0x00, 0x0f}, 00143 {0x00, 0x00, 0xff, 0x0f} 00144 } 00145 }; 00146 #define MAXPAT1 6 00147 const uint8_t PAT1[2][MAXPAT1][3] = { 00148 // G R B 00149 {{0x00, 0xff, 0xff}, 00150 {0x00, 0x00, 0xff}, 00151 {0xff, 0x00, 0xff}, 00152 {0xff, 0x00, 0x00}, 00153 {0xff, 0xff, 0x00}, 00154 {0x00, 0xff, 0x00}}, 00155 {{0xff, 0x00, 0x00}, 00156 {0x00, 0xff, 0x00}, 00157 {0x00, 0x00, 0xff}, 00158 {0xff, 0x00, 0x00}, 00159 {0x00, 0xff, 0x00}, 00160 {0x00, 0x00, 0xff}} 00161 }; 00162 00163 int i; 00164 int mode; 00165 uint8_t step_color1; 00166 uint8_t dim_pat_no; 00167 uint8_t max_chip; 00168 00169 void color0(uint8_t no, uint8_t loop){ 00170 uint8_t step_color0; 00171 uint8_t n; 00172 uint8_t pat_no; 00173 pat_no = no % DIMPATMAX; 00174 nju6063.check_dim(); 00175 for (n = 0; n < max_chip; n++) { 00176 step_color0 = i + n; 00177 if (step_color0 >= MAXPAT) { 00178 step_color0 = step_color0 - MAXPAT; 00179 } 00180 nju6063.set_pwm( 00181 n+1, 00182 PAT[pat_no][step_color0][0], 00183 PAT[pat_no][step_color0][1], 00184 PAT[pat_no][step_color0][2], 00185 PAT[pat_no][step_color0][3] 00186 ); 00187 } 00188 nju6063.dim_start(NJU6063_ALL); 00189 i++; 00190 if (i >= MAXPAT) { 00191 i = 0; 00192 } 00193 } 00194 void color1(){ 00195 nju6063.check_dim(); 00196 nju6063.set_pwm( 00197 0xff, 00198 PAT1[0][step_color1][0], 00199 PAT1[0][step_color1][1], 00200 PAT1[0][step_color1][2], 00201 0x00 00202 ); 00203 nju6063.dim_start(NJU6063_ALL); 00204 step_color1++; 00205 if (step_color1 >= MAXPAT1) { 00206 step_color1 = 0; 00207 } 00208 } 00209 void color2(uint8_t pat_no, uint8_t loop){ 00210 int n; 00211 nju6063.check_dim(); 00212 for (n = 0; n < max_chip; n++) { 00213 step_color1 = i + n; 00214 if (step_color1>= MAXPAT1) { 00215 step_color1 = step_color1 - MAXPAT1; 00216 } 00217 nju6063.set_pwm( 00218 n+1, 00219 PAT1[pat_no][step_color1][0], 00220 PAT1[pat_no][step_color1][1], 00221 PAT1[pat_no][step_color1][2], 00222 loop 00223 ); 00224 } 00225 nju6063.dim_start(NJU6063_ALL); 00226 i++; 00227 if (i >= MAXPAT1) { 00228 i = 0; 00229 } 00230 } 00231 00232 /* 00233 SW2 SW1 00234 H v dim start 00235 L v dimpat inc 00236 v H pat inc 00237 v L pat group 00238 */ 00239 00240 00241 int main () { 00242 pc.printf("NJU6063\r\n"); 00243 sw.begin(); 00244 dim_pat_no = 0; 00245 mode = 1; 00246 i = 0; 00247 nju6063.reset(); 00248 max_chip=nju6063.set_multi_device(0x08); 00249 pc.printf("N %d\r\n", max_chip); 00250 //chip = MAXCHIP; 00251 nju6063.init(NJU6063_ALL, NJU6063_EN); 00252 //nju6063.set_iled(NJU6063_ALL, NJU6063_ILED1X1, NJU6063_ILED2X1, NJU6063_ILED3X1); 00253 nju6063.set_iled(NJU6063_ALL, NJU6063_ILED1X025, NJU6063_ILED2X025, NJU6063_ILED3X025); 00254 nju6063.set_pwm(NJU6063_ALL, 0x7f,0x7f,0x7f); 00255 nju6063.dim_start(NJU6063_ALL); 00256 sw.clear(0); 00257 sw.clear(1); 00258 //while(1){}; 00259 while(1){ 00260 //printf("X %d\r\n", mode); 00261 if(sw.negedge(0)){ 00262 if (sw.level(1)) { 00263 mode = 1; 00264 dim_pat_no++; 00265 //printf("A %d\r\n", mode); 00266 }else{ 00267 mode++; 00268 //printf("B %d\r\n", mode); 00269 } 00270 sw.clear(0); 00271 } 00272 if(sw.negedge(1)){ 00273 if (sw.level(0)) { 00274 switch (mode){ 00275 case 2: color1(); break; 00276 case 3: color2(0, 0x00); break; 00277 case 4: color2(0, 0x5f); break; 00278 case 5: color2(1, 0x00); break; 00279 case 6: color2(1, 0x5f); break; 00280 default: mode = 2; color1(); 00281 } 00282 //printf("C %d\r\n", mode); 00283 }else{ 00284 mode--; 00285 //printf("D %d\r\n", mode); 00286 } 00287 sw.clear(1); 00288 } 00289 if (mode == 1) { 00290 color0(dim_pat_no, 0x5f); 00291 //wait(0.1); 00292 } 00293 } 00294 } 00295
Generated on Tue Jul 19 2022 11:37:58 by 1.7.2