skmdmasud
Member
Hi..
Its been a while since my last project, this time i am building a automatic water changing system for my aquarium. I ran into a problem with integer becoming <0 and my comparison in my WHILE statement fails to detect that...
I have attached a part of my code. I am sending the temp variable to my LCD. the temp gets minus with 2 or 3 or 4 depending on power head capacity.
In my LCD i see
temp is 10
temp is 6
temp is 2
temp is *$&@!
temp is *${})*
and so on... my while fails to see that temp became <1 and loops forever
all variable are 16bit
Its been a while since my last project, this time i am building a automatic water changing system for my aquarium. I ran into a problem with integer becoming <0 and my comparison in my WHILE statement fails to detect that...
I have attached a part of my code. I am sending the temp variable to my LCD. the temp gets minus with 2 or 3 or 4 depending on power head capacity.
In my LCD i see
temp is 10
temp is 6
temp is 2
temp is *$&@!
temp is *${})*
and so on... my while fails to see that temp became <1 and loops forever
all variable are 16bit
Code:
while (temp >1 | float_sensor_bottom == 0) //check amount of water drained
{
lcd_light_on();
powerhead_on();
if (bit_is_clear(PIND,5))
{
float_sensor_bottom = 1;
}
if (internal_sec >40) // it will take 10s for internal_sec to become 40 cuz 4hz it goes ++
{
temp = temp - power_head_liter_10s;
internal_sec = 0;
eeprom_update_word((&NV_water_drained), temp); //writing drained amount at eeprom memory
}