Year Two Project ELEC 2645: Embedded Systems Project Portable Weather Station
Dependencies: BMP180 ConfigFile N5110 PowerControl beep mbed
Outputs.h@0:da2b8c7a1ec1, 2015-05-11 (annotated)
- Committer:
- OHstin
- Date:
- Mon May 11 15:25:52 2015 +0000
- Revision:
- 0:da2b8c7a1ec1
Completed Weather Station
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
OHstin | 0:da2b8c7a1ec1 | 1 | /** |
OHstin | 0:da2b8c7a1ec1 | 2 | @file Outputs.h |
OHstin | 0:da2b8c7a1ec1 | 3 | @brief Contains all the outputs required for the weather station application\n |
OHstin | 0:da2b8c7a1ec1 | 4 | @brief the outputs are N5110 LCD screen, piezo buzzer, red LED and blue LED |
OHstin | 0:da2b8c7a1ec1 | 5 | @author Augustine K Kizito |
OHstin | 0:da2b8c7a1ec1 | 6 | @date April 2015 |
OHstin | 0:da2b8c7a1ec1 | 7 | */ |
OHstin | 0:da2b8c7a1ec1 | 8 | |
OHstin | 0:da2b8c7a1ec1 | 9 | #ifndef OUTPUTS_H |
OHstin | 0:da2b8c7a1ec1 | 10 | #define OUTPUTS_H |
OHstin | 0:da2b8c7a1ec1 | 11 | |
OHstin | 0:da2b8c7a1ec1 | 12 | #include "N5110.h" |
OHstin | 0:da2b8c7a1ec1 | 13 | #include "beep.h" |
OHstin | 0:da2b8c7a1ec1 | 14 | #include "PowerControl/PowerControl.h" |
OHstin | 0:da2b8c7a1ec1 | 15 | |
OHstin | 0:da2b8c7a1ec1 | 16 | N5110 lcd(p7,p8,p9,p10,p11,p13,p26); // pwm for led backlight |
OHstin | 0:da2b8c7a1ec1 | 17 | Beep buzzer(p21); // pwm for buzzer |
OHstin | 0:da2b8c7a1ec1 | 18 | |
OHstin | 0:da2b8c7a1ec1 | 19 | DigitalOut logLed(p24); //led that turns on when logging |
OHstin | 0:da2b8c7a1ec1 | 20 | DigitalOut batStatLed(p23); // led that turns on when battery voltage is low |
OHstin | 0:da2b8c7a1ec1 | 21 | |
OHstin | 0:da2b8c7a1ec1 | 22 | Ticker batStatTimer; |
OHstin | 0:da2b8c7a1ec1 | 23 | bool batStatLedState = false; // tracks if the batStatLed is in use |
OHstin | 0:da2b8c7a1ec1 | 24 | |
OHstin | 0:da2b8c7a1ec1 | 25 | void turnOnBatStatLed() // turns on the battery status led |
OHstin | 0:da2b8c7a1ec1 | 26 | { |
OHstin | 0:da2b8c7a1ec1 | 27 | if(!batStatLedState) { // battery status led is not already on |
OHstin | 0:da2b8c7a1ec1 | 28 | // turn it on |
OHstin | 0:da2b8c7a1ec1 | 29 | batStatLed = 1; |
OHstin | 0:da2b8c7a1ec1 | 30 | // call this function every 2 seconds |
OHstin | 0:da2b8c7a1ec1 | 31 | batStatTimer.attach(&turnOnBatStatLed,2); |
OHstin | 0:da2b8c7a1ec1 | 32 | // battery status led is now in use |
OHstin | 0:da2b8c7a1ec1 | 33 | batStatLedState = true; |
OHstin | 0:da2b8c7a1ec1 | 34 | } else { // battery status led is already on |
OHstin | 0:da2b8c7a1ec1 | 35 | |
OHstin | 0:da2b8c7a1ec1 | 36 | // toggle the battery status led |
OHstin | 0:da2b8c7a1ec1 | 37 | batStatLed = !batStatLed; |
OHstin | 0:da2b8c7a1ec1 | 38 | } |
OHstin | 0:da2b8c7a1ec1 | 39 | |
OHstin | 0:da2b8c7a1ec1 | 40 | } |
OHstin | 0:da2b8c7a1ec1 | 41 | |
OHstin | 0:da2b8c7a1ec1 | 42 | void turnOffBatStatLed() // turns off the battery status led |
OHstin | 0:da2b8c7a1ec1 | 43 | { |
OHstin | 0:da2b8c7a1ec1 | 44 | // battery status led is still on |
OHstin | 0:da2b8c7a1ec1 | 45 | if (batStatLedState) { |
OHstin | 0:da2b8c7a1ec1 | 46 | // disable the interrupt that toggles the led |
OHstin | 0:da2b8c7a1ec1 | 47 | batStatTimer.detach(); |
OHstin | 0:da2b8c7a1ec1 | 48 | // the battery status led is off |
OHstin | 0:da2b8c7a1ec1 | 49 | batStatLedState = false; |
OHstin | 0:da2b8c7a1ec1 | 50 | // turn off the battery status led |
OHstin | 0:da2b8c7a1ec1 | 51 | batStatLed = 0; |
OHstin | 0:da2b8c7a1ec1 | 52 | |
OHstin | 0:da2b8c7a1ec1 | 53 | } |
OHstin | 0:da2b8c7a1ec1 | 54 | |
OHstin | 0:da2b8c7a1ec1 | 55 | } |
OHstin | 0:da2b8c7a1ec1 | 56 | |
OHstin | 0:da2b8c7a1ec1 | 57 | Ticker logLedTimer; |
OHstin | 0:da2b8c7a1ec1 | 58 | bool logLedState = false; // tracks if the log Led is in use |
OHstin | 0:da2b8c7a1ec1 | 59 | |
OHstin | 0:da2b8c7a1ec1 | 60 | void turnOnLogLed() // turns on the log led |
OHstin | 0:da2b8c7a1ec1 | 61 | { |
OHstin | 0:da2b8c7a1ec1 | 62 | if(!logLedState) { // log led is not already on |
OHstin | 0:da2b8c7a1ec1 | 63 | // turn it on |
OHstin | 0:da2b8c7a1ec1 | 64 | logLed = 1; |
OHstin | 0:da2b8c7a1ec1 | 65 | // call this function every 2 seconds |
OHstin | 0:da2b8c7a1ec1 | 66 | logLedTimer.attach(&turnOnLogLed,2); |
OHstin | 0:da2b8c7a1ec1 | 67 | // log led is now in use |
OHstin | 0:da2b8c7a1ec1 | 68 | logLedState = true; |
OHstin | 0:da2b8c7a1ec1 | 69 | } else { // log led is already on |
OHstin | 0:da2b8c7a1ec1 | 70 | |
OHstin | 0:da2b8c7a1ec1 | 71 | // toggle the log led |
OHstin | 0:da2b8c7a1ec1 | 72 | logLed = !logLed; |
OHstin | 0:da2b8c7a1ec1 | 73 | } |
OHstin | 0:da2b8c7a1ec1 | 74 | |
OHstin | 0:da2b8c7a1ec1 | 75 | } |
OHstin | 0:da2b8c7a1ec1 | 76 | |
OHstin | 0:da2b8c7a1ec1 | 77 | void turnOffLogLed() // turns off the log led |
OHstin | 0:da2b8c7a1ec1 | 78 | { |
OHstin | 0:da2b8c7a1ec1 | 79 | // log led is still on |
OHstin | 0:da2b8c7a1ec1 | 80 | if (logLedState) { |
OHstin | 0:da2b8c7a1ec1 | 81 | // disable the interrupt that toggles the led |
OHstin | 0:da2b8c7a1ec1 | 82 | logLedTimer.detach(); |
OHstin | 0:da2b8c7a1ec1 | 83 | // the log led is off |
OHstin | 0:da2b8c7a1ec1 | 84 | logLedState = false; |
OHstin | 0:da2b8c7a1ec1 | 85 | // turn off the log led |
OHstin | 0:da2b8c7a1ec1 | 86 | logLed = 0; |
OHstin | 0:da2b8c7a1ec1 | 87 | |
OHstin | 0:da2b8c7a1ec1 | 88 | } |
OHstin | 0:da2b8c7a1ec1 | 89 | |
OHstin | 0:da2b8c7a1ec1 | 90 | } |
OHstin | 0:da2b8c7a1ec1 | 91 | |
OHstin | 0:da2b8c7a1ec1 | 92 | bool soundFx = true; // variable that tracks the sound effects |
OHstin | 0:da2b8c7a1ec1 | 93 | int currentBrightness; // variable that tracks the LCD brightness |
OHstin | 0:da2b8c7a1ec1 | 94 | |
OHstin | 0:da2b8c7a1ec1 | 95 | void playSound() |
OHstin | 0:da2b8c7a1ec1 | 96 | { |
OHstin | 0:da2b8c7a1ec1 | 97 | if (soundFx) { // the sound effects are activated |
OHstin | 0:da2b8c7a1ec1 | 98 | |
OHstin | 0:da2b8c7a1ec1 | 99 | // if brightenss is at 50 or 20 % , reduce buzzer frequency. |
OHstin | 0:da2b8c7a1ec1 | 100 | // this is implemented because the above modes seem to affect the |
OHstin | 0:da2b8c7a1ec1 | 101 | // PWM signal to the LCD brightness. Reducing the buzzer frequency |
OHstin | 0:da2b8c7a1ec1 | 102 | // somewhat alleviates this problem |
OHstin | 0:da2b8c7a1ec1 | 103 | |
OHstin | 0:da2b8c7a1ec1 | 104 | if (currentBrightness == 50 || currentBrightness == 25 ) { |
OHstin | 0:da2b8c7a1ec1 | 105 | buzzer.beep(80,0.05); // sound 80kHz tone |
OHstin | 0:da2b8c7a1ec1 | 106 | |
OHstin | 0:da2b8c7a1ec1 | 107 | } else { // sound the normal 2kHz Tone |
OHstin | 0:da2b8c7a1ec1 | 108 | buzzer.beep(2000.0,0.1); |
OHstin | 0:da2b8c7a1ec1 | 109 | } |
OHstin | 0:da2b8c7a1ec1 | 110 | |
OHstin | 0:da2b8c7a1ec1 | 111 | |
OHstin | 0:da2b8c7a1ec1 | 112 | |
OHstin | 0:da2b8c7a1ec1 | 113 | } |
OHstin | 0:da2b8c7a1ec1 | 114 | |
OHstin | 0:da2b8c7a1ec1 | 115 | |
OHstin | 0:da2b8c7a1ec1 | 116 | } |
OHstin | 0:da2b8c7a1ec1 | 117 | |
OHstin | 0:da2b8c7a1ec1 | 118 | |
OHstin | 0:da2b8c7a1ec1 | 119 | #endif |