df

Dependencies:   mbed mbedWSEsbc

Committer:
m170984
Date:
Tue Sep 29 01:28:19 2015 +0000
Revision:
0:f303c63965dd
code and shit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
m170984 0:f303c63965dd 1 //MIDN 2/C Chau
m170984 0:f303c63965dd 2 //Take a temp reading from sensor and send it to MatLab for analysis
m170984 0:f303c63965dd 3 //ES305 Lab2
m170984 0:f303c63965dd 4 #include "mbed.h"
m170984 0:f303c63965dd 5 #include "mbedWSEsbc.h"
m170984 0:f303c63965dd 6
m170984 0:f303c63965dd 7 float dt; // total change in time
m170984 0:f303c63965dd 8 float totaltime = 5; // total sampling time
m170984 0:f303c63965dd 9 float Ts = 0.01; // sampling period
m170984 0:f303c63965dd 10 int repeat = 17; //Boolean for yes or no
m170984 0:f303c63965dd 11 float Time = 0; // time object
m170984 0:f303c63965dd 12 float measurement = 0; //The measured voltage of the thermocouple
m170984 0:f303c63965dd 13
m170984 0:f303c63965dd 14 int main()
m170984 0:f303c63965dd 15 {
m170984 0:f303c63965dd 16 mbedWSEsbcInit(19200); //set baud rate
m170984 0:f303c63965dd 17 Time = 0; // reset time var
m170984 0:f303c63965dd 18 t.reset(); // reset time object
m170984 0:f303c63965dd 19 pc.printf("Enter 1 to begin the loop:\n\r");
m170984 0:f303c63965dd 20 pc.scanf("%d", &repeat);
m170984 0:f303c63965dd 21 pc.printf("Enter total sampling time(sec):\n\r");
m170984 0:f303c63965dd 22 pc.scanf("%f", &totaltime);
m170984 0:f303c63965dd 23 pc.printf("Enter sampling period(sec):\n\r");
m170984 0:f303c63965dd 24 pc.scanf("%f", &Ts);
m170984 0:f303c63965dd 25 while (repeat ==1)
m170984 0:f303c63965dd 26 {
m170984 0:f303c63965dd 27 Time = 0; // reset time var
m170984 0:f303c63965dd 28 t.reset(); // reset time object
m170984 0:f303c63965dd 29
m170984 0:f303c63965dd 30 while (Time <= totaltime)
m170984 0:f303c63965dd 31 {
m170984 0:f303c63965dd 32 t.start(); // start timing object
m170984 0:f303c63965dd 33
m170984 0:f303c63965dd 34 measurement = read_max1270_volts(6,0,0); //read from the device
m170984 0:f303c63965dd 35 pc.printf("%f,%f\n", Time, measurement); // print measurement
m170984 0:f303c63965dd 36
m170984 0:f303c63965dd 37 Time = Time + Ts; // increment time
m170984 0:f303c63965dd 38
m170984 0:f303c63965dd 39 dt = Ts - t.read(); // calculate elapsed time
m170984 0:f303c63965dd 40 wait(dt); // wait
m170984 0:f303c63965dd 41
m170984 0:f303c63965dd 42 t.reset(); //restart timing object
m170984 0:f303c63965dd 43 }
m170984 0:f303c63965dd 44 pc.printf("Enter 1 to begin the loop:\n\r");
m170984 0:f303c63965dd 45 pc.scanf("%d", &repeat);
m170984 0:f303c63965dd 46 pc.printf("Enter total sampling time(sec):\n\r");
m170984 0:f303c63965dd 47 pc.scanf("%f", &totaltime);
m170984 0:f303c63965dd 48 pc.printf("Enter sampling period(sec):\n\r");
m170984 0:f303c63965dd 49 pc.scanf("%f", &Ts);
m170984 0:f303c63965dd 50 }
m170984 0:f303c63965dd 51 }