Programming LED Display in Loop

So I’m creating a force sensor and display that will be able to communicate the number of rounds left in a magazine based on the spring force in the mag. I am using the Chinese Arduino Nano and have the necessary drivers. I have uploaded code for the display and the force sensor separately and they are both working separately. I am now trying to combine the code so that when the sensor reads say 200g the display spits out 05 rounds. Right now I am using a serial loop that just keeps reading the resistance from the force sensor. However, my display code seems to be running very linearly. The LED display will very quickly display the first digit every time the force sensor cycles (about every second) and then turn off and only display the second number in the code. It’s like the code reads the first number and then forgets about it and sticks with the second number until it loops again. How can I get both numbers to hold a display through the entire loop?

Thanks

int pressureAnalogPin = 0; //pin where our pressure pad is located.
int pressureReading; //variable for storing our reading

//Adjust these if required.
int noPressure = 5; //max value for no pressure on the pad
int lightPressure = 333; //max value for light pressure on the pad
int mediumPressure = 666; //max value for medium pressure on the pad

#include <LEDDisplay.h>

LEDDisplay *led;
 
void setup(void) {
  int digitFlagPins[] = {10, 11};
  int segmentPins[] = {2, 3, 4, 5 ,6 ,7 ,8, 9};
  int decimalPointPin = 9;
  led = new LEDDisplay(2, digitFlagPins, segmentPins, decimalPointPin);
  Serial.begin(9600);
}
 
void loop(void) {
  pressureReading = analogRead(pressureAnalogPin);
  
  Serial.print("Pressure Pad Reading = ");
  Serial.println(pressureReading);

  if (pressureReading < noPressure) {
    Serial.println(" - No pressure"); 
      led->displayNumber(0,1);
      led->displayNumber(5,0);
  } else if (pressureReading < lightPressure) {
    Serial.println(" - Light Pressure");
      led->displayNumber(1,1);
      led->displayNumber(0,0);
  } else if (pressureReading < mediumPressure) {
    Serial.println(" - Medium Pressure");
      led->displayNumber(2,1);
      led->displayNumber(5,0);
  } else{
    Serial.println(" - High Pressure");
      led->displayNumber(3,1);
      led->displayNumber(0,0);
  }
  delay(1000);
}

I've deleted your other cross posts @TmAnBuIck.

Cross posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes writing a detailed answer on this thread, without knowing that someone else already did the same in the other thread.

Repeated cross posting will result in a suspension from the forum.

In the future, please take some time to pick the forum section that best suits the topic of your question and then only post once to that forum section. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum section. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

How annoying!

I had just composed a full reply to this and it just disappeared as I tried to post it!

I am guessing (well, it is pretty obvious :grinning: ) that you are using a very crude display code that assumes your LED digits are multiplexed, and it is your responsibility to spend equal time displaying the two digits. (I hope you have the 1k segment resistors in place. :cold_sweat: )

To do that, your code must first determine what numbers are to be displayed. Presumably it will do that once per second - there are a couple of ways to do that.

Now that you know the first and second digit to be displayed, you display the first digit and delay for 5 milliseconds, then display the second digit and delay for 5 milliseconds also. If you count how many times you do this in total, than after doing it 100 times, that will be another second and you can go and read your force sensor and recalculate the numbers if necessary.

There you go - that's how to do it for a beginner, it's up to you now! :sunglasses:

Paul__B: Now that you know the first and second digit to be displayed, you display the first digit and delay for 5 milliseconds, then display the second digit and delay for 5 milliseconds also. If you count how many times you do this in total, than after doing it 100 times, that will be another second and you can go and read your force sensor and recalculate the numbers if necessary.

I haven't tried running this, but what you're describing looks to me like the first number will be displayed for 5 milliseconds, disappear, and then the second number will be displayed for the rest of the loop. I would like to have the two digits displayed for the entire loop at the same time. Is this possible?

pert: I've deleted your other cross posts @TmAnBuIck.

Cross posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes writing a detailed answer on this thread, without knowing that someone else already did the same in the other thread.

Repeated cross posting will result in a suspension from the forum.

In the future, please take some time to pick the forum section that best suits the topic of your question and then only post once to that forum section. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum section. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

My apologies, I wasn't sure where this belonged since it involved displays, sensors, etc. But I see now that my main question deals with my programming. Thank you.