Very advanced Click Air Quality example for Hexiwear featuring OLED Display, Bluetooth, Cloud and Touch

Dependencies:   Hexi_KW40Z Hexi_OLED_SSD1351

This project has been developed by mbed user daveyclk

This project demonstrates the use of the Mikroelektronika Click Air Quality module with hexiwear featuring the OLED display, the Bluetooth for Cloud connectivity and Touch buttons

Plug Hexiwear into the Docking Station and the Air Quality Click to the Click Socket 1
Connect the USB cable to your computer and to the micro-USB port of the Docking Station

Compile the project and copy the binary "Hexi_Click_AirQuality_Example_HEXIWEAR.bin" in the DAP-LINK drive from your computer file explorer
Press the K64F-RESET button on the docking station to start the program on your board

The OLED screen will display some graphics and the Air Quality measurement in ppm below
Blow gently on the sensor and see the value changing
Graphic displayed will move the Arrow from Green to Purple depending from the ppm value measured by the Air Quality sensor
Download the cell phone App Hexiwear from iOS or Android stores to connect your board to your phone
Type the pin displayed on the screen and give a name to your board to pair it via the App
Congratulation your data are now streamed directly to Wolkabout Cloud...
To visualize the data remotely (over cloud not bluetooth), you can go to Wolksense.com or download the Wolksense iOS/Android App and login with same account

Revision:
2:8e7d89c2cbde
Parent:
1:7b9c19276087
Child:
3:97bc87323258
--- a/main.cpp	Fri Oct 21 13:20:11 2016 +0000
+++ b/main.cpp	Mon Oct 24 15:14:39 2016 +0000
@@ -1,3 +1,5 @@
+
+
 /******************************************************************************
 * Includes
 *******************************************************************************/
@@ -5,7 +7,9 @@
 #include "mbed.h"
 #include "Hexi_OLED_SSD1351.h"
 #include "images.h"
+#include "new_images.h"
 #include "string.h"
+#include "stdbool.h"
 
 /******************************************************************************
 * Input and Output Pinout
@@ -26,9 +30,16 @@
 int value_old = 0;
 uint16_t adc_rd;
     
-const uint8_t *image1;  // Pointer for the image to be displayed
-char text[20];          // Text Buffer for dynamic value displayed
-    
+//const uint8_t *image1;          // old cover image
+const uint8_t *green_arrow;     // Pointer for the image to be displayed
+const uint8_t *yellow_arrow;    // Pointer for the image to be displayed
+const uint8_t *orange_arrow;    // Pointer for the image to be displayed
+const uint8_t *red_arrow;       // Pointer for the image to be displayed
+const uint8_t *purple_arrow;    // Pointer for the image to be displayed
+
+char text[20];                  // Text Buffer for dynamic value displayed
+
+bool test = false; // used to put the program in text mode to check images    
 
 
 /**************************************************************************************************
@@ -41,31 +52,37 @@
 
 void InitModules()
 {
-    image1  = AirQuality;         // Setting pointer location of the 96 by 96 pixel bitmap
-    oled.DrawImage(image1,0,0);     // Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0  
+    //image1  = AirQuality;         // Setting pointer location of the 96 by 96 pixel bitmap
+    //oled.DrawImage(image1,0,0);     // Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0  
+    
+    green_arrow = Green_arrow_bmp;      // Setting pointer location of the 96 by 96 pixel bitmap Arrow Point to Green To begin
+    yellow_arrow = Yellow_arrow_bmp;    // Setting pointer location of the 96 by 96 pixel bitmap
+    orange_arrow = Orange_arrow_bmp;    // Setting pointer location of the 96 by 96 pixel bitmap 
+    red_arrow = Red_arrow_bmp;          // Setting pointer location of the 96 by 96 pixel bitmap 
+    purple_arrow = Purple_arrow_bmp;    // Setting pointer location of the 96 by 96 pixel bitmap 
+    
+    oled.DrawImage(green_arrow,0,0);     // Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0 
     
     oled_text_properties_t textProperties = {0};    // Get OLED Class Default Text Properties
     oled.GetTextProperties(&textProperties); 
       
-    textProperties.fontColor = COLOR_BLUE;          // Set text properties to white and right aligned for the dynamic text
-    textProperties.alignParam = OLED_TEXT_ALIGN_LEFT;
-    oled.SetTextProperties(&textProperties);  
+    //PPM text now in the Bitmap
+   
+    //textProperties.fontColor = COLOR_BLUE;          // Set text properties to white and right aligned for the dynamic text
+    //textProperties.alignParam = OLED_TEXT_ALIGN_LEFT;
+    //oled.SetTextProperties(&textProperties);  
       
-    strcpy((char *) text,"ppm:");       // Display Legends
-    oled.Label((uint8_t *)text,15,75);      
+    //strcpy((char *) text,"ppm:");       // Display Legends
+   // oled.Label((uint8_t *)text,15,75);      
     
-    textProperties.fontColor = COLOR_BLUE;          // Set text properties to white and right aligned for the dynamic text
+    textProperties.fontColor = COLOR_WHITE;          // Set text properties to white and right aligned for the dynamic text
     textProperties.alignParam = OLED_TEXT_ALIGN_RIGHT;
     oled.SetTextProperties(&textProperties);  
 
     sprintf(text,"%i",value);                       // Format the value
-    oled.TextBox((uint8_t *)text,55,75,20,15);   //Increase textbox for more digits
+    oled.TextBox((uint8_t *)text,55,76,20,15);   //Increase textbox for more digits
       
-    /** initialize ADC */
-//    ADC0_Init();
 
-    /** pause for 100ms for ADC module stabilization */
-    wait_ms(100);
 }
 
 
@@ -123,6 +140,17 @@
     if (value_old != value)
     {
 
+        if( value > 200) 
+            oled.DrawImage(purple_arrow,0,0);     // Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0
+        else if (value < 200 && value > 150) 
+            oled.DrawImage(red_arrow,0,0);
+        else if (value < 150 && value > 100) 
+            oled.DrawImage(orange_arrow,0,0);
+        else if (value < 100 && value > 50) 
+            oled.DrawImage(yellow_arrow,0,0); 
+        else  
+            oled.DrawImage(green_arrow,0,0);
+        
         oled_text_properties_t textProperties = {0};    // Get OLED Class Default Text Properties
         oled.GetTextProperties(&textProperties); 
 
@@ -132,7 +160,7 @@
         oled.SetTextProperties(&textProperties);  
 
         sprintf(text,"%i",value_old);                       // Format the value
-        oled.TextBox((uint8_t *)text,55,75,20,15);   //Increase textbox for more digits
+        oled.TextBox((uint8_t *)text,55,76,20,15);   //Increase textbox for more digits
 
         // display the new value
         textProperties.fontColor = COLOR_WHITE;          // Set text properties to white and right aligned for the dynamic text
@@ -140,7 +168,7 @@
         oled.SetTextProperties(&textProperties);  
 
         sprintf(text,"%i",value);                       // Format the value
-        oled.TextBox((uint8_t *)text,55,75,20,15);   //Increase textbox for more digits
+        oled.TextBox((uint8_t *)text,55,76,20,15);   //Increase textbox for more digits
     }
     value_old = value;
 }
@@ -158,19 +186,36 @@
 {
 
     InitModules();
-
+    test = false; // use this to test the BMPS 
+         
+    
     while (true) 
     {
 
         ReadSensor();
         pc.printf("Sensor Value 0x%04X\n\r",ain.read_u16());
-
-        CalculatePPM();
-
-        DisplayAirQValue(ppm);
+       
+        // added a test to toggle through the images
+        if (test == true)
+        {  
+            int test_ppm = 10;
+            for( int i = 0; i < 5; i++)
+            {
+               DisplayAirQValue(test_ppm);
+               test_ppm += 50;
+               led1 = !led1;
+               Thread::wait(1000);
+            }
+        }        
+        else
+        {
         
-        led1 = !led1;
-        Thread::wait(500);
+            CalculatePPM();
+            DisplayAirQValue(ppm);
+        
+            led1 = !led1;
+            Thread::wait(500);
+        }   
 
     }
 }
\ No newline at end of file