Closed Joshi115 closed 4 years ago
First on an Arduino snprintf doesn't support floating point numbers Second even if it did %u would be wrong, %f for floating point say 5 long and two decimals would be "%5.2f". If it worked, but not supported so you need to use dtostrf. Now I'm doing this from memory so you might need to experiment with this code or google but you want something like: Note the extra include files, I don't remember which one you need but including both won't cause any harm.
#include "GUIslice.h"
#include "GUIslice_drv.h"
#include <stdio.h>
#include <stdlib.h>
float Po = analogRead(adcPin) * 5.0 / 1024;
float phValue = 7 - (2.5 - Po) / m;
char acTxt[4];
gslc_tsElemRef* phvaluebox = gslc_PageFindElemById(&m_gui,E_PG_MAIN,phbox);
// snprintf(acTxt,4,"%u",phvalue);
dtostrf(phValue, 4, 0, acTxt );
gslc_ElemSetTxtStr(&m_gui,phvaluebox,acTxt);
While we are at it your InitGUI() shows:
phvaluebox = pElemRef;
which means you don't need the
gslc_tsElemRef* phvaluebox = gslc_PageFindElemById(&m_gui,E_PG_MAIN,phbox);
it's redundant. Paul--
Hi Paul,
Thank you very much! It works now without a charm! I'm so happy right now! Thank you again. I was working on this for hours and couldn't figure it out.
Another small question (I haven't taken a look at it yet): I also want to add a Graph later. So the values from my pH Meter on the x - Axis. And on my y- Axis should be my values from another variable (simple counter variable / every time my pump goes on it adds 5 [ml] to my y Axis counter variable).
Is this possible? I haven't taken a look at it.
Thank you again very much,
Joshua
Yes, easy fast way and hardway. Easy: using Builder drop graph element where you want it on display, size height and width, set Maximum Points, say 100. and inside loop() call
gslc_ElemXGraphAdd()
to add points. However, it's not very pretty. Can't say I ever liked it. See ex11_bld_graph first.
Hardway, draw graph yourself, updating in a draw callback and using the tick callback to check your meter and trigger drawing callback. See ex06_bld_callback.
If you run into trouble send an email to Support: guislice@gmail.com or to me by going to my profile and using my public email address.
If you however run into a bug or want to request enchancements please open a new issue. The issues isn't really for C programming questions since it's not constructed as real forum it's just a flat list of bugs enhancement requests ,or questions of how to use the project. THe issues list would get out of hand quickly if we ran it like the Arduino forum.
Also, Please close this issue if we are done. PS: I'm going to add your questions to my GUIsliceBuilder's FAQ. Paul--
[My Hardware: -ELEGOO Mega2560 R3 Amazon Link -Generic 3.5 Inch Touch Display Amazon Link -My Skills: Newbie ]
Hi, I'm not sure if I can ask questions here or if I should go to the Arduino Forum next time.
What do I want to do (at least for now / very basic for my program):
I have a pH Meter and I would like to display the always changing variable in my text box. For that I have a working pH Meter Script:
Code
In the end, I get my variable phValue or phvalue2. Both of them work and I get a reading for them through Serial Monitor.
Now I thought that I just have to copy it into my GUISlice Projekt. So I created a Page with just a Text Box. Then I used the code from an Example (Exp. 18) to get it running.
This is what I put together:
Code
When I'm playing around with
snprintf(acTxtNum,2,**"%u"**,phValue);
(with %u) then I usually get different results.As a result, I get:
or
or
I think that I'm missing something here... Maybe with the snprintf string? Maybe I'm defining the variables wrong? I really don't know.
Please keep your work up! It's great and I love it!
Joshua
Sources and Websites I have already looked at: FAQ User-Guide Other Guide sprintf Guide