I want to make a hour counter and rpm for my bike. I had written following codes for that but while compiling these codes. many errors are comming. one of those code is "'lcd' does not name a type".
please help me to compile the following codes.
regards
Roshan
#include <LiquidCrystal.h> #include <EEPROM.h>
int address = 0;
float x= 254.4 ;
float y= millis()/60000; // to count decimal of hours
int RPM = 0;// starting value of sensor
float f=1.5; //change value of f for calibration
LiquidCrystal lcd(12,11,5,4,3,2);
lcd.begin(16,2);
lcd.print("Hello Roshan");//welcome message in lcd
lcd.println("welcome");
void setup() {
if(EEPROM.get(address,x)>x)
{
x=EEPROM.get(address,x); //for getting eeprom value last stored when re powered
}else{
x=x;
}
lcd.begin(16,2);
// put your setup code here, to run once:
}
void loop() {
RPM = analogRead(A0)*f;// calculation of sensor value
if (digitalRead(13)== 1) //when pin 13 will be high proceed to next step else update eeprom
{
if(digitalRead(14)==1) //when pin 14 will be high calculate x i.e. progressive hours
{
x+=y;
}
else {
x=x;
}} else {
EEPROM.update(address,x);
}
}
lcd.setCursor(0,1); //printing value of sensor in lcd in 1st line
lcd.print("RPM=");
lcd.print(RPM);
lcd.setCursor(0,2); //printing value of hours in second line of lcd
lcd.print("Engine Hrs.-");
lcd.print(x);
delay(100);
}
I am new to programming so,
If the following code is readable and understandable. Please help to rectify the errors
#include <LiquidCrystal.h> #include <EEPROM.h>
int address = 0;
float x= 254.4 ;
float y= millis()/60000; // to count decimal of hours
int RPM = 0; // starting value of sensor
float f=1.5; //change value of f for calibration
void setup()
LiquidCrystal lcd(12,11,5,4,3,2);
lcd.begin(16,2);
lcd.print("Hello Roshan"); //welcome message in lcd
lcd.println("welcome")
{
if(EEPROM.get(address,x)>x)
{
x=EEPROM.get(address,x); //for getting eeprom value last stored when re powered
}else{
x=x;
}
}
void loop() {
RPM = analogRead(A0)*f; // calculation of sensor value
if (digitalRead(13)== 1) //when pin 13 will be high proceed to next step else update eeprom
{
if(digitalRead(14)==1) //when pin 14 will be high calculate x i.e. progressive hours
{
x+=y;
}
else {
x=x;
}} else {
EEPROM.update(address,x);
}
}
lcd.setCursor(0,1); //printing value of sensor in lcd in 1st line
lcd.print("RPM=");
lcd.print(RPM);
lcd.setCursor(0,2); //printing value of hours in second line of lcd
lcd.print("Engine Hrs.-");
lcd.print(x);
delay(100);
}
Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
You need to write your code in stages:
Write code for the LCD Display, debug it and get it working.
Write code for the EEPROM read and write, debug it and get it working.
Write code for the RPM detection and Calculation, debug it and get it working.
Write code for the Hour Calculation, debug it and get it working.
Combine the LCD Display code and the RPM Detection and Calculation, debug it and get it working.
Combine this code with the Hour Calculation Code, debug it and get it working.
Combine this code with the EEPROM code, debug it and get it working.
It may sound long and laborious but in the end it means you minimise errors and learn statement structure.