Digits do no increment down to one column on display.

I'm sorry for not knowing the proper terminology, I am very new to Arduino. I assumed the issue I'm having is common, but i have to been able to find any solution through searching. I am displaying Duty Cycle on a 16X2 display. When I am in the single digit range 0%-9% it increments up and down perfectly, but when i go into the double or triple digits, the number will not drop back down to just one column. I end up with "000" after spanning the range and returning, instead of "0". I am using an Arduno Uno. I can post the code if that would help solve my issue. Thanks in advance for any help, and i apologize for my horrible terminology.

Allen

Yes, you have to clear the digits when you're not using them anymore. That's a common issue with displays.

You print 9 and then print 10 over it, so the 1 replaces the 9 and the 0 goes next to it. Then you print 9 again over that, so the 9 replaces the 1 but there's nothing printing over the 0 and you're not clearing the display so it just sits there. You can either clear the display between numbers or you can print a few extra spaces when the number has less digits.

Please post your code using code tags.

Type
** **[code]** **

Past your code after that
Type
** **[/code]** **

I will look like

your code here

Thank you so much for the quick reply. I copied, pasted, and messed around with the sketch so much, I'm sure it's something I have done. I'm having a blast figuring i out though!

  #include <LiquidCrystal_I2C.h>
  #include <PWM.h>
  int32_t frequency = 20;
  LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); 

  void setup()  

{

  InitTimersSafe ();
  bool success = SetPinFrequencySafe(9, frequency);
  if (success) {
  pinMode (13, OUTPUT);
  digitalWrite (13, HIGH);
  
}
  
  Serial.begin(115200); 
  Serial.println();
  lcd.begin(16, 2);   
  lcd.clear ();
  pinMode (A1,INPUT);
  pinMode (A2,INPUT);
  pinMode (9, OUTPUT);
  
{
  
  lcd.backlight();
  delay(250);
  lcd.noBacklight();
  delay(250);
  
}
  
  lcd.backlight();   
  lcd.setCursor(0,0);
  lcd.print("   Sup Bitches");
  delay(1000);
  lcd.setCursor(0,1);
  lcd.print("Ankle Biters 2.0");
  delay(2000);  
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("RPM   DUTY   MS");
 
}

  void loop()  

{
    
  int potDuty = analogRead(A1);
  int potRpm = analogRead (A2);  
  int duty = map(potDuty ,0, 1022, 0,100);
  int rpm = map (potRpm ,0, 1022, 10, 200);  
  Serial.println("DUTY");
  Serial.println(duty);
  Serial.println("RPM");
  Serial.println(frequency * 60);
  lcd.setCursor(7,1);
  lcd.print(duty);  
  lcd.setCursor(0,1);
  lcd.print(frequency * 60);
  int sensorValue = analogRead (A1);
  pwmWrite (9, sensorValue / 4);
  

}
[code]

[/code]

The easy fix is to add the below at the beginning of loop()

  lcd.setCursor(0, 1);
  lcd.print(F("                "));

It will clear the second line of the display. Note the use of the F macro; instead of placing the text (16 spaces) in data memory, it is placed in code memory. If you run low on data memory, it will save you (in this case) 16 bytes of data memory at the cost of code memory.

Question:
Why do you read pin A1 twice in loop()? Basically potDuty and sensorValue will contain the same data. You could just as well use potDuty in the pwmWrite().

Note:
the last [code] that you typed should have been [/code] :wink: Your code block now contains [code] at the end.

sterretje:
The easy fix is to add the below at the beginning of loop()

  lcd.setCursor(0, 1);

lcd.print(F("                "));



It will clear the second line of the display. Note the use of the F macro; instead of placing the text (16 spaces) in data memory, it is placed in code memory. If you run low on data memory, it will save you (in this case) 16 bytes of data memory at the cost of code memory.

Thank you so much for the help, I'll try that this evening and report back.

sterretje:
Question:
Why do you read pin A1 twice in loop()? Basically potDuty and sensorValue will contain the same data. You could just as well use potDuty in the pwmWrite().

I have been trying to figure out how to vary the frequency in my sketch, using a potentiometer. I haven't had any luck yet. That is a bit of code that I forgot to remove from one of my failed attempts. That is the next hurdle I have to overcome. I'm trying to get in the habit of annotating the code I add, so it can be easily removed when it doesn't work :-). That line slipped through the cracks. You wouldn't happen to have a solution for that issue would you? I just need to be able to generate a signal from 10Hz to 200Hz, and be able to adjust the duty cycle. It would also be great if I could display the pin 9 "high" time in milliseconds, on my display. I don't know if that's possible though. Thanks for all your help. My project is starting to become a reality!

sterretje:
Note:
the last

[code]

that you typed should have been

[/code]

:wink: Your code block now contains [code] at the end.

Got it, thanks again!