Liam Decaster
/
PM2_Example_IRSensor
Hello there
Diff: main.cpp
- Revision:
- 10:f459b443f676
- Parent:
- 9:c5e1e1facb02
- Child:
- 11:cfc9b8e963db
diff -r c5e1e1facb02 -r f459b443f676 main.cpp --- a/main.cpp Sat Mar 13 17:34:29 2021 +0100 +++ b/main.cpp Sat Mar 13 17:37:03 2021 +0100 @@ -1,12 +1,10 @@ #include "mbed.h" #include "platform/mbed_thread.h" -#include "string" using namespace std::chrono; InterruptIn user_button(USER_BUTTON); DigitalOut led(LED1); -BufferedSerial pc(USBTX, USBRX); bool executeMainTask = false; Timer user_button_timer, loop_timer; @@ -18,10 +16,6 @@ /* input your stuff here */ AnalogIn analogIn(PA_0); float dist = 0.0f; - -/* those numbers are just for testing the SerialBuffer class */ -float floatNumber = 0.003713f; -int integerNumber = 777; int main() { @@ -40,20 +34,8 @@ dist = analogIn.read()*3.3f; /* do only output what's really necessary, outputting "Measured value in mV: "" within the loop is no good solution */ - // printf("Measured value in mV: %d\r\n", (static_cast<int>(dist * 1e3))); + printf("Measured value in mV: %d\r\n", (static_cast<int>(dist * 1e3))); - /* using the BufferedSerial class as an example */ - string msg_str = "Measured value in mV: "; - msg_str.append(to_string((static_cast<int>(dist * 1e3)))); - msg_str.append(";"); - msg_str.append(to_string((static_cast<int>(floatNumber * 1e6)))); - msg_str.append(";"); - msg_str.append(to_string(integerNumber)); - msg_str.append(";\r\n"); - char msg[msg_str.length() + 1]; - strcpy(msg, msg_str.c_str()); - pc.write(msg, sizeof(msg)); - /* visual feedback that the main task is executed */ led = !led;