Ian Wolf
/
InjectorValveFourthMicro
Fork of TEMPFINALInterrupt_copy by
Diff: main.cpp
- Revision:
- 2:4425049f4174
- Parent:
- 1:1de97b1145f3
- Child:
- 3:0f441a513e2c
--- a/main.cpp Wed Aug 16 13:51:57 2017 +0000 +++ b/main.cpp Thu Aug 31 13:57:01 2017 +0000 @@ -1,10 +1,16 @@ #include "mbed.h" +#include <string> // Read temperature from MAX1363 3-channel ADC I2C i2c(PB_9 , PB_8); +DigitalOut Relay(D7); +Serial pc(SERIAL_TX, SERIAL_RX); -Serial pc(SERIAL_TX, SERIAL_RX); +std::string str; +char ch; +double SetTemp=0; +float x=0; // address information for the Serenity temperature sensor device const int SLAVE_ADDRESS = 0x34 << 1; @@ -44,8 +50,18 @@ return temp_k + CONV_K_TO_C; } +void callback(){ +ch=pc.getc(); +str+=ch; +SetTemp= atof(str.c_str()); +return; +} + + int main() { - pc.baud(250000); + pc.baud(115200); + + pc.attach(&callback); // reserve 4 bytes for transfer char cmd[4]; @@ -60,7 +76,10 @@ float values[2] = {0}; while (1) { - wait(0.5); + //Clear string holding the input from serial + str.clear(); + + wait(1); // clear buffer, only to detect invalid data cmd[0] = 0x00; @@ -81,14 +100,15 @@ // handle invalid data } } - + x=values[1]; + if (x<SetTemp){ + Relay=0; + } + if (x>SetTemp+1){ + Relay=1; + } // output temperature data - - printf("%0.2f\t %0.2f\r\n", values[0], values[1]); + printf("%0.2f\t %0.2f\t %0.2f\r\n", SetTemp, values[0], values[1]); + } } - - - - -