New Jersey
Offline
Edison Member
Karma: 24
Posts: 2345
|
 |
« Reply #15 on: March 04, 2013, 08:45:32 pm » |
Whatever you do though, once you've made any of the suggested changes, please post the entire sketch that's giving you problems - attach it if necessary rather than posting it inline.
|
|
|
|
|
Logged
|
|
|
|
|
Mauritius
Offline
Jr. Member
Karma: 2
Posts: 93
Learning Never Ends . . .
|
 |
« Reply #16 on: March 05, 2013, 07:15:27 am » |
hi peter .. thanks for your kind response, i appreciate it loads..
i did read about the stack memory being overflow after around 50 days, but did not really know how to aproach for its preventive measures .. here you showed to me..
i was suspecting the itemIdx being my culprit the way it was incrementing.. thanks for confirming ..
i shall try out these changes once im back home, n will update all here with the entire code as attachment as requested by wildbill also ..
thanks again..
see ya ..
|
|
|
|
|
Logged
|
tz .....
|
|
|
|
Mauritius
Offline
Jr. Member
Karma: 2
Posts: 93
Learning Never Ends . . .
|
 |
« Reply #17 on: March 06, 2013, 01:46:07 pm » |
Hello,
Thanks for the great help peterH . .
Now my voltage pin do flip like a charm, my moisture values are quite stable and im happy that my sensors work as expected.
The modulo function do great in the switching of the case, great idea . . thanks load peterH.
I attached the source code for reference, and if any other changes and improvements can be made, i will be glad to review it and make necessary changes, while getting to learn more and new things at the same time.
Thanks again for all the responses towards this post.
My next step is to implement an LCD , to display all the real values and essential information with a pushbutton to change the mode Display. Im looking forward to be using another switch Case function again, hope i dont run into much trouble.
However, troubles are here for us to learn more , . . . and Learning never ends . . .
Regards
Tazlim . . .
|
|
|
|
|
Logged
|
tz .....
|
|
|
|
Des Moines, WA - USA
Offline
God Member
Karma: 21
Posts: 697
|
 |
« Reply #18 on: March 06, 2013, 02:00:31 pm » |
When are you going to fix - if ( FanStatus ) ; { FanControlOFF(); }
|
|
|
|
|
Logged
|
|
|
|
|
Des Moines, WA - USA
Offline
God Member
Karma: 21
Posts: 697
|
 |
« Reply #19 on: March 06, 2013, 02:04:10 pm » |
And didn't you mean - if ( ! FanStatus ) { FanControlON(); } else { FanControlOFF(); }
|
|
|
|
« Last Edit: March 06, 2013, 02:06:01 pm by lloyddean »
|
Logged
|
|
|
|
|
New Jersey
Offline
Edison Member
Karma: 24
Posts: 2345
|
 |
« Reply #20 on: March 06, 2013, 02:57:16 pm » |
This section (and others like it) could be improved/shortened: if (pump_Status == true) { Serial.print(" Pump Status : ACTIVE "); Serial.println(); }
else if (pump_Status == false) { Serial.print(" Pump Staus : INACTIVE "); Serial.println(); }
If you're testing a boolean, you can simply use if (pump_Status)
Since it's a boolean, if it's not true, no need to test if it's false. You have some very repetetive code there. Consider adding a function that takes a boolean and a string. Let the function print the string, test the boolean, and println "active" or "inactive" depending on its value. Then use if for all that conditional printing you're doing.
|
|
|
|
|
Logged
|
|
|
|
|
Des Moines, WA - USA
Offline
God Member
Karma: 21
Posts: 697
|
 |
« Reply #21 on: March 06, 2013, 03:17:27 pm » |
Amongst other things - Serial.print(" Pump Status : "); Serial.println((pump_Status ? "ACTIVE " : "INACTIVE ")); Serial.print(" Light Status : "); Serial.println((LightStatus ? "ACTIVE " : "INACTIVE ")); Serial.print(" Fan Status : "); Serial.println((FanStatus ? "ACTIVE " : "INACTIVE "));
|
|
|
|
|
Logged
|
|
|
|
|
Mauritius
Offline
Jr. Member
Karma: 2
Posts: 93
Learning Never Ends . . .
|
 |
« Reply #22 on: March 07, 2013, 10:59:49 am » |
hello! Thanks for the suggestions.. Ok i did get it, i will work to shortened and remove some repetitive codes further up, but will have to do some more reading what i see  The serial print for now is just to test if code is running properly, however i will be using LCD.print to display all these stuffs which is in serial.print for now. Serial.print(" Pump Status : "); Serial.println((pump_Status ? "ACTIVE " : "INACTIVE ")); Serial.print(" Light Status : "); Serial.println((LightStatus ? "ACTIVE " : "INACTIVE ")); Serial.print(" Fan Status : "); Serial.println((FanStatus ? "ACTIVE " : "INACTIVE "));
One question here, how will the code know that if pump_Status is 'true' to display ACTIVE or INACTIVE . . thanks taz . .
|
|
|
|
|
Logged
|
tz .....
|
|
|
|
Des Moines, WA - USA
Offline
God Member
Karma: 21
Posts: 697
|
 |
« Reply #23 on: March 07, 2013, 11:35:41 am » |
'false' is always zero, not false is alway not 'zero' yet not 'exactly' 'true' while 'true' is only 'true'.
To answer the question read -
<http://www.cplusplus.com/articles/1AUq5Di1/>
|
|
|
|
|
Logged
|
|
|
|
|
Mauritius
Offline
Jr. Member
Karma: 2
Posts: 93
Learning Never Ends . . .
|
 |
« Reply #24 on: March 07, 2013, 12:31:32 pm » |
You have some very repetetive code there. Consider adding a function that takes a boolean and a string. Let the function print the string, test the boolean, and println "active" or "inactive" depending on its value. Then use if for all that conditional printing you're doing.
Thats seems interesting, i will try to do this . . any help or source where i can start to grasp a good comprehension about the subject. I think i will be starting with Arduino Reference for string in the meanwhile . . Thanks . . 'false' is always zero, not false is alway not 'zero' yet not 'exactly' 'true' while 'true' is only 'true'.
Seems confusing, but i shall read it for a proper understanding, i shall keep things posted here, and in time of trouble, i shall ask for a push from time to time . .  I am actually editing my code for implementation with a 16X2 lcd, and display all my serial print to the latter. Thanks for your precious time and support . . See ya .. taz ...
|
|
|
|
|
Logged
|
tz .....
|
|
|
|
New Jersey
Offline
Edison Member
Karma: 24
Posts: 2345
|
 |
« Reply #25 on: March 07, 2013, 12:43:30 pm » |
What I'm suggesting is that the sections like this: if (pump_Status == true) { Serial.print(" Pump Status : ACTIVE "); Serial.println(); }
else if (pump_Status == false) { Serial.print(" Pump Staus : INACTIVE "); Serial.println(); } Could be replaced by a call like this: DisplayStatus("Pump",pump_Status);
Where the DisplayStatus Function is: void DisplayStatus (char* Title,boolean Status) { Serial.print(Title); if(Status) Serial.println(" ACTIVE); else Serial.println(" INACTIVE"); }
|
|
|
|
« Last Edit: March 08, 2013, 07:43:10 am by wildbill »
|
Logged
|
|
|
|
|
Des Moines, WA - USA
Offline
God Member
Karma: 21
Posts: 697
|
 |
« Reply #26 on: March 07, 2013, 02:01:23 pm » |
It's simple really. Conditional tests such as used in 'if', 'while', 'do while', and several others, evaluate to zero as false and not zero as not false.
The 'bool' values 'false' and 'true' have specific values - 'false' is always zero while 'true' may be any non-zero value depending upon the language version.
Here is an easy to read article concerning conditionals in C++
<http://www.cplusplus.com/forum/articles/3483/>
|
|
|
|
|
Logged
|
|
|
|
|
Mauritius
Offline
Jr. Member
Karma: 2
Posts: 93
Learning Never Ends . . .
|
 |
« Reply #27 on: March 10, 2013, 01:29:42 pm » |
Hello,
Im back again after some workings on the code.
I added up from the previous revision, an lcd 16x2, with some new lines in the code, but here im stuck with some bugs in the code.
My temperature part of the code is not giving me values. I suspected some wiring went wrong, however, when i test the temperature code alone, it works as nice as it should be. . .
With this new revision i added the lcd, and some menu to be displayed like, intro menu, soile percentage menu and LDR Raw reading. . I went through a pushbutton to swap between menus.
Here also without pressing my button, the lcd is changing menu.
Find herewith attached my code. Any suggestions where i can tackle for this bug.
Thanks in advance . .
|
|
|
|
|
Logged
|
tz .....
|
|
|
|
Des Moines, WA - USA
Offline
God Member
Karma: 21
Posts: 697
|
 |
« Reply #28 on: March 10, 2013, 01:37:30 pm » |
I'm curious why this continues to linger in your code - if (FanStatus == true);{ FanControlOFF (); }
|
|
|
|
« Last Edit: March 10, 2013, 01:42:02 pm by lloyddean »
|
Logged
|
|
|
|
|
Mauritius
Offline
Jr. Member
Karma: 2
Posts: 93
Learning Never Ends . . .
|
 |
« Reply #29 on: March 10, 2013, 01:52:41 pm » |
Oops was busy adding new lines and forgot about modification. A small recap please,  . . I need not to test for a boolean if it is true or not right ? intead of above i should i be using something likewise : And didn't you mean - if ( ! FanStatus ) { FanControlON(); } else { FanControlOFF(); }
Im getting to it, now  .. thanks again . .
|
|
|
|
|
Logged
|
tz .....
|
|
|
|
|