Sensor Data - first assignment CO838
Dependencies: mbed C12832 FXOS8700Q LM75B eCompass_FPU_Lib
Sensor Data - Project developed by Jean-Paul Saysana (jls44)
First assignment for the Internet of Things and Mobile Devices CO838 module
University of Kent (2016-2017)
Functionalities:
- Temperature Sensor
- Compass
- Music box
- Potentiometer that changes LED colours
Libraries used: C12832, eCompass_FPU_Lib, FXOS8700Q, LM75B
src/TemperatureSensor.cpp@1:c54902f21aa8, 2017-02-24 (annotated)
- Committer:
- co838_jls44
- Date:
- Fri Feb 24 14:33:41 2017 +0000
- Revision:
- 1:c54902f21aa8
- Parent:
- 0:4b83b332b327
comment about the playnote method
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
co838_jls44 | 0:4b83b332b327 | 1 | #include "TemperatureSensor.h" |
co838_jls44 | 0:4b83b332b327 | 2 | |
co838_jls44 | 0:4b83b332b327 | 3 | /* Instanciate the global object of LM75B which can read the temperature */ |
co838_jls44 | 0:4b83b332b327 | 4 | LM75B g_lm75b(D14, D15); |
co838_jls44 | 0:4b83b332b327 | 5 | |
co838_jls44 | 0:4b83b332b327 | 6 | TemperatureSensor::TemperatureSensor() : temp_mode(CELSIUS) { |
co838_jls44 | 0:4b83b332b327 | 7 | } |
co838_jls44 | 0:4b83b332b327 | 8 | |
co838_jls44 | 0:4b83b332b327 | 9 | /* Get the ambiant temperature */ |
co838_jls44 | 0:4b83b332b327 | 10 | float TemperatureSensor::GetTemperature() const { |
co838_jls44 | 0:4b83b332b327 | 11 | /* Read temperature */ |
co838_jls44 | 0:4b83b332b327 | 12 | float temperature = g_lm75b.read(); |
co838_jls44 | 0:4b83b332b327 | 13 | /* If the temperature sensor is set in Fahrenheit */ |
co838_jls44 | 0:4b83b332b327 | 14 | if (temp_mode == FAHRENHEIT) { |
co838_jls44 | 0:4b83b332b327 | 15 | /* Convert the Celsius in Fahrenheit. */ |
co838_jls44 | 0:4b83b332b327 | 16 | temperature = temperature * (9.0/5.0) + 32.0; |
co838_jls44 | 0:4b83b332b327 | 17 | } |
co838_jls44 | 0:4b83b332b327 | 18 | /* Return temperature */ |
co838_jls44 | 0:4b83b332b327 | 19 | return temperature; |
co838_jls44 | 0:4b83b332b327 | 20 | } |
co838_jls44 | 0:4b83b332b327 | 21 | |
co838_jls44 | 0:4b83b332b327 | 22 | /* Switch temperature mode */ |
co838_jls44 | 0:4b83b332b327 | 23 | void TemperatureSensor::SwitchMode() { |
co838_jls44 | 0:4b83b332b327 | 24 | switch (temp_mode) { |
co838_jls44 | 0:4b83b332b327 | 25 | /* In the case it's set in celsius mode, set it in fahrenheit */ |
co838_jls44 | 0:4b83b332b327 | 26 | case CELSIUS: |
co838_jls44 | 0:4b83b332b327 | 27 | SetFahrenheit(); |
co838_jls44 | 0:4b83b332b327 | 28 | break; |
co838_jls44 | 0:4b83b332b327 | 29 | /* In the case it's set in fahrenheit mode, set it in celsius */ |
co838_jls44 | 0:4b83b332b327 | 30 | case FAHRENHEIT: |
co838_jls44 | 0:4b83b332b327 | 31 | SetCelsius(); |
co838_jls44 | 0:4b83b332b327 | 32 | break; |
co838_jls44 | 0:4b83b332b327 | 33 | default: |
co838_jls44 | 0:4b83b332b327 | 34 | SetCelsius(); |
co838_jls44 | 0:4b83b332b327 | 35 | break; |
co838_jls44 | 0:4b83b332b327 | 36 | } |
co838_jls44 | 0:4b83b332b327 | 37 | } |
co838_jls44 | 0:4b83b332b327 | 38 | |
co838_jls44 | 0:4b83b332b327 | 39 | /* Set temperature sensor in celsius */ |
co838_jls44 | 0:4b83b332b327 | 40 | void TemperatureSensor::SetCelsius() { |
co838_jls44 | 0:4b83b332b327 | 41 | temp_mode = CELSIUS; |
co838_jls44 | 0:4b83b332b327 | 42 | } |
co838_jls44 | 0:4b83b332b327 | 43 | |
co838_jls44 | 0:4b83b332b327 | 44 | /* return true if the temperature sensor is set in celsius */ |
co838_jls44 | 0:4b83b332b327 | 45 | bool TemperatureSensor::IsCelsius() { |
co838_jls44 | 0:4b83b332b327 | 46 | return (temp_mode == CELSIUS ? true : false); |
co838_jls44 | 0:4b83b332b327 | 47 | } |
co838_jls44 | 0:4b83b332b327 | 48 | |
co838_jls44 | 0:4b83b332b327 | 49 | /* Set temperature sensor in fahrenheit */ |
co838_jls44 | 0:4b83b332b327 | 50 | void TemperatureSensor::SetFahrenheit() { |
co838_jls44 | 0:4b83b332b327 | 51 | temp_mode = FAHRENHEIT; |
co838_jls44 | 0:4b83b332b327 | 52 | } |
co838_jls44 | 0:4b83b332b327 | 53 | |
co838_jls44 | 0:4b83b332b327 | 54 | /* return true if the temperature sensor is set in fahrenheit */ |
co838_jls44 | 0:4b83b332b327 | 55 | bool TemperatureSensor::IsFahrenheit() { |
co838_jls44 | 0:4b83b332b327 | 56 | return (temp_mode == FAHRENHEIT ? true : false); |
co838_jls44 | 0:4b83b332b327 | 57 | } |
co838_jls44 | 0:4b83b332b327 | 58 | |
co838_jls44 | 0:4b83b332b327 | 59 | /* get the temperature sensor mode */ |
co838_jls44 | 0:4b83b332b327 | 60 | TemperatureSensor::eTemp TemperatureSensor::GetMode() const { |
co838_jls44 | 0:4b83b332b327 | 61 | return temp_mode; |
co838_jls44 | 0:4b83b332b327 | 62 | } |