Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9215359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:11:14+00:00 2026-06-18T02:11:14+00:00

I have a question about some code and weird anomalies. This code is placed

  • 0

I have a question about some code and weird anomalies. This code is placed on a Digispark. The Digispark has a code size limit of 6,010 bytes. When using nested if statements, text is not outputted to the LCD screen (see links below). By commenting out each set seperately I am able to get it working again.

Basic LCD functions:

  1. LCD outputs internal beer temp and ambient air temp. https://i.stack.imgur.com/4hAQk.jpg
  2. LCD clears
  3. LCD outputs target temp and heater (relay) status https://i.stack.imgur.com/eYaJf.jpg

Variables are of float type.

float inside_temp;
float outside_temp;
float target = 74.00;

//inside_temp and outside_temp are values from 2 ds18b20's
inside_temp = 70.70;
outside_temp = 70.81;

The LCD works when using this code with it commented out like this. The compiled size is 5,928 bytes.

if(inside_temp < target){
    //Create a limit so heater isn't crazy hot as 5 gallons takes a while to change temperature.
    // float limit = target + 1;
    // if(outside_temp > limit){
    //     digitalWrite(RELAY_PIN, LOW);
    //     lcd.print("OFF");
    // }
    // else{
    digitalWrite(RELAY_PIN, HIGH);
    lcd.print("ON");
    // }
  }
  else{
      digitalWrite(RELAY_PIN, LOW);
      lcd.print("OFF");
  }

The LCD also works with this code. The compiled size is 5,590 bytes.

// if(inside_temp < target){
    //Create a limit so the heater isn't crazy hot as 5 gallons takes a while to change temperature.
    float limit = target + 1;
    if(outside_temp > limit){
        digitalWrite(RELAY_PIN, LOW);
        lcd.print("OFF");
    }
    else{
       digitalWrite(RELAY_PIN, HIGH);
       lcd.print("ON");
    }
    // }
    // else{
    //     digitalWrite(RELAY_PIN, LOW);
    //     lcd.print("OFF");
    // }

LCD does NOT work when uncommented. The compiled size is 5,992 bytes. All it does is sit there with the backlit on and no text. https://i.stack.imgur.com/OUt15.jpg

if(inside_temp < target){
    //create a limit so heater isn't crazy hot as 5 gallons takes a while to change temperature.
    float limit = target + 1;
    if(outside_temp > limit){
        digitalWrite(RELAY_PIN, LOW);
        lcd.print("OFF");
    }
    else{
        digitalWrite(RELAY_PIN, HIGH);
        lcd.print("ON");
    }
}
else{
    digitalWrite(RELAY_PIN, LOW);
    lcd.print("OFF");
}

I don’t understand why this happens. Is this occuring because I’m getting too close to maximum size limit? Can I not structure code like this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:11:15+00:00Added an answer on June 18, 2026 at 2:11 am

    I think it’s pretty hard to answer this in a conclusive manner, without being able to test it locally.

    It does sound very suspicious though, that it breaks when the code size approaches the maximum. On the other hand, it seems to indicate a bug in the tools that it doesn’t break “hard”, if some limit was exceeded.

    Some tips on how to reduce the code size:

    • Don’t use float since the CPU must emulate it. A fixed-point format should be fine for temperatures.
    • Factor out the function calls to digitalWrite() and lcd.print(), since function calls generate quite a lot of code.

    One way of factoring out those calls is doing something like this:

    uint8_t relay_pin = LOW;
    const char *lcd_text = "OFF";
    if(inside_temp < target) {
        float limit = target + 1;
        if(outside_temp > limit) {
        }
        else {
          relay_pin = HIGH;
          lcd_text = "ON";
        }
    }
    digitalWrite(RELAY_PIN, relay_pin);
    lcd.print(lcd_text);
    

    This uses the fact that we want to always update the LCD and relay, so we can always call the functions. Then we use variables to hold the desired values, since assignments are usually cheaper (in terms of code size, here) than function calls.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have what i hope is a quick question about some code i am
I'm working on some JQuery code and I have a question about caching selectors.
Quick question about include/requre_once . I have some code that is common to a
I have some question about assembly, is it possible to convert ASCII code of
I have a question about interface and class implementing interface. This is my code:
I was looking at some code that uses Boost.Function and have a question about
I have a configuration question about SVN. I have downloaded some code from a
I have a question about some code I'm testing to start understanding posix threads.
I have a question about some functionality I'm trying to add to my jQuery
I have some question about WH_MOUSE. From what I've read, by putting the hook

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.