9 years ago.

Printing analog voltage using a terminal and function

Hi, I am practising with the mbed and I need to make a program that can do a couple of things, including printing the voltage of the analogue input.

I currently have a main function containing a while(1) loop that contains a bunch of if and else statements. After the closing of the main function I have made the function:

void SendData(float Data) { pc.printf("%f", pot1.read()); while(1) { pc.putc(pc.getc() + 1); } }

I get no errors but the program does not print the voltage on the terminal. I need to use a function called 'void SendData(float Data)'.

Additionally: How can I configure the baud rate?

1 Answer

9 years ago.

Hi Marc,

Are you ever actually calling your SendData function? Could you post the rest of the code? (Make sure to use the <<code>><</code>> tags).

Also, your SendData function doesn't look right from what you described.

void SendData(float Data) {
    pc.printf("%f", pot1.read());
    while(1) {
        pc.putc(pc.getc() + 1);
    } 
}

The while loop will loop forever and I'm not sure you want that. Also, are you supposed to be using the Data argument? If you post all of your code that might help.

To configure the baud rate, you need to declare a specific instance of a Serial object like this:

Serial pc(USBTX, USBRX);

int main() {
    pc.baud(115200); // Replace 115200 with your desired baud rate

    // rest of program
}