I am reading values from a potentiometer that I can rotate to produce a range of numbers from 0-1023. I want to be able to display these numbers in terms of a horizontal bar graph on an LCD screen. The LCD screen is 20 blocks wide so the 0-1023 must be scaled down to 0-20. The character I want to use to produce the bar graph is a block that fills one entire block out of the 20 available. The bit pattern for this block is 0b11110001
.
block = 0b11110001;
BarGraph = ((DELVAL2/5115)*2000);
lcd_putxy(2,0,buf);
for (delay = 0; delay < 50000; delay++); // introduce a delay
sprintf(buf, "*", BarGraph);
lcd_putxy(2,0,buf);
I was hoping somebody could explain to me how to achieve this and the best method for scaling down my potentiometer values.
Your calculation has mistake
DELVAL2 is 0-1023. You divide it by 5115, so you get value between 0 and 1. It's probably casted to 0. 0 Mutliplied by 2000 is still 0.
Try first multiply, then divide:
Also for printing
will not work. Refer to sprintf function or simple use loop for putting symbol in buf array.