Advanced temperature and humidity program example for Hexiwear featuring OLED Display
Dependencies: Hexi_OLED_SSD1351
main.cpp
00001 #include "mbed.h" 00002 #include "HTU21D.h" 00003 #include "Hexi_OLED_SSD1351.h" 00004 #include "images.h" 00005 #include "string.h" 00006 00007 // Pin connections 00008 DigitalOut led1(LED_GREEN); // RGB LED 00009 Serial pc(USBTX, USBRX); // Serial interface 00010 HTU21D temphumid(PTB1,PTB0); // HTU21D Sensor 00011 DigitalOut powerEN (PTB12); // Power Enable HTU21D Sensor 00012 SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // SSD1351 OLED Driver (MOSI,SCLK,POWER,CS,RST,DC) 00013 00014 // Variables 00015 int sample_ftemp; 00016 int sample_ctemp; 00017 int sample_ktemp; 00018 int sample_humid; 00019 const uint8_t *image1; // Pointer for the image to be displayed 00020 char text[20]; // Text Buffer for dynamic value displayed 00021 00022 int main() { 00023 powerEN = 0; 00024 00025 /* Setting pointer location of the 96 by 96 pixel bitmap */ 00026 image1 = TempHumid; 00027 00028 /* Turn on the backlight of the OLED Display */ 00029 // oled.DimScreenON(); 00030 00031 /* Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0 */ 00032 oled.DrawImage(image1,0,0); 00033 00034 while(true) { 00035 00036 sample_ftemp = temphumid.sample_ftemp(); 00037 printf("Temperature: %d F\n\r", sample_ftemp); 00038 00039 sample_ctemp = temphumid.sample_ctemp(); 00040 printf("Temperature: %d C\n\r", sample_ctemp); 00041 00042 sample_ktemp = temphumid.sample_ktemp(); 00043 printf("Temperature: %d K\n\r", sample_ktemp); 00044 00045 sample_humid = temphumid.sample_humid(); 00046 printf("Humidity: %d %%\n\r", sample_humid); 00047 printf("\n\r"); 00048 00049 /* Get OLED Class Default Text Properties */ 00050 oled_text_properties_t textProperties = {0}; 00051 oled.GetTextProperties(&textProperties); 00052 00053 /* Set text properties to white and right aligned for the dynamic text */ 00054 textProperties.fontColor = COLOR_RED; 00055 textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT; 00056 oled.SetTextProperties(&textProperties); 00057 00058 /* Display Legends */ 00059 strcpy((char *) text,"Temp."); 00060 oled.Label((uint8_t *)text,5,67); 00061 00062 /* Format the value */ 00063 sprintf(text,"%i",sample_ctemp); 00064 /* Display time reading in 35px by 15px textbox at(x=55, y=40) */ 00065 oled.TextBox((uint8_t *)text,57,67,20,15); //Increase textbox for more digits 00066 00067 /* Display Units */ 00068 strcpy((char *) text,"dC"); 00069 oled.Label((uint8_t *)text,82,67); 00070 00071 /* Set text properties to white and right aligned for the dynamic text */ 00072 textProperties.fontColor = COLOR_BLUE; 00073 textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT; 00074 oled.SetTextProperties(&textProperties); 00075 00076 /* Display Legends */ 00077 strcpy((char *) text,"Humidity"); 00078 oled.Label((uint8_t *)text,5,81); 00079 00080 /* Format the value */ 00081 sprintf(text,"%i",sample_humid); 00082 /* Display time reading in 35px by 15px textbox at(x=55, y=40) */ 00083 oled.TextBox((uint8_t *)text,57,81,20,15); //Increase textbox for more digits 00084 00085 /* Display Units */ 00086 strcpy((char *) text,"%"); 00087 oled.Label((uint8_t *)text,82,81); 00088 00089 led1 = !led1; 00090 Thread::wait(500); 00091 } 00092 }
Generated on Sun Jul 17 2022 12:24:18 by 1.7.2