Breathalyzer running on the MBED 1768 Platform; EE4427 Group 3 Spring 2018

Dependencies:   4DGL-uLCD-SE mbed

Committer:
phred754
Date:
Mon Apr 23 22:18:27 2018 +0000
Revision:
0:35f90b280233
EE4427 Final Project Group 3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
phred754 0:35f90b280233 1 //Written by Todd Clark
phred754 0:35f90b280233 2 #include "mbed.h"
phred754 0:35f90b280233 3 #include "lcdOut.h"
phred754 0:35f90b280233 4 #include "sensor.h"
phred754 0:35f90b280233 5 #include "light.h"
phred754 0:35f90b280233 6 #include "convertToBAC.h"
phred754 0:35f90b280233 7 #include "switch.h"
phred754 0:35f90b280233 8
phred754 0:35f90b280233 9 BusOut onboardLED {LED1,LED2,LED3,LED4};
phred754 0:35f90b280233 10 InterruptIn button(p18);
phred754 0:35f90b280233 11 Timer debounce;
phred754 0:35f90b280233 12 Ticker reset;
phred754 0:35f90b280233 13
phred754 0:35f90b280233 14 bool overLimit;
phred754 0:35f90b280233 15 bool lightsOn = false;
phred754 0:35f90b280233 16
phred754 0:35f90b280233 17 bool isOverLimit(float out, bool isUtahMode){
phred754 0:35f90b280233 18 float legalLimitBAC = (isUtahMode) ? 0.05 : 0.08;
phred754 0:35f90b280233 19 return (out < legalLimitBAC) ? false : true;
phred754 0:35f90b280233 20 }
phred754 0:35f90b280233 21
phred754 0:35f90b280233 22 void resetLights(){
phred754 0:35f90b280233 23 lightsOn = false;
phred754 0:35f90b280233 24 turnOff();
phred754 0:35f90b280233 25 resetDisplay();
phred754 0:35f90b280233 26 onboardLED = 0x0;
phred754 0:35f90b280233 27 }
phred754 0:35f90b280233 28
phred754 0:35f90b280233 29 void runTest(){
phred754 0:35f90b280233 30 reset.attach(&resetLights, 30);
phred754 0:35f90b280233 31 bool isUtahMode = getUtahMode();
phred754 0:35f90b280233 32 float input = takeReading();
phred754 0:35f90b280233 33 float out = getBAC(input);
phred754 0:35f90b280233 34 overLimit = isOverLimit(out, isUtahMode);
phred754 0:35f90b280233 35 displayOut(out, isUtahMode);
phred754 0:35f90b280233 36 }
phred754 0:35f90b280233 37
phred754 0:35f90b280233 38 void toggle(){
phred754 0:35f90b280233 39 if (debounce.read_ms()>200){
phred754 0:35f90b280233 40 runTest();
phred754 0:35f90b280233 41 lightsOn = true;
phred754 0:35f90b280233 42 debounce.reset();
phred754 0:35f90b280233 43 }
phred754 0:35f90b280233 44 }
phred754 0:35f90b280233 45
phred754 0:35f90b280233 46 void initialize(){
phred754 0:35f90b280233 47 debounce.start();
phred754 0:35f90b280233 48 button.rise(&toggle);
phred754 0:35f90b280233 49 }
phred754 0:35f90b280233 50
phred754 0:35f90b280233 51 int main(){
phred754 0:35f90b280233 52 float delay = 0.1;
phred754 0:35f90b280233 53 displayOut(-1.0, false);
phred754 0:35f90b280233 54 while(1){
phred754 0:35f90b280233 55 initialize();
phred754 0:35f90b280233 56 if(overLimit && lightsOn){
phred754 0:35f90b280233 57 changeBlue();
phred754 0:35f90b280233 58 onboardLED = 0x1;
phred754 0:35f90b280233 59 wait(delay);
phred754 0:35f90b280233 60 changeRed();
phred754 0:35f90b280233 61 onboardLED = 0x2;
phred754 0:35f90b280233 62 wait(delay);
phred754 0:35f90b280233 63 changeBlue();
phred754 0:35f90b280233 64 onboardLED = 0x4;
phred754 0:35f90b280233 65 wait(delay);
phred754 0:35f90b280233 66 changeRed();
phred754 0:35f90b280233 67 onboardLED = 0x8;
phred754 0:35f90b280233 68 }
phred754 0:35f90b280233 69 else if(lightsOn){
phred754 0:35f90b280233 70 changeGreen();
phred754 0:35f90b280233 71 onboardLED = 0x0;
phred754 0:35f90b280233 72 }
phred754 0:35f90b280233 73 else{
phred754 0:35f90b280233 74 turnOff();
phred754 0:35f90b280233 75 onboardLED = 0x0;
phred754 0:35f90b280233 76 }
phred754 0:35f90b280233 77 wait(delay);
phred754 0:35f90b280233 78 }
phred754 0:35f90b280233 79 }
phred754 0:35f90b280233 80
phred754 0:35f90b280233 81