Hi thanks that works great. just need some time to pick at it and and try to understand it.
With practice and familiarity with the computer language of your choice this becomes easier.
However it is better to have it written in a high level human like language first so you can work out the logic and flow of a program that is easy to read and understand and then have it translated down to the computer language of your choice.
A high level description also makes it easier to translate your code from one language to another (C++ to Python perhaps). A higher level description will also make it easier to "pick at and understand" the code.
If I remember correctly you wanted the display to come on for a short time after you pressed a button?
Thank struggled to get that to work. I'm a bit pushed fro time at the moment though. I will get back to it and give it another try.
Hm... not sure why you struggled to get it to work. The code I provided was a simple copy and paste, with nothing else to do to it but run it to understand how it works. What problems did you have with it?
Thank struggled to get that to work. I'm a bit pushed fro time at the moment though. I will get back to it and give it another try.
Hm... not sure why you struggled to get it to work. The code I provided was a simple copy and paste, with nothing else to do to it but run it to understand how it works. What problems did you have with it?
Hi I couldn't get it to compile.
@frogandto
I apologize it did work. Thanks
Ok finally found some time to spend on it after a lot of reading. I've worked out how to convert a measured distance in to a percentage. 😉 Managed to write the code myself with help from the previous posts. My only problem is I need the percentage in tank 1 to go down from 100% (when full) to zero not from zero to 100%. I'm struggling to achieve this. Here is my code.
Great satisfaction working it out for yourself 🙂
If your outputs are in the range 0 to 100 you can simply invert them.
value = 100-value
Have you actually placed your sonar sensors on the top of the tanks yet?
Ok finally found some time to spend on it after a lot of reading. I've worked out how to convert a measured distance in to a percentage. 😉 Managed to write the code myself with help from the previous posts. My only problem is I need the percentage in tank 1 to go down from 100% (when full) to zero not from zero to 100%. I'm struggling to achieve this. Here is my code.
Great satisfaction working it out for yourself 🙂
If your outputs are in the range 0 to 100 you can simply invert them.
value = 100-valueHave you actually placed your sonar sensors on the top of the tanks yet?
Hi thanks. Yes it does feel good. No they are not in place yet Still testing but i have the measurements of the tanks so i can set the depth on a test rig i have set up.
If your outputs are in the range 0 to 100 you can simply invert them.
value = 100-value
Thanks that worked great.
@frogandto
I apologize it did work. Thanks
Cool, that's great to hear!
Just saw your recent emails too, so congrats on working it out to get your program working. It becomes very satisfying when you can get stuff to work!
When you get a little more proficient in coding, the next step might be to refactor your code to incorporate functions, which can make your code much more readable and in many cases shorter too.
Anytime you use multiple variable names for the same quantity, you have to ask yourself the question... do I really need to keep repeating these variables, or is there a better way?... and yes there is!
Might be a good exercise to look into 🙂
Cheers!
Thanks will look in to it.
What i'm doing at the mo is following a great series on youtube by a great teacher called Paul McWhorter. I follow his lessons and if there is something i feel is relevant to my project i try to apply it. It seems to be working well at the moment just a little slow process but i'm enjoying the learning.
Hi discovered a problem with my code. 😪 😪 I've been racking my brain on it all afternoon. I will do my best to explain. When the sensors are at same level the math works out fine. but if the water levels are different in both tanks it cant calculate them correctly and gives me inaccurate percentages. I hope that makes sense.
It's ok think i got it working I changed from int to float on percentage 1 and 2 and it messed it up.
percentage2 = (100*Distance/TankDepth2);
From a much earlier post it looks like you were using "Distance" instead of Distance2 in your second tank calculation.