Russell Shomberg
/
shomberg_hw_6
HW6 for OCE560
Fork of shomberg_hw_5 by
OCE360Input.cpp@14:b3c87a7c7689, 2018-10-30 (annotated)
- Committer:
- rshomberg
- Date:
- Tue Oct 30 14:08:40 2018 +0000
- Revision:
- 14:b3c87a7c7689
- Parent:
- 13:fa74bf0c3b8d
working code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rshomberg | 9:da0b72918880 | 1 | /** |
rshomberg | 9:da0b72918880 | 2 | Temperature Sensor and Switch Read |
rshomberg | 9:da0b72918880 | 3 | OCE360Input.cpp |
rshomberg | 9:da0b72918880 | 4 | |
rshomberg | 9:da0b72918880 | 5 | Purpose: Read a switch connected at p7 |
rshomberg | 9:da0b72918880 | 6 | Read a temperature sensor connected at p20 |
rshomberg | 9:da0b72918880 | 7 | |
rshomberg | 9:da0b72918880 | 8 | @author Russell Shomberg |
rshomberg | 9:da0b72918880 | 9 | @created 2018-10-25 |
rshomberg | 9:da0b72918880 | 10 | @revised 2018-10-25 |
rshomberg | 9:da0b72918880 | 11 | @version 0.0 |
rshomberg | 9:da0b72918880 | 12 | |
rshomberg | 9:da0b72918880 | 13 | Issues: |
rshomberg | 9:da0b72918880 | 14 | |
rshomberg | 9:da0b72918880 | 15 | */ |
rshomberg | 9:da0b72918880 | 16 | // INCLUDES |
rshomberg | 9:da0b72918880 | 17 | #include "mbed.h" |
rshomberg | 9:da0b72918880 | 18 | #include "OCE360Input.h" |
rshomberg | 9:da0b72918880 | 19 | |
rshomberg | 9:da0b72918880 | 20 | // DEFINES |
rshomberg | 9:da0b72918880 | 21 | #define VREF 3.5 |
rshomberg | 12:ea407dcaff78 | 22 | #define TEMP_CALIBRATION_A 0.1 |
rshomberg | 9:da0b72918880 | 23 | #define TEMP_CALIBRATION_B 0 |
rshomberg | 9:da0b72918880 | 24 | |
rshomberg | 13:fa74bf0c3b8d | 25 | DigitalIn myswitch(p7); |
rshomberg | 13:fa74bf0c3b8d | 26 | AnalogIn Ain(p20); |
rshomberg | 11:42914083ac70 | 27 | |
rshomberg | 11:42914083ac70 | 28 | int switchPosition; |
rshomberg | 11:42914083ac70 | 29 | int sensorVoltage; |
rshomberg | 11:42914083ac70 | 30 | int sensorTemp; |
rshomberg | 11:42914083ac70 | 31 | |
rshomberg | 9:da0b72918880 | 32 | int read_switch(void) { |
rshomberg | 9:da0b72918880 | 33 | return myswitch; |
rshomberg | 9:da0b72918880 | 34 | } |
rshomberg | 9:da0b72918880 | 35 | |
rshomberg | 9:da0b72918880 | 36 | float read_sensor(void){ |
rshomberg | 13:fa74bf0c3b8d | 37 | return Ain*VREF*1000; // voltage in mV |
rshomberg | 9:da0b72918880 | 38 | } |
rshomberg | 9:da0b72918880 | 39 | |
rshomberg | 11:42914083ac70 | 40 | float convert_mV_to_temp(float sensorVoltage) { |
rshomberg | 13:fa74bf0c3b8d | 41 | return sensorVoltage*TEMP_CALIBRATION_A+TEMP_CALIBRATION_B; //temp in deg C |
rshomberg | 9:da0b72918880 | 42 | } |