Russell Shomberg
/
shomberg_hw_6
HW6 for OCE560
Fork of shomberg_hw_5 by
OCE360Input.cpp@11:42914083ac70, 2018-10-25 (annotated)
- Committer:
- rshomberg
- Date:
- Thu Oct 25 18:58:41 2018 +0000
- Revision:
- 11:42914083ac70
- Parent:
- 9:da0b72918880
- Child:
- 12:ea407dcaff78
compiles, but using extern
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 | 9:da0b72918880 | 22 | #define TEMP_CALIBRATION_A 0.01 |
rshomberg | 9:da0b72918880 | 23 | #define TEMP_CALIBRATION_B 0 |
rshomberg | 9:da0b72918880 | 24 | |
rshomberg | 11:42914083ac70 | 25 | DigitalIn myswitch(p7); |
rshomberg | 11:42914083ac70 | 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 | 9:da0b72918880 | 37 | return Ain*VREF*1000; |
rshomberg | 9:da0b72918880 | 38 | } |
rshomberg | 9:da0b72918880 | 39 | |
rshomberg | 11:42914083ac70 | 40 | float convert_mV_to_temp(float sensorVoltage) { |
rshomberg | 9:da0b72918880 | 41 | return sensorVoltage*TEMP_CALIBRATION_A+TEMP_CALIBRATION_B; |
rshomberg | 9:da0b72918880 | 42 | } |