I’m working on this little project for some fun and I can’t seem to get the unit to work the way I want.
I’m reading from a analog sensor and it appears that my numbers are coming out fine on my HD44780. Except; I have a lot of decimal places! So many in fact it erases the other information on the screen.
You have a bug in your sketch, the analogue ADC returns an integer value between 0 and 1023, there are no decimal places. If you post your sketch using the code button (#), we’ll maybe be able to put you right.
Well the value 0-1023 is then put into a formula, so a few calculations are done. Could that not yeild a decimal?
Here is parts of my code:
#include <LiquidCrystal.h>
int sensor = 0; //Sets the sensor input to pin 0
int boost = 0; //sets the boost to 0
int sensorval = 0; //sets sensor value to 0
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //sets the pins for the LCD
void loop() {
sensorval = analogRead(sensor); //Polls the sensor for data
boost = ((sensorval*.0049)/5.1+.04/.00369 *.14503774); //converts sensorval
lcd.setCursor(7,0); //sets the cursor position
lcd.print(boost); //prints boost data
lcd.setCursor(11,1);
Since your calculations are using integer variables, all they can return is integers. As far as I’m aware the lcdprint function can only handle strings, you need to convert the number to a string before displaying it.
Do some looking up of “sprintf”
Sounds like your problem is more to do with leading zero suppression than decimals.
If your first number to display occupies 4 digits, but subsequent ones are three digits, then the fourth digit may not be being erased.
You could try printing trailing spaces, though it is visually better (IMO) to print leading spaces.
Just to get rid of this misunderstanding. OP probably selected ‘copy for forum’ from the IDE. Then there is nice syntax coloring but has to be a ‘quote’. I’ve posted about this in the software Bugs & Suggestions board about this http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1259327352