/* * BigClown - Humidity Module * * https://chiptron.cz * https://time4ee.com * * The example code is based on https://www.bigclown.com/ * * 2018 */ #include "application.h" #define BLACK true // sht20 instance bc_sht20_t sht20; void sht20_module_event_handler(bc_sht20_t *self, bc_sht20_event_t event, void *event_param) { (void) event_param; char bufferTemp[13]; char bufferHum[13]; float temperature = 0.0; float humidity = 0.0; if (event == BC_SHT20_EVENT_UPDATE) { bc_sht20_get_temperature_celsius(self, &temperature); bc_sht20_get_humidity_percentage(self, &humidity); sprintf(bufferTemp, "%05.2f", temperature); bufferTemp[12] = '\0'; sprintf(bufferHum, "%05.2f", humidity); bufferHum[12] = '\0'; // Use big font bc_module_lcd_set_font(&bc_font_ubuntu_24); bc_module_lcd_draw_string(5, 30, &bufferTemp[0], BLACK); bc_module_lcd_draw_string(100, 30, "°C", BLACK); bc_module_lcd_draw_string(5, 55, &bufferHum[0], BLACK); bc_module_lcd_draw_string(100, 55, "%", BLACK); // Don't forget to update bc_module_lcd_update(); } else { temperature = 0.0; // Use big font bc_module_lcd_set_font(&bc_font_ubuntu_24); bc_module_lcd_draw_string(5, 30, "0.0", BLACK); // Don't forget to update bc_module_lcd_update(); } } void application_init(void) { // The parameter is internal buffer in SDK, no need to define it bc_module_lcd_init(&_bc_module_lcd_framebuffer); // sht20 initialization bc_sht20_init(&sht20, BC_I2C_I2C0, 0x40); // set update interval bc_sht20_set_update_interval(&sht20, 1000); // set evend handler (what to do when tag update is triggered) bc_sht20_set_event_handler(&sht20, sht20_module_event_handler, NULL); // Init default font, this is necessary // See other fonts in sdk/bcl/inc/bc_font_common.h bc_module_lcd_set_font(&bc_font_ubuntu_15); // Draw string at X, Y location bc_module_lcd_draw_string(10, 5, "time4ee.com", BLACK); bc_module_lcd_draw_line(5, 20, 115, 20, BLACK); // Don't forget to update bc_module_lcd_update(); }