Lcd progressbar problem help plase

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

int sensor=A0;
int progress=0;

byte zero[] = {
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000
};
byte one[] = {
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
B10000
};

byte two[] = {
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
B11000
};

byte three[] = {
B11100,
B11100,
B11100,
B11100,
B11100,
B11100,
B11100,
B11100
};

byte four[] = {
B11110,
B11110,
B11110,
B11110,
B11110,
B11110,
B11110,
B11110
};

byte five[] = {
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111
};

void setup() {

pinMode(A0,INPUT);
lcd.init();
lcd.backlight();
lcd.createChar(0, zero);
lcd.createChar(1, one);
lcd.createChar(2, two);
lcd.createChar(3, three);
lcd.createChar(4, four);
lcd.createChar(5, five);

}

void loop() {

{ progress=analogRead(sensor);
progress = map(progress,620,0,0,600);
progress = progress > 100 ? 100 : progress;
progress = progress < 0 ? 0 :progress;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(progress);
lcd.print(" ");
updateprogress(progress, 100, 1);
delay(200);
}
delay(1000);

{
lcd.setCursor(0,0);
lcd.print(progress);
lcd.print(" ");
updateprogress(progress, 100, 1);
delay(50);
}
delay(1000);
}

void updateprogress(unsigned long count, unsigned long totalCount, int lineToPrintOn)
{
double factor = totalCount/80.0;
int percent = (count+1)/factor;
int number = percent/5;
int remainder = percent%5;
if(number > 0)
{
lcd.setCursor(number-1,lineToPrintOn);
lcd.write(5);
}

   lcd.setCursor(number,lineToPrintOn);
   lcd.write(remainder);   

}İşleniyor: MOV_0001.mp4...

Hello, do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation of your ask).

I hope you don't mind that I took the liberty to change the sketch and see how far I got. That worked out pretty well if I may say so.

// Show progress bar with the full display width.
// 
// Possible update:
//   Only one custom character would be enough,
//   if it was created in the sketch every time.
//

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#define LCD_WIDTH 16
LiquidCrystal_I2C lcd( 0x27, LCD_WIDTH, 2);

const int sensorPin = A0;

const byte zero[] = 
{
  0b00000000,
  0b00000000,
  0b00000000,
  0b00000000,
  0b00000000,
  0b00000000,
  0b00000000,
  0b00000000
};

const byte one[] = 
{
  0b00010000,
  0b00010000,
  0b00010000,
  0b00010000,
  0b00010000,
  0b00010000,
  0b00010000,
  0b00010000
};

const byte two[] = 
{
  0b00011000,
  0b00011000,
  0b00011000,
  0b00011000,
  0b00011000,
  0b00011000,
  0b00011000,
  0b00011000
};

const byte three[] = 
{
  0b00011100,
  0b00011100,
  0b00011100,
  0b00011100,
  0b00011100,
  0b00011100,
  0b00011100,
  0b00011100
};

const byte four[] = 
{
  0b00011110,
  0b00011110,
  0b00011110,
  0b00011110,
  0b00011110,
  0b00011110,
  0b00011110,
  0b00011110
};

const byte five[] = 
{
  0b00011111,
  0b00011111,
  0b00011111,
  0b00011111,
  0b00011111,
  0b00011111,
  0b00011111,
  0b00011111
};

void setup() 
{
  lcd.init();
  lcd.backlight();
  lcd.createChar( 0, zero);
  lcd.createChar( 1, one);
  lcd.createChar( 2, two);
  lcd.createChar( 3, three);
  lcd.createChar( 4, four);
  lcd.createChar( 5, five);
}


void loop() 
{
  int rawADC = analogRead( sensorPin);
  int progress = map( rawADC, 0, 1023, 0, 100);

  lcd.setCursor( 0, 0);
  lcd.print( progress);          // A number, 0...100
  lcd.print( "  ");              // clear previous text with spaces
 
  updateprogress( progress, 1);  // The first parameter should be a percentage

  delay( 100);                   // 10Hz update rate
}


void updateprogress( int percentage, int lineToPrintOn)
{
  // Total number of pixel horizontal is 16 * 5 (16 characters, 5 per character)
  // When the number of pixels is known, the number of full blocks and
  // the remaining is easy to calculate.
  int pixels = (int) round( float( percentage) / 100.0 * 5 * LCD_WIDTH);
  int fullBlocks = pixels / 5;       // number of characters that are full block
  int remainder = pixels % 5;        // number of pixels within character

  lcd.setCursor( 0, 1);              // second row
  for( int i = 0; i < fullBlocks; i++)
    lcd.write( '\5');                // full block

  lcd.write( remainder);             // write the remaining columns within character

  // Overwrite the rest with spaces to clear previous text
  // The number that is already written are the full blocks plus the remainder
  for( int i = fullBlocks + 1; i < LCD_WIDTH; i++)
    lcd.write( ' ');
}

This sketch in Wokwi (start the simulation and turn the potentiometer):

@serkansore You really have to put your sketch between code tags on this forum, otherwise it will be hard for us to help.

1 Like

Thank you works but reverse potatiometer volume up progressbar down :frowning:

Thank you no problem map code problem :relieved:


DSC_0002

You could have reversed the poles of the potentiometer

Posting a picture of a part of screen just to show the map command… don’t you think text would have been enough? (And clearer, and less energy wasted on the planet)

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.