Code for the Hexiwear sensor system. Requires an Air Quality Click, Carbon Monoxide Click, and Buzzer Click for full functionality. Currently only reads values and displays to the OLED while testing and alerting the user of present threats. Future goals are to incorporate button presses with separate screens to display the data as well as using the KW40 drivers to transmit the data. Still in early stages of development, many unnecessary files will be removed and cleaned up once final product is completed within the next month. Driver.cpp is the main driver for the program and was written for purposes of this project. All other headers and functions were found on mbed.org from other developers repositories or provided by NXP Semiconductors for purposes of this project.

Dependencies:   Hexi_KW40Z images

Revision:
0:f70b1d60f794
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pwm_tone.cpp	Wed Mar 15 19:14:55 2017 +0000
@@ -0,0 +1,136 @@
+/* Includes ------------------------------------------------------------------*/
+#include "pwm_tone.h"
+
+/* Private typedef -----------------------------------------------------------*/
+/* Private define ------------------------------------------------------------*/
+/* Private variables ---------------------------------------------------------*/
+/* Private function prototypes -----------------------------------------------*/
+/* Private functions ---------------------------------------------------------*/
+
+/**
+   * @brief     Tune Function
+   * @param  name : Choose the PwmOut
+                    period : this param is tune value. (C_3...B_5)
+                    beat : this param is beat value. (1..16) 1 means 1/16 beat
+   * @retval    None
+   */
+void Tune(PwmOut name, int period, int beat)
+{  
+    int delay;
+    
+    delay = beat*63;
+    name.period_us(period);
+    name.write(0.50f); // 50% duty cycle
+    wait_ms(delay); // 1 beat
+    name.period_us(0); // Sound off
+}
+
+/**
+   * @brief     Auto tunes Function
+   * @param  name : Choose the PwmOut
+                    period : this param is tune value. (C_3...B_5)
+                    beat : this param is beat value. (1..16) 1 means 1/16 beat
+   * @retval    None
+   */
+void Auto_tunes(PwmOut name, int period, int beat)
+{    
+    int delay;
+    
+    delay = beat*63;
+    name.period_us(period);
+    name.write(0.50f); // 50% duty cycle
+    wait_ms(delay);
+}
+
+/**
+   * @brief     Stop tunes Function
+   * @param  name : Choose the PwmOut
+   * @retval    None
+   */
+void Stop_tunes(PwmOut name)
+{
+    name.period_us(0);
+}
+
+//void buzzer(PwmOut Buzzer, int ppm, float B_4, float B_5)
+//{
+    //int counter = 0;  /* Break condition to take another measurement */
+    //if (ppm >=10 and ppm <=25) {
+        //while (1) {
+            
+           // if (led_green == 0 && led_red == 1 && led_blue == 1){
+               // led_green = 0;
+               // led_red = 0;   /* Yellow LED */
+               // led_blue = 1;
+            //} 
+
+            //else if (led_green == 0 && led_red == 0 && led_blue == 1) {
+               //     led_green = 1;
+                 //   led_red = 1;   /* Blink LED off */
+                  //  led_blue = 1;
+            //}
+            //else {
+                  //  led_green = 0;
+                  //  led_red = 0;   /* Blink LED on */
+                  //  led_blue = 1;
+            //} 
+            //counter++;
+            //wait_ms(400);
+            //if (counter >= 5)
+                //return;   /* After 20 iterations of the alarm, break */
+        //}
+    //}
+    //else if (ppm > 25 and ppm < 100) {
+       // while (1) {
+            
+            //if (led_green == 0 && led_red == 1 && led_blue == 1){
+              //  led_green = 0;
+               // led_red = 0;   /* Yellow LED */
+               // led_blue = 1;
+            //}
+            
+           // else if (led_green == 0 && led_red == 0 && led_blue == 1) {
+                 //   led_green = 1;
+                   // led_red = 1;   /* Blink LED off */
+                  //  led_blue = 1;
+            //}
+            //else {
+              //      led_green = 0;
+                //    led_red = 0;   /* Blink LED on */
+                 //   led_blue = 1;
+            //}
+         //   Tune(Buzzer, B_4, 10);
+            //counter++; 
+           // wait_ms(250);
+            //if (counter >= 5)
+                //return;   /* After 20 iterations of the alarm, break */
+       // }
+    //}
+    
+    //else if (ppm >= 100) {
+        //while (1) {
+            
+            //if (led_green == 0 && led_red == 1 && led_blue ==1){
+            //led_green = 1;
+            //led_red = 0;   /* Red LED */
+            //led_blue = 1;
+            //}
+            
+            //else if (led_green == 1 && led_red == 0 && led_blue == 1) {
+              //      led_green = 1;
+               //     led_red = 1;   /* Blink LED off */
+               //     led_blue = 1;
+            //}
+            //else {
+              //      led_green = 1;
+                //    led_red = 0;   /* Blink LED on */
+                //    led_blue = 1;
+            //}
+           // Tune(Buzzer, B_5, 5); 
+            //counter++;
+           // wait_ms(100);
+            //if (counter >= 5)
+                //return;   /* After 20 iterations of the alarm, break */
+       // }
+   // }
+//}