Breathalyzer running on the MBED 1768 Platform; EE4427 Group 3 Spring 2018
Dependencies: 4DGL-uLCD-SE mbed
Revision 0:35f90b280233, committed 2018-04-23
- Comitter:
- phred754
- Date:
- Mon Apr 23 22:18:27 2018 +0000
- Commit message:
- EE4427 Final Project Group 3
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/4DGL-uLCD-SE.lib Mon Apr 23 22:18:27 2018 +0000 @@ -0,0 +1,1 @@ +http://os.mbed.com/users/sparkfun/code/4DGL-uLCD-SE/#e39a44de229a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/convertToBAC.cpp Mon Apr 23 22:18:27 2018 +0000 @@ -0,0 +1,11 @@ +//Written by Todd Clark +#include "convertToBAC.h" + +float getBAC(float input){ + float voltage = input * 3; //Conversion from input resistance to voltage. + float calibratedVoltage = voltage / 0.6; //Convert voltage to work with our 3 volt output signal. + float ppm = 1033.992 + (55.84479 - 1033.992)/(1 + pow((calibratedVoltage/4.540421), 8.423297)); //Calculate ppm from our voltage values based on specs for MQ-3 gas sensor. + float bac = (ppm * 0.21) / 100; //Calculate BAC from ppm. Formula taken from http://nootropicdesign.com/projectlab/2010/09/17/arduino-breathalyzer/ + float calibratedBac = bac - 0.12; //Calibrate sensor based on value at 0% alcohol. + return (calibratedBac < 0.0) ? 0 : calibratedBac; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/convertToBAC.h Mon Apr 23 22:18:27 2018 +0000 @@ -0,0 +1,4 @@ +//Written by Todd Clark +#include "mbed.h" + +float getBAC(float input); \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lcdOut.cpp Mon Apr 23 22:18:27 2018 +0000 @@ -0,0 +1,66 @@ +//Written by Todd Clark +#include "lcdOut.h" + +uLCD_4DGL uLCD(p9,p10,p11); //Set up serial bus for LCD screen as an object using code library for LCD from https://os.mbed.com/users/sparkfun/code/4DGL-uLCD-SE/ +int textSize; +float legalLimit; + +void resetDisplay(){ + uLCD.background_color(BLACK); + uLCD.cls(); + uLCD.textbackground_color(BLACK); + displayStart(); +} + +void displayTest(float out, bool isUtahMode){ + legalLimit = (isUtahMode) ? 0.05 : 0.08; + + uLCD.baudrate(115200); + uLCD.background_color(WHITE); + uLCD.cls(); + uLCD.textbackground_color(WHITE); + + textSize = 1; + uLCD.locate(0, 1); + uLCD.text_width(textSize); + uLCD.text_height(textSize); + uLCD.color(BLACK); + uLCD.printf("Your BAC is:%.2f", out); + + uLCD.locate(0, 3); + uLCD.printf("The maximum legal limit is %.2f", legalLimit); + + uLCD.locate(0, 6); + if (out < legalLimit){ + uLCD.color(BLUE); + uLCD.printf("You are under the legal limit.", legalLimit); + } + else{ + uLCD.color(RED); + uLCD.printf("You are drunk! \nDo not Drive!"); + } +} + +void displayStart(){ + textSize = 1; + uLCD.locate(3, 1); + uLCD.text_width(textSize); + uLCD.text_height(textSize); + uLCD.color(RED); + uLCD.printf("Breathalyzer \n"); + + uLCD.locate(0, 3); + uLCD.text_width(textSize); + uLCD.text_height(textSize); + uLCD.color(BLUE); + uLCD.printf("Press button to \nconduct test\n"); +} + +void displayOut(float out, bool isUtahMode){ + if(out == -1.0){ + displayStart(); + } + else{ + displayTest(out, isUtahMode); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lcdOut.h Mon Apr 23 22:18:27 2018 +0000 @@ -0,0 +1,10 @@ +//Written by Todd Clark +#include "mbed.h" +#include "uLCD_4DGL.h" + +void displayOut(float out, bool isUtahMode); +void displayTest(float out, bool isUtahMode); +void displayStart(); +void resetDisplay(); + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/light.cpp Mon Apr 23 22:18:27 2018 +0000 @@ -0,0 +1,30 @@ +//Written by Madison Wilkey +#include "light.h" + +PwmOut led_red(p21); +PwmOut led_green(p22); +PwmOut led_blue(p23); + +void changeRed(){ + led_red.write(1.0f); + led_green.write(0.0f); + led_blue.write(0.0f); +} + +void changeBlue(){ + led_red.write(0.0f); + led_green.write(0.0f); + led_blue.write(1.0f); +} + +void changeGreen(){ + led_red.write(0.0f); + led_green.write(1.0f); + led_blue.write(0.0f); +} + +void turnOff(){ + led_red.write(0.0f); + led_green.write(0.0f); + led_blue.write(0.0f); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/light.h Mon Apr 23 22:18:27 2018 +0000 @@ -0,0 +1,8 @@ +//Written by Madison Wilkey +#include "mbed.h" + +void changeLight(bool isOverLimit); +void changeRed(); +void changeGreen(); +void changeBlue(); +void turnOff(); \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Apr 23 22:18:27 2018 +0000 @@ -0,0 +1,81 @@ +//Written by Todd Clark +#include "mbed.h" +#include "lcdOut.h" +#include "sensor.h" +#include "light.h" +#include "convertToBAC.h" +#include "switch.h" + +BusOut onboardLED {LED1,LED2,LED3,LED4}; +InterruptIn button(p18); +Timer debounce; +Ticker reset; + +bool overLimit; +bool lightsOn = false; + +bool isOverLimit(float out, bool isUtahMode){ + float legalLimitBAC = (isUtahMode) ? 0.05 : 0.08; + return (out < legalLimitBAC) ? false : true; +} + +void resetLights(){ + lightsOn = false; + turnOff(); + resetDisplay(); + onboardLED = 0x0; +} + +void runTest(){ + reset.attach(&resetLights, 30); + bool isUtahMode = getUtahMode(); + float input = takeReading(); + float out = getBAC(input); + overLimit = isOverLimit(out, isUtahMode); + displayOut(out, isUtahMode); +} + +void toggle(){ + if (debounce.read_ms()>200){ + runTest(); + lightsOn = true; + debounce.reset(); + } +} + +void initialize(){ + debounce.start(); + button.rise(&toggle); +} + +int main(){ + float delay = 0.1; + displayOut(-1.0, false); + while(1){ + initialize(); + if(overLimit && lightsOn){ + changeBlue(); + onboardLED = 0x1; + wait(delay); + changeRed(); + onboardLED = 0x2; + wait(delay); + changeBlue(); + onboardLED = 0x4; + wait(delay); + changeRed(); + onboardLED = 0x8; + } + else if(lightsOn){ + changeGreen(); + onboardLED = 0x0; + } + else{ + turnOff(); + onboardLED = 0x0; + } + wait(delay); + } +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Apr 23 22:18:27 2018 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/994bdf8177cb \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sensor.cpp Mon Apr 23 22:18:27 2018 +0000 @@ -0,0 +1,7 @@ +//Written by Madison Wilkey +#include "sensor.h" +AnalogIn sensorInput(p15); + +float takeReading(){ + return sensorInput.read(); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sensor.h Mon Apr 23 22:18:27 2018 +0000 @@ -0,0 +1,4 @@ +//Written by Madison Wilkey +#include "mbed.h" + +float takeReading(); \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/switch.cpp Mon Apr 23 22:18:27 2018 +0000 @@ -0,0 +1,8 @@ +//Written by Madison Wilkey +#include "switch.h" + +DigitalIn toggleSwitch(p5); + +bool getUtahMode(){ + return toggleSwitch; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/switch.h Mon Apr 23 22:18:27 2018 +0000 @@ -0,0 +1,4 @@ +//Written by Madison Wilkey +#include "mbed.h" + +bool getUtahMode(); \ No newline at end of file