Implement a SD card into HW6
Dependencies: SDFileSystem mbed
Fork of shomberg_hw_6 by
main.cpp@18:699b41309be7, 2018-10-31 (annotated)
- Committer:
- rshomberg
- Date:
- Wed Oct 31 22:50:37 2018 +0000
- Revision:
- 18:699b41309be7
- Parent:
- 12:ea407dcaff78
- Child:
- 19:1f4dd59bbe6b
basic outline
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rshomberg | 0:82635173a413 | 1 | /** |
rshomberg | 8:d6560caeda9a | 2 | Temperature Sensor for hw6 |
rshomberg | 0:82635173a413 | 3 | main.cpp |
rshomberg | 0:82635173a413 | 4 | |
rshomberg | 6:8cfa0216554f | 5 | Purpose: Read signal from TMP36 connected to pin20 |
rshomberg | 18:699b41309be7 | 6 | Toggle switch connected to pin07 activates SD logging |
rshomberg | 18:699b41309be7 | 7 | Log: Time Elasped, Current Voltage, Current Temp, Delta Temp |
rshomberg | 18:699b41309be7 | 8 | Finish log -> save file and send to USB serial port |
rshomberg | 18:699b41309be7 | 9 | |
rshomberg | 8:d6560caeda9a | 10 | @author Russell Shomberg |
rshomberg | 18:699b41309be7 | 11 | @created 2018-10-31 |
rshomberg | 18:699b41309be7 | 12 | @revised 2018-10-31 |
rshomberg | 8:d6560caeda9a | 13 | @version 0.0 |
rshomberg | 18:699b41309be7 | 14 | |
rshomberg | 18:699b41309be7 | 15 | Issues: |
rshomberg | 18:699b41309be7 | 16 | |
rshomberg | 18:699b41309be7 | 17 | */ |
rshomberg | 0:82635173a413 | 18 | |
rshomberg | 0:82635173a413 | 19 | // INCLUDES |
rshomberg | 0:82635173a413 | 20 | #include "mbed.h" |
rshomberg | 9:da0b72918880 | 21 | #include "OCE360Input.h" |
rshomberg | 18:699b41309be7 | 22 | #include "SDFileSystem.h" |
rshomberg | 0:82635173a413 | 23 | |
rshomberg | 0:82635173a413 | 24 | // OUTPUTS |
rshomberg | 2:312a0a9c4485 | 25 | Serial pc(USBTX, USBRX); // for debugging |
rshomberg | 6:8cfa0216554f | 26 | |
rshomberg | 0:82635173a413 | 27 | // VARIABLES |
rshomberg | 6:8cfa0216554f | 28 | int outputT= 0; |
rshomberg | 18:699b41309be7 | 29 | float starting_voltage; |
rshomberg | 18:699b41309be7 | 30 | float starting_temp; |
rshomberg | 18:699b41309be7 | 31 | |
rshomberg | 18:699b41309be7 | 32 | float current_time; |
rshomberg | 18:699b41309be7 | 33 | float current_voltage; |
rshomberg | 18:699b41309be7 | 34 | float current_temp; |
rshomberg | 18:699b41309be7 | 35 | |
rshomberg | 6:8cfa0216554f | 36 | |
rshomberg | 0:82635173a413 | 37 | |
rshomberg | 18:699b41309be7 | 38 | int main() |
rshomberg | 18:699b41309be7 | 39 | { |
rshomberg | 18:699b41309be7 | 40 | |
rshomberg | 0:82635173a413 | 41 | while(1) { |
rshomberg | 18:699b41309be7 | 42 | while(read_switch()) { // skip everything if switch is off |
rshomberg | 18:699b41309be7 | 43 | // Take initial readings |
rshomberg | 18:699b41309be7 | 44 | starting_voltage = read_sensor(); |
rshomberg | 18:699b41309be7 | 45 | starting_temp = onvert_mV_to_temp(starting_voltage); |
rshomberg | 18:699b41309be7 | 46 | |
rshomberg | 18:699b41309be7 | 47 | // Initialize a file |
rshomberg | 18:699b41309be7 | 48 | |
rshomberg | 18:699b41309be7 | 49 | // Write header to file |
rshomberg | 18:699b41309be7 | 50 | //"Time (s), Voltage (mv), Temperature (C), Delta T (C)\n\r" |
rshomberg | 18:699b41309be7 | 51 | |
rshomberg | 18:699b41309be7 | 52 | // start a loop that logging |
rshomberg | 18:699b41309be7 | 53 | // exiting this loop will initialize data save procedures |
rshomberg | 18:699b41309be7 | 54 | while(read_switch()) { // Main loop for logging |
rshomberg | 18:699b41309be7 | 55 | |
rshomberg | 18:699b41309be7 | 56 | // Get data for logging |
rshomberg | 18:699b41309be7 | 57 | current_time = check_time(); |
rshomberg | 18:699b41309be7 | 58 | current_voltage = read_sensor(); |
rshomberg | 18:699b41309be7 | 59 | current_temp = convert_mV_to_temp(current_voltage); |
rshomberg | 18:699b41309be7 | 60 | |
rshomberg | 18:699b41309be7 | 61 | //"%1.2f, %1.2f, %1.2f, %1.2f \n\r", current_time, current_voltage, current_temp, current_temp-starting_temp |
rshomberg | 18:699b41309be7 | 62 | |
rshomberg | 18:699b41309be7 | 63 | wait(1); |
rshomberg | 18:699b41309be7 | 64 | } |
rshomberg | 18:699b41309be7 | 65 | // This code runs when the switch is toggled off |
rshomberg | 18:699b41309be7 | 66 | // Close out file |
rshomberg | 18:699b41309be7 | 67 | |
rshomberg | 18:699b41309be7 | 68 | // Print to USB serial |
rshomberg | 18:699b41309be7 | 69 | |
rshomberg | 6:8cfa0216554f | 70 | } |
rshomberg | 18:699b41309be7 | 71 | // Re-enter main while loop |
rshomberg | 18:699b41309be7 | 72 | //continuously check for switch to turn on again |
rshomberg | 0:82635173a413 | 73 | } |
rshomberg | 18:699b41309be7 | 74 | } |