![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Breathalyzer running on the MBED 1768 Platform; EE4427 Group 3 Spring 2018
Dependencies: 4DGL-uLCD-SE mbed
Diff: main.cpp
- Revision:
- 0:35f90b280233
diff -r 000000000000 -r 35f90b280233 main.cpp --- /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); + } +} + +