lexus2k / lcdgfx

Driver for LCD displays running on Arduino/Avr/ESP32/Linux (including Rasperry) platforms
MIT License
377 stars 52 forks source link

Printing Floating Point Values to OLED #67

Closed josephmcg16 closed 3 years ago

josephmcg16 commented 3 years ago

Hello, sorry for the noob question. I'm sure this is a stupid question but I'm a bit stumped and can't find a solution.

I'm using this library as it's the only one that works with my Arduino Nano and SH1106 OLED. I'm trying to print floating point values.

Is there an easy way to break down the floats into individual bytes and encode as an ASCII char array to print to the OLED?

I'm just using the standard float dtype for Arduino. I have tried using the standard display.print() function with the setTextCursor method but there is no way to specify the number of digits to print. I therefore just print out something like 13.129999999 instead of 13.13.

I would post my code but it's just a few print statements so no point.

Is there a better way to print floats? I'm reading the data from some sensors over I2C and I get the values as arduino floats.

Thanks in advance!

josephmcg16 commented 3 years ago

` float humidity = 49.12; float temperature = 23.98; float pressure = 1001.15;

char humid_char[8], temp_char[8], prss_char[8]; String(humidity).toCharArray(humid_char, 8);`

I used this workaround with the Arduino string class. Then the regular print functions can be used. :)