Water level indicat...
 
Notifications
Clear all

Water level indicator

81 Posts
12 Users
11 Reactions
13.6 K Views
(@tooter)
Member
Joined: 4 years ago
Posts: 33
Topic starter  

   
ReplyQuote
(@tooter)
Member
Joined: 4 years ago
Posts: 33
Topic starter  

   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2185
 
Posted by: @tooter

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?

 


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@tooter

Posted by: @tooter

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?


   
ReplyQuote
(@tooter)
Member
Joined: 4 years ago
Posts: 33
Topic starter  
Posted by: @frogandtoad

@tooter

Posted by: @tooter

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. 


   
ReplyQuote
(@tooter)
Member
Joined: 4 years ago
Posts: 33
Topic starter  

@frogandto

I apologize it did work. Thanks 


   
ReplyQuote
(@tooter)
Member
Joined: 4 years ago
Posts: 33
Topic starter  

   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2185
 
Posted by: @tooter

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?

 


   
ReplyQuote
(@tooter)
Member
Joined: 4 years ago
Posts: 33
Topic starter  
Posted by: @robotbuilder
Posted by: @tooter

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?

 

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. 


   
ReplyQuote
(@tooter)
Member
Joined: 4 years ago
Posts: 33
Topic starter  
Posted by: @robotbuilder

If your outputs are in the range 0 to 100 you can simply invert them.
value = 100-value

Thanks that worked great.


   
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 
Posted by: @tooter

@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!


   
ReplyQuote
(@tooter)
Member
Joined: 4 years ago
Posts: 33
Topic starter  

@frogandtoad

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.


   
ReplyQuote
(@tooter)
Member
Joined: 4 years ago
Posts: 33
Topic starter  

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.


   
ReplyQuote
(@tooter)
Member
Joined: 4 years ago
Posts: 33
Topic starter  

It's ok think i got it working I changed from int to float on percentage 1 and 2 and it messed it up.


   
ReplyQuote
Ruplicator
(@ruplicator)
Member
Joined: 5 years ago
Posts: 130
 
Posted by: @tooter

percentage2 = (100*Distance/TankDepth2);

From a much earlier post it looks like you were using "Distance" instead of Distance2 in your second tank calculation.


   
ReplyQuote
Page 4 / 6