brunialti / MENWIZ

ARDUINO LCD menu library: short user code to manage complex menu structures
65 stars 25 forks source link

drawUsrScreen with a float #2

Closed hayden-t closed 12 years ago

hayden-t commented 12 years ago

hi, im a bit new but want your take on how to output a float to my screen with your drawUsrScreen function ?

brunialti commented 12 years ago

void addUsrScreen(void (*f)(), unsigned long elapsed);

f argument is the user defined void function (callback) called after elapsed millisecs from the last interaction with the menu. Inside f callback the user can read sensor values, perform its own task and compose its own screen. The callback is fired once for each draw() method call, allowing fast data refreshing to be displayed. It is usefull to use the method drawUsrScreen to display a formatted screen inside the f callback. To display values on the the screen you can manage yourself the lcd or you can use the following function:

drawUsrScreen("Test user screen\nline1\nline2\n\n");

The above example call let the lcd display four lines (blank padding is automatic). The last line is empty (blank line). The string passed to the drawUsrScreen can be formatted using the standard c function sprintf. Unfortunately the sprintf implementation in Arduino does not support float values ! So you must use some other function (e.g dtostrf) to obtain a string from float value. After that you can use sprintf to format the rest of the line and include the string obtained by stostrf.

hayden-t commented 12 years ago

yeah sorry i worked out to use dtostrf