Im struggling to use the LCD4BIT library although i have got the example code that comes with it working well, ive tried the standard liquidcrystal library for simplicity but i cant even get the example to work.. so i want to perservere with the LCD4BIt library
i would be very grateful if someone could show me how to write a integer variable to the LCD using the LCD4BIT library.
here is the code im currently trying to use, im new to C++ as you will proberbly be able to tell from my code. i think the problem has something to do with the way im trying to type cast from an Int to char* as i dont think i fully understand the use of pointers.
#include <LCD4Bit.h>
//create object to control an LCD.
//number of lines in display=1
LCD4Bit lcd = LCD4Bit(1);
int rpm = 100;
char* rpmlocation ; //address of rpm varible???
void setup() {
pinMode(13, OUTPUT); //we'll use the debug LED to output a heartbeat
lcd.init();
}
void loop() {
rpm = 120;
digitalWrite(13, HIGH); //light the debug LED
rpmlocation = (char*) rpm; //convert to rpm int to char*
lcd.clear();
lcd.printIn(rpmlocation);
delay(1000);
digitalWrite(13, LOW);
}
Thanks for your help, the code you suggested worked great. And ive been able to measure RPM quite well since this morning
Ive also since figured out how to send a decimal to the lcd using this bit of code if any noobs like me would like to use it to save them selves some head scratching
void printfloat(float all , int decimals){ // will only work with lcd4bit library, basically it breaks the float into 2 integers then prints them seperatley with decimal point in the middle.
int decimal = 1 ;// intial multiplier so you dont get the situation decimal = 0 * 10 arrising
while(decimals > 0) // calculate the multipler for moving the decimal along i.e. *10 *100 *1000 etc
{
decimal = decimal * 10 ;
decimals = decimals - 1;
}
int parta; // the first part of the float (numbers after the decimal point)
int partb; // the last part of the part (numbers before the decimal point)
parta = int(all); // converting the float into an integer droping the info after the decimal
partb = (all * decimal) - (parta * decimal); // messing around to derive the integer form of the numbers before the decimal
itoa (parta, buf, 10);
lcd.printIn(buf);
if (partb > 0) // tests to see if the decimal is actually needed, delete if you always want the decimal i.e. xx.0
{
lcd.printIn(".");
itoa (partb, buf, 10);
lcd.printIn(buf);
}