I just bought a couple of cheap LCD's off of ebay, but now I can't figure out how the heck to get them working. I thought it was easy but I didn't look into it before buying them... How would I get these things working?
LarryD:
Maybe this will help you:
http://arduino-info.wikispaces.com/LCD-Blue-I2CYou get what you pay for
Thank you! I swear I've been googling for hours and couldn't get anything to work. That tutorial worked PERFECT! Thanks a million!
Okay, this isn't related to my LCD but it's the same project, and it seems spammey to post another thread just for this. So I'm trying to make a water meter, but I don't know how to divide and include decimals. In the code below, I would like the integer "gallons" to go out to at least 2 decimals.
Ignore the // sidenotes on the code, I recycled some code from a previous project.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int sensor = 12; //Flow meter is attached to pin 12
int count; //Variable for storing the current tick count
int pcount; //Variable for storing the previous tick count
int sstate; //Variable for storing the current state of the coin sensor
int psstate; //Variable for storing the previous state of the coin sensor
int gallon;
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
void setup(){
Serial.begin(9600);
lcd.begin(20,4); // initialize the lcd for 20 chars 4 lines and turn on backlight
lcd.backlight(); // finish with backlight on
lcd.setCursor(1,0);
lcd.print("Gallons Dispensed:");
pinMode(sensor, INPUT); //Sensor pin is an input
count = 0; //Sets the current coin count to 0
pcount = 0; //Sets the previous coin count to 0
sstate = 0;
psstate = 0;
gallon = 0;
}
void loop(){
sstate = digitalRead(sensor);
if(sstate == 1 && psstate == 0){
count = pcount + 1;
}
gallon = (count/1249.19);
lcd.setCursor(1,2);
lcd.print(gallon);
Serial.print(count);
Serial.print(", ");
Serial.println(gallon);
pcount = count;
psstate = sstate;
delay(5);
}
gallon = (count/1249.19);
You have int gallon;
Make it float gallon;
LarryD:
gallon = (count/1249.19);You have int gallon;
Make it float gallon;
Thanks again! And this isn't necessary right now, but if I wanted more (or less) numbers after the decimal, how would I do that?
Just kidding, figured it out. Just add a comma and the # of decimals I want after the "print (gallon)". So "print (gallon, 5)"