NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » tempsensor

August 19, 2010
by LindaEC
LindaEC's Avatar

Hello, I wanted to add an if statement in the tempsensor project such as" if temp_avg < 5 then display temp, how and where would I insert this statement.

August 20, 2010
by Ralphxyz
Ralphxyz's Avatar

Hi LindaEC, first let me say that I am not a programmer but learning. I feel safe in answering as someone will jump into correct anything I say that is incorrect.

I did not test this code but it could be functional.

if(temp_avg < 5)                    // if temp_avg <5 show Temperatures on LCD otherwise just leave the LCD blank       
 {   
        // write message to LCD
        lcd_home();
        lcd_write_string(PSTR("ADC: "));
        lcd_write_int16(last_sample);

        if (temp_avg >3)            // if temp_avg <5 but >3 show this line otherwise skip this line
            {
                lcd_write_string(PSTR(" of 1024   "));
                lcd_line_two();
            }

        //fprintf_P(&lcd_stream, PSTR("Temperature: %.2f"), temp_avg);
        fprintf_P(&lcd_stream, PSTR("Temperature: %.0f"), temp_avg);
        lcd_write_data(0xdf);
        lcd_write_string(PSTR("F      "));
    }

The code is relatively meaningless I just randomly stuck in some if functions for illustrations.

Man that code format button is so cool.

Ralph

August 20, 2010
by LindaEC
LindaEC's Avatar

Thanks Ralph, I will try it,I have no prior programming experience but I am trying to learn and understand it. Thanks again.

August 20, 2010
by LindaEC
LindaEC's Avatar

Ralph,it works!!!!!!!!!!! Thanks

Post a Reply

Please log in to post a reply.

Did you know that two resistors plus a transistor can be used to make a better voltage supply? Learn more...