Using Hexiware, Hexiware dock and an Alcohol click board, create your own breathalizer that connects to Wolksense to record your readings
Dependencies: Hexi_KW40Z Hexi_OLED_SSD1351
Fork of Hexi_OLED_Text_Example by
Diff: main.cpp
- Revision:
- 6:7f4ba36b025f
- Parent:
- 5:a27fdb811237
--- a/main.cpp Tue Sep 27 09:27:06 2016 +0000 +++ b/main.cpp Tue Sep 27 10:23:28 2016 +0000 @@ -84,7 +84,9 @@ text3[20]; float value[20], // initial sensor set up values - value1[20]; // initial sensor set up values + value1[20]; // initial sensor set up values + +bool isFirstBoot = true; /****************************************************************************** @@ -103,18 +105,17 @@ /****************************************************************************** * Instance setups *******************************************************************************/ +/* Define timer for haptic feedback */ +RtosTimer hapticTimer(StopHaptic, osTimerOnce); + +//set up Analog read pin for alcohol sensor +AnalogIn Alcohol(PTB2); /* Instantiate the SSD1351 OLED Driver */ SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); /* (MOSI,SCLK,POWER,CS,RST,DC) */ /* Get OLED Class Default Text Properties */ oled_text_properties_t textProperties = {0}; - -//set up Analog read pin for alcohol sensor -AnalogIn Alcohol(PTB2); - -/* Define timer for haptic feedback */ -RtosTimer hapticTimer(StopHaptic, osTimerOnce); /* Instantiate the Hexi KW40Z Driver (UART TX, UART RX) */ KW40Z kw40z_device(PTE24, PTE25); @@ -175,7 +176,7 @@ hang = iBreatheHang_bmp; // You'll have a hangover image ini = iBreatheini_bmp; // Initialising image sober = iBreatheSober_bmp; // Sober as a judge image - + /* Set initial Values */ sysinit(); } @@ -341,6 +342,9 @@ void ButtonUp(void) { StartHaptic(); + + bool Ref = false; + bool Test = true; /* LED set to green for test beginning*/ redLed = LED_OFF; @@ -350,15 +354,25 @@ /* Fill 96px by 96px Screen with 96px by 96px Initialising Image starting at x=0,y=0 */ oled.DrawImage(ini,0,0); + /* first boot bug work around to stop junk values */ + if (isFirstBoot == true) + { + /*read ambient atmosphere levels with 10 samples and set flag to show it's ambient basline figure*/ + ambient(1); + CalculatePPM(1,Ref); + isFirstBoot = false; + } + /*read ambient atmosphere levels with 10 samples and set flag to show it's ambient basline figure*/ ambient(10); - CalculatePPM(10,false); + CalculatePPM(10,Ref); + /* Fill 96px by 96px Screen with 96px by 96px Blowing Image starting at x=0,y=0 */ oled.DrawImage(blow,0,0); /*read breathe alcohol levels with 10 samples and set flag to show it's breathilyzer test figure*/ - CalculatePPM(10,true); + CalculatePPM(10,Test); /*Calculate the difference in Alcohol level based on Ambient and test sample*/ ppm = ppm - ppm_1;