Vishay VEML6075 UV Sensor test program on quattro
Dependencies: TFT_fonts UniGraphic VEML6075 mbed vt100
main.cpp
00001 #include "mbed.h" 00002 #include "vt100.h" 00003 #include "quattro.h" 00004 #include "SEPS225.h" 00005 #include "Arial12x12.h" 00006 #include "Arial24x23.h" 00007 #include "Arial28x28.h" 00008 #include "font_big.h" 00009 #include "VEML6075.h" 00010 00011 #include "kinetis_raw128x128.h" 00012 00013 // dummy assign for RESET PIN 00014 #define PIN_RESET_TFT PTC5 00015 00016 #define VEML6075_I2C_ADDRESS (0x10) 00017 00018 VEML6075 *veml6075 = 0 ; 00019 00020 SEPS225 TFT(SPI_8, 10000000, 00021 PIN_OLED_MOSI, PIN_OLED_MISO, PIN_OLED_SCLK, 00022 PIN_OLED_CS, PIN_RESET_TFT, PIN_OLED_RS, "OLED SEPS225") ; 00023 00024 Serial pc(PTE0, PTE1) ; 00025 vt100 *tty = 0 ; 00026 int page = 0 ; 00027 int prevPage = 0 ; 00028 int numPages = 6 ; 00029 00030 void enableSW(void) 00031 { 00032 int3_r->enable_irq() ; 00033 int4_g->enable_irq() ; 00034 int5_b->enable_irq() ; 00035 } 00036 00037 void disableSW(void) 00038 { 00039 int3_r->disable_irq() ; 00040 int4_g->disable_irq() ; 00041 int5_b->disable_irq() ; 00042 } 00043 00044 void swRPressed(void) 00045 { 00046 int3_r->disable_irq() ; 00047 *led3_org = !(*led3_org) ; 00048 page++ ; 00049 page %= numPages ; 00050 wait(0.25) ; 00051 int3_r->enable_irq() ; 00052 } 00053 00054 void swGPressed(void) 00055 { 00056 int4_g->disable_irq() ; 00057 *led4_org = !(*led4_org) ; 00058 page = 0 ; 00059 wait(0.25) ; 00060 int4_g->enable_irq() ; 00061 } 00062 00063 void swBPressed(void) 00064 { 00065 int5_b->disable_irq() ; 00066 *led5_org = !(*led5_org) ; 00067 page-- ; 00068 if (page < 0) { 00069 page = numPages - 1 ; 00070 } 00071 wait(0.25) ; 00072 int5_b->enable_irq() ; 00073 } 00074 00075 void doLines(unsigned short color) 00076 { 00077 TFT.cls() ; 00078 for (int i = 0 ; i < 128 ; i += 8) { 00079 TFT.line(i, 0, 127-i, 127, color) ; 00080 } 00081 } 00082 00083 void doCircles(unsigned short color) 00084 { 00085 TFT.cls() ; 00086 for (int i = 0 ; i < 64 ; i+= 4) { 00087 TFT.circle(64, 64, i, color) ; 00088 } 00089 } 00090 00091 void doRects(unsigned short color) 00092 { 00093 00094 *oled_cs = 0 ; 00095 TFT.cls() ; 00096 TFT.line(32, 32, 100, 100, color) ; 00097 TFT.rect(32, 32, 100, 100, color) ; 00098 /* 00099 for (i = 0 ; i < 64 ; i += 4) { 00100 x0 = 64 - i ; 00101 x1 = 64 + i ; 00102 y0 = 64 - i ; 00103 y1 = 64 + i ; 00104 TFT.rect(x0, y0, x1, y1, color) ; 00105 } 00106 */ 00107 *oled_cs = 1 ; 00108 } 00109 00110 void doText(void) 00111 { 00112 TFT.cls() ; 00113 // *oled_cs = 0 ; 00114 // TFT.line(0, 64, 127, 64, 0xFF00) ; 00115 TFT.set_font((unsigned char*) Arial12x12); 00116 TFT.foreground(0xFFFF) ; 00117 TFT.background(0x0000) ; 00118 TFT.locate(10, 20) ; 00119 TFT.printf("MBED") ; 00120 TFT.foreground(0xFFFF); 00121 TFT.locate(20, 60) ; 00122 TFT.printf("2.8\"TFT") ; 00123 TFT.locate(20, 80) ; 00124 TFT.printf("ABCDEF") ; 00125 00126 // *oled_cs = 1 ; 00127 } 00128 00129 void doSplash(void) 00130 { 00131 TFT.cls() ; 00132 TFT.foreground(0xFFFF) ; 00133 TFT.background(0x0000) ; 00134 TFT.set_font((unsigned char*) Arial28x28); 00135 TFT.locate(5, 5) ; 00136 TFT.printf("Marubun") ; 00137 TFT.set_font((unsigned char*) Arial12x12); 00138 TFT.locate(35, 40) ; 00139 TFT.printf("quattro-II") ; 00140 TFT.locate(50, 60) ; 00141 TFT.printf("&") ; 00142 TFT.locate(40, 80) ; 00143 TFT.printf("shaft-II") ; 00144 TFT.foreground(0xFD20) ; 00145 TFT.set_font((unsigned char*) Arial24x23); 00146 TFT.locate(10, 100) ; 00147 TFT.printf("Kinetis") ; 00148 TFT.foreground(0xFFFF) ; 00149 TFT.set_font((unsigned char*) Arial12x12); 00150 } 00151 00152 void doPict(unsigned short pict[]) 00153 { 00154 int x, y ; 00155 TFT.display(0) ; 00156 // TFT.window(0, 0, 127, 127) ; 00157 TFT.cls() ; 00158 for (y = 0 ; y < 128 ; y++ ) { 00159 for (x = 0 ; x < 128 ; x++ ) { 00160 TFT.pixel(x, y, pict[128*y + x]) ; 00161 } 00162 } 00163 // TFT.window_pushpixelbuf(pict, 128*128) ; 00164 TFT.display(1) ; 00165 } 00166 00167 void init_sensors(void) 00168 { 00169 veml6075 = new VEML6075(PTB3, PTB2, VEML6075_I2C_ADDRESS) ; // for FRDM-K22F 00170 veml6075->setUVConf(0x00) ; 00171 // veml6040 = new VEML6040(PTB3, PTB2, VEML6040_I2C_ADDRESS) ; // for FRDM-K22F 00172 // veml6040->setCOLORConf(0x00) ; 00173 } 00174 00175 void reportVEML6075(VEML6075 *veml,int x, int y) 00176 { 00177 uint8_t uvconf = 0x00 ; 00178 uint16_t id = 0 ; 00179 uint16_t uvadata = 0 ; 00180 uint16_t uvbdata = 0 ; 00181 uint16_t uvcomp1data = 0 ; 00182 uint16_t uvcomp2data = 0 ; 00183 float fUVA = 0.0 ; 00184 float fUVA_CIE = 0.0 ; 00185 float fUVB = 0.0 ; 00186 float fUVB_CIE = 0.0 ; 00187 float uvi = 0 ; 00188 00189 veml->setUVConf(uvconf) ; 00190 veml->getUVConf(&uvconf) ; 00191 veml->getID(&id) ; 00192 00193 veml->getUVAData(&uvadata) ; 00194 veml->getUVBData(&uvbdata) ; 00195 veml->getUVCOMP1Data(&uvcomp1data) ; 00196 veml->getUVCOMP2Data(&uvcomp2data) ; 00197 fUVA = veml->getUVA() ; 00198 fUVA_CIE = veml->getUVA_CIE() ; 00199 fUVB = veml->getUVB() ; 00200 fUVB_CIE = veml->getUVB_CIE() ; 00201 uvi = veml->UVI() ; 00202 00203 TFT.foreground(White); 00204 TFT.locate(x+30, y) ; 00205 TFT.printf("VEML6075\n") ; 00206 TFT.locate(x, y+10) ; 00207 TFT.printf("ID = 0x%04X\n", id) ; 00208 TFT.locate(x, y+20) ; 00209 TFT.printf("uvconf = 0x%02X\n", uvconf) ; 00210 TFT.locate(x, y+40) ; 00211 TFT.printf("UVLED:NCSU033X\n") ; 00212 TFT.locate(x, y+50) ; 00213 TFT.printf("UVA [%08.2f uW/cm2]\n", fUVA ) ; 00214 // TFT.locate(x, y+50) ; 00215 // TFT.printf("UVA [%.7f W/m2]\n", fUVA_CIE ) ; 00216 TFT.locate(x, y+70) ; 00217 TFT.printf("UVLED:UVTOP310TO39HS\n") ; 00218 TFT.locate(x, y+80) ; 00219 TFT.printf("UVB [%08.2f uW/cm2]\n", fUVB ) ; 00220 // TFT.locate(x, y+80) ; 00221 // TFT.printf("UVB [%.7f W/m2]\n", fUVB_CIE ) ; 00222 TFT.locate(x, y+100) ; 00223 if (uvi >= 8.0 ) 00224 TFT.foreground(Red); 00225 else if (uvi < 8.0 && uvi > 3.0 ) 00226 TFT.foreground(Yellow); 00227 else 00228 TFT.foreground(White); 00229 // TFT.printf("UVI [ %.1f ] for Demo\n", uvi ) ; // For demo 00230 TFT.printf("UVI [ %.1f ] \n", uvi ) ; 00231 // TFT.printf("comp1 [ %6d ]", uvcomp1data) ; 00232 // TFT.printf("comp2 [ %6d ]", uvcomp2data) ; 00233 } 00234 00235 void doReportVeml(void) 00236 { 00237 if (prevPage != page) { 00238 TFT.cls() ; 00239 wait(0.5) ; 00240 } 00241 TFT.set_font((unsigned char*) Terminal6x8); 00242 reportVEML6075(veml6075, 5, 10) ; 00243 // reportVEML6040(veml6040, 5, 10) ; 00244 } 00245 00246 double clip(double src) 00247 { 00248 double value ; 00249 value = src ; 00250 if (value < 0.0) { 00251 value = 0.0 ; 00252 } else if (value > 2.0) { 00253 value = 2.0 ; 00254 } 00255 return( value ) ; 00256 } 00257 00258 void updatePage(void) 00259 { 00260 switch(page) { 00261 case 0: // splash 00262 if (page != prevPage) { 00263 doSplash() ; 00264 } 00265 break ; 00266 case 1: 00267 if (page != prevPage) { 00268 doPict(kinetis_logo) ; 00269 } 00270 break ; 00271 case 2: 00272 doReportVeml() ; 00273 // if (page != prevPage) { 00274 // doPict(ojizo) ; 00275 // } 00276 break ; 00277 default: 00278 page = 0 ; 00279 doPict(kinetis_logo) ; 00280 break ; 00281 } 00282 prevPage = page ; 00283 } 00284 00285 int main() 00286 { 00287 oled_cs = new DigitalOut(PIN_OLED_CS, 1) ; 00288 oled_rs = new DigitalOut(PIN_OLED_RS, 1) ; 00289 tty = new vt100() ; 00290 tty->cls() ; 00291 00292 init_quattro() ; 00293 int3_r->fall(swRPressed) ; 00294 int4_g->fall(swGPressed) ; 00295 int5_b->fall(swBPressed) ; 00296 00297 init_sensors() ; 00298 00299 printf("quattro (%s)\n\r", __DATE__) ; 00300 TFT.set_font((unsigned char*) Arial12x12); 00301 TFT.window(0,0,128,128) ; 00302 00303 doSplash() ; 00304 page = 0 ; 00305 prevPage = 0 ; 00306 TFT.display(1) ; 00307 00308 wait(1) ; 00309 while(1) { 00310 disableSW() ; 00311 updatePage() ; 00312 enableSW() ; 00313 wait(0.1) ; 00314 } 00315 }
Generated on Wed Jul 13 2022 02:58:53 by
1.7.2