Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years ago.
Print on serial monitor string and char var.
Good morning programmers! Can you help me on how I can correct this code? I am trying to send that string of characters but the result is not what I expect, I think it is because of the conflict of variables when using the printf command, I'm not sure and I do not know how to correct that error. Please help!!!
Annex the code in which I am working:
#include "mbed.h"
#include <string
Serial USB(USBTX, USBRX);
void enviaDato(int id, int canal, int dato) {
string comando = "add ";
comando += id;
comando += ",";
comando += canal;
comando += ",";
comando += dato;
comando += "\xFF\xFF\xFF";
USB.printf(comando.c_str());
}
int main(){
USB.baud(115200);
for (int i=0; i<50; i++) {
enviaDato(1,0,i);
//Serial.println(i);
enviaDato(1,1,i+100);
wait(0.020);
}
}
P.d: I am working on a program that communicates a stm32F446re card with a nextion display.
1 Answer
7 years ago.
Hello Alexander,
The following might help get started
#include "mbed.h"
Serial usb(USBTX, USBRX);
void enviaDato(int id, int canal, int dato) {
usb.printf("add %d,%d,%d\\xFF\\xFF\\xFF\r\n", id, canal, dato);
}
int main(){
usb.baud(115200);
for (int i=0; i<50; i++) {
enviaDato(1,0,i);
enviaDato(1,1,i+100);
wait(0.020);
}
}