Smart

Dependencies:   Hexi_KW40Z

Committer:
Team_Eta_MBED
Date:
Wed Feb 28 16:34:40 2018 +0000
Revision:
0:69293b19ee19
Smart Baby Monitor Foundations

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Team_Eta_MBED 0:69293b19ee19 1 #include "mbed.h"
Team_Eta_MBED 0:69293b19ee19 2 #include "HTU21D.h"
Team_Eta_MBED 0:69293b19ee19 3 #include "Hexi_KW40Z.h"
Team_Eta_MBED 0:69293b19ee19 4 #include "Hexi_OLED_SSD1351.h"
Team_Eta_MBED 0:69293b19ee19 5 #include "images.h"
Team_Eta_MBED 0:69293b19ee19 6 #include "string.h"
Team_Eta_MBED 0:69293b19ee19 7
Team_Eta_MBED 0:69293b19ee19 8 // Pin connections
Team_Eta_MBED 0:69293b19ee19 9 DigitalOut led1(LED_GREEN); // RGB LED
Team_Eta_MBED 0:69293b19ee19 10 Serial pc(USBTX, USBRX); // Serial interface
Team_Eta_MBED 0:69293b19ee19 11 HTU21D temphumid(PTB1,PTB0); // HTU21D Sensor
Team_Eta_MBED 0:69293b19ee19 12 DigitalOut powerEN (PTB12); // Power Enable HTU21D Sensor
Team_Eta_MBED 0:69293b19ee19 13 SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // SSD1351 OLED Driver (MOSI,SCLK,POWER,CS,RST,DC)
Team_Eta_MBED 0:69293b19ee19 14
Team_Eta_MBED 0:69293b19ee19 15 /* Instantiate the Hexi KW40Z Driver (UART TX, UART RX) */
Team_Eta_MBED 0:69293b19ee19 16 KW40Z kw40z_device(PTE24, PTE25);
Team_Eta_MBED 0:69293b19ee19 17
Team_Eta_MBED 0:69293b19ee19 18 // Variables
Team_Eta_MBED 0:69293b19ee19 19 int sample_ftemp;
Team_Eta_MBED 0:69293b19ee19 20 int sample_ctemp;
Team_Eta_MBED 0:69293b19ee19 21 int sample_ktemp;
Team_Eta_MBED 0:69293b19ee19 22 int sample_humid;
Team_Eta_MBED 0:69293b19ee19 23 const uint8_t *image1; // Pointer for the image to be displayed
Team_Eta_MBED 0:69293b19ee19 24 char text[20]; // Text Buffer for dynamic value displayed
Team_Eta_MBED 0:69293b19ee19 25
Team_Eta_MBED 0:69293b19ee19 26 int main() {
Team_Eta_MBED 0:69293b19ee19 27 powerEN = 0;
Team_Eta_MBED 0:69293b19ee19 28
Team_Eta_MBED 0:69293b19ee19 29 /* Setting pointer location of the 96 by 96 pixel bitmap */
Team_Eta_MBED 0:69293b19ee19 30 image1 = TempHumid;
Team_Eta_MBED 0:69293b19ee19 31
Team_Eta_MBED 0:69293b19ee19 32 /* Turn on the backlight of the OLED Display */
Team_Eta_MBED 0:69293b19ee19 33 //oled.DimScreenON();
Team_Eta_MBED 0:69293b19ee19 34
Team_Eta_MBED 0:69293b19ee19 35 /* Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0 */
Team_Eta_MBED 0:69293b19ee19 36 oled.DrawImage(image1,0,0);
Team_Eta_MBED 0:69293b19ee19 37
Team_Eta_MBED 0:69293b19ee19 38 while(true) {
Team_Eta_MBED 0:69293b19ee19 39
Team_Eta_MBED 0:69293b19ee19 40 sample_ftemp = temphumid.sample_ftemp();
Team_Eta_MBED 0:69293b19ee19 41 printf("Temperature: %d F\n\r", sample_ftemp);
Team_Eta_MBED 0:69293b19ee19 42
Team_Eta_MBED 0:69293b19ee19 43 sample_ctemp = temphumid.sample_ctemp();
Team_Eta_MBED 0:69293b19ee19 44 printf("Temperature: %d C\n\r", sample_ctemp);
Team_Eta_MBED 0:69293b19ee19 45
Team_Eta_MBED 0:69293b19ee19 46 sample_ktemp = temphumid.sample_ktemp();
Team_Eta_MBED 0:69293b19ee19 47 printf("Temperature: %d K\n\r", sample_ktemp);
Team_Eta_MBED 0:69293b19ee19 48
Team_Eta_MBED 0:69293b19ee19 49 sample_humid = temphumid.sample_humid();
Team_Eta_MBED 0:69293b19ee19 50 printf("Humidity: %d %%\n\r", sample_humid);
Team_Eta_MBED 0:69293b19ee19 51 printf("\n\r");
Team_Eta_MBED 0:69293b19ee19 52
Team_Eta_MBED 0:69293b19ee19 53 /* Get OLED Class Default Text Properties */
Team_Eta_MBED 0:69293b19ee19 54 oled_text_properties_t textProperties = {0};
Team_Eta_MBED 0:69293b19ee19 55 oled.GetTextProperties(&textProperties);
Team_Eta_MBED 0:69293b19ee19 56
Team_Eta_MBED 0:69293b19ee19 57 /* Set text properties to white and right aligned for the dynamic text */
Team_Eta_MBED 0:69293b19ee19 58 textProperties.fontColor = COLOR_RED;
Team_Eta_MBED 0:69293b19ee19 59 textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT;
Team_Eta_MBED 0:69293b19ee19 60 oled.SetTextProperties(&textProperties);
Team_Eta_MBED 0:69293b19ee19 61
Team_Eta_MBED 0:69293b19ee19 62 /* Display Legends */
Team_Eta_MBED 0:69293b19ee19 63 strcpy((char *) text,"Temp.");
Team_Eta_MBED 0:69293b19ee19 64 oled.Label((uint8_t *)text,5,67);
Team_Eta_MBED 0:69293b19ee19 65
Team_Eta_MBED 0:69293b19ee19 66 /* Format the value */
Team_Eta_MBED 0:69293b19ee19 67 sprintf(text,"%i",sample_ftemp);
Team_Eta_MBED 0:69293b19ee19 68 /* Display time reading in 35px by 15px textbox at(x=55, y=40) */
Team_Eta_MBED 0:69293b19ee19 69 oled.TextBox((uint8_t *)text,57,67,20,15); //Increase textbox for more digits
Team_Eta_MBED 0:69293b19ee19 70
Team_Eta_MBED 0:69293b19ee19 71 /* Display Units */
Team_Eta_MBED 0:69293b19ee19 72 strcpy((char *) text,"dF");
Team_Eta_MBED 0:69293b19ee19 73 oled.Label((uint8_t *)text,80,67);
Team_Eta_MBED 0:69293b19ee19 74
Team_Eta_MBED 0:69293b19ee19 75 /* Set text properties to white and right aligned for the dynamic text */
Team_Eta_MBED 0:69293b19ee19 76 textProperties.fontColor = COLOR_BLUE;
Team_Eta_MBED 0:69293b19ee19 77 textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT;
Team_Eta_MBED 0:69293b19ee19 78 oled.SetTextProperties(&textProperties);
Team_Eta_MBED 0:69293b19ee19 79
Team_Eta_MBED 0:69293b19ee19 80 /* Display Legends */
Team_Eta_MBED 0:69293b19ee19 81 strcpy((char *) text,"Humidity");
Team_Eta_MBED 0:69293b19ee19 82 oled.Label((uint8_t *)text,5,81);
Team_Eta_MBED 0:69293b19ee19 83
Team_Eta_MBED 0:69293b19ee19 84 /* Format the value */
Team_Eta_MBED 0:69293b19ee19 85 sprintf(text,"%i",sample_humid);
Team_Eta_MBED 0:69293b19ee19 86 /* Display time reading in 35px by 15px textbox at(x=55, y=40) */
Team_Eta_MBED 0:69293b19ee19 87 oled.TextBox((uint8_t *)text,57,81,20,15); //Increase textbox for more digits
Team_Eta_MBED 0:69293b19ee19 88
Team_Eta_MBED 0:69293b19ee19 89 /* Display Units */
Team_Eta_MBED 0:69293b19ee19 90 strcpy((char *) text,"%");
Team_Eta_MBED 0:69293b19ee19 91 oled.Label((uint8_t *)text,80,81);
Team_Eta_MBED 0:69293b19ee19 92
Team_Eta_MBED 0:69293b19ee19 93 led1 = !led1;
Team_Eta_MBED 0:69293b19ee19 94 Thread::wait(1000);
Team_Eta_MBED 0:69293b19ee19 95 }
Team_Eta_MBED 0:69293b19ee19 96 }