5 years, 2 months ago.

mbed serial - print variable value

Board: FRM K64f

Trying to print a value of a variable.

heres code

Serial pc(USBTX, USBRX); int main () {

DynamixelClass my(57600, PTC17, PTC16);

int pos = my.readPosition(SERVO_ID);

pc.baud(57600);

pc.printf("H");

pc.printf(pos);

Error: Argument of type "int" is incompatible with parameter of type "const char *" in "main.cpp", Line: 12, Col: 16

1 Answer

5 years, 2 months ago.

correct is...

pc.printf("%d \n", pos);

http://www.cplusplus.com/reference/cstdio/printf/

okay, that seems to have worked partially, now it doesnt even print H which appears before the correction

posted by Bilal Saleem 24 Feb 2019

It will be printing the H but on the same line as the number with no spaces between them. If you want a new line you need to include either \n or \r\n, (unix or DOS line endings, most terminals have an option to select which on to expect.)

posted by Andy A 25 Feb 2019