I can't print a float in Hercules, WHY?

I want to print a float, which is the value I get from a potentiometer through serial communication (BufferedSerial), but it doesn’t appear in Hercules, but if I put it as an int it does print it, what am I wrong with my code?
Look at the code:
#include “mbed.h”

#define tiempo 1500ms

Mutex p_serie; //proteger el puerto serie

//decalraciones de pines
BufferedSerial pc(USBTX, USBRX);
AnalogIn pot(A0);

//prototipos de las funciones
void leer_pot (void);

//tareas o hilos
Thread hilo_leer_pot (osPriorityNormal, 2048);

//variables globales
const float voltaje_a = 3.3f; // Voltaje de referencia
char men[300]; //almacenar la cadena de caracteres
const float angulo_maximo = 290.0f; // Máximo ángulo del potenciómetro

int main() {
hilo_leer_pot.start(leer_pot);
}

void leer_pot(){

//configurar la velocidad de transmision
pc.set_baud(9600);

pc.set_format(8, BufferedSerial::None, 1); //8-N-1

while (true){
    // Leer el valor del potenciómetro
    float valor_adc = pot.read();

    // Calcular el voltaje real
    float voltaje_pot = voltaje_a * valor_adc;

    // Calcular el ángulo
    float angulo_pot = ((voltaje_pot / voltaje_a) * angulo_maximo);

    p_serie.lock();

    // Enviar el valor por el puerto serie
    sprintf(men, "El valor es: %f\n\r", angulo_pot);
    //pc.write(men, sizeof(men));

    p_serie.unlock();

    // Esperar 2 segundos antes de leer el potenciómetro nuevamente
    ThisThread::sleep_for(tiempo); 
}

}

this is what I get:

Yeah and i give you answer in your previous topic.

BR, Jan

1 Like