'void LiquidCrystal_I2C::init()'
I am having this proplem every time then i verify my code
Can someone help me?
It would help if you post the exact compiler's message and share your code and link to the library you are using.
There are multiple LiquidCrystal libraries and some use begin() and other init() so you might have picked the wrong one.
Drop LiquidCrystal_I2C and use that one hd44780 - Arduino Reference
Arduino: 1.8.19 (Windows 7), Placa:"Arduino Uno"
C:\Users\enzo siman\Documents\Arduino\sketch_mar22a\sketch_mar22a.ino: In function 'void setup()':
sketch_mar22a:24:7: error: invalid use of non-static member function 'void LiquidCrystal_I2C::init()'
lcd.init ;
In file included from C:\Users\enzo siman\Documents\Arduino\sketch_mar22a\sketch_mar22a.ino:7:0:
C:\Users\enzo siman\Documents\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:87:8: note: declared here
void init();
^~~~
C:\Users\enzo siman\Documents\Arduino\sketch_mar22a\sketch_mar22a.ino: In function 'void loop()':
sketch_mar22a:35:37: error: 'unsigned int Ultrasonic::timing()' is private within this context
long microsec = ultrasonic.timing();
^
In file included from C:\Users\enzo siman\Documents\Arduino\sketch_mar22a\sketch_mar22a.ino:5:0:
C:\Users\enzo siman\Documents\Arduino\libraries\Ultrasonic\src/Ultrasonic.h:43:18: note: declared private here
unsigned int timing();
^~~~~~
sketch_mar22a:38:23: error: 'class Ultrasonic' has no member named 'convert'
cmMsec = ultrasonic.convert(microsec, Ultrasonic::CM);
^~~~~~~
In file included from C:\Users\enzo siman\Documents\Arduino\sketch_mar22a\sketch_mar22a.ino:5:0:
C:\Users\enzo siman\Documents\Arduino\libraries\Ultrasonic\src/Ultrasonic.h:26:12: error: expected unqualified-id before numeric constant
#define CM 28
^\Arduino\sketch_mar22a\sketch_mar22a.ino:38:53: note: in expansion of macro 'CM'
cmMsec = ultrasonic.convert(microsec, Ultrasonic::CM);
^~
exit status 1
invalid use of non-static member function 'void LiquidCrystal_I2C::init()'
is this the error code
this is the code i'm am using
#include <Ultrasonic.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define pin_trigger 4
#define pin_echo 5
LiquidCrystal_I2C lcd(0x27,20,4);
Ultrasonic ultrasonic(pin_trigger, pin_echo);
void setup()
{
Serial.begin(9600);
lcd.begin(16,2);
lcd.clear();
lcd.init ;
}
void loop()
{
float cmMsec;
//float inMsec;
long microsec = ultrasonic.timing();
cmMsec = ultrasonic.convert(microsec, Ultrasonic::CM);
//inMsec = ultrasonic.convert(microsec, Ultrasonic::IN);
String cmMsecToMetersFinal = String(cmMsec/100);
String cmMsecString = String(cmMsec, 0); //. RCosta.
String cmMsecStringFinal = cmMsecString + " cm";
String mMsecToMetersFinal = cmMsecToMetersFinal + " m";
//--------------------------------------------------------------------------
lcd.setCursor(0,0);
lcd.print("Dist.1: ");
lcd.print(" ");
lcd.setCursor(9,0);
lcd.print(cmMsecStringFinal);
//lcd.print("cm");
Serial.print("Cent: ");
Serial.print(cmMsecStringFinal);
lcd.setCursor(0,1);
lcd.print("Dist.2: ");
lcd.print(" ");
lcd.setCursor(8,1);
lcd.print(mMsecToMetersFinal);
Serial.print(", meters: ");
Serial.println(mMsecToMetersFinal);
delay(1000);
}
Remove the line with lcd.init ;
// lcd.init ;
If you use the "Ultrasonic" library from the Library Manager, then you have this library: https://github.com/ErickSimoes/Ultrasonic
Here is an example how to use it: https://github.com/ErickSimoes/Ultrasonic/blob/master/examples/UltrasonicSimple/UltrasonicSimple.ino
If you found that sketch online, then you have to check again to see which library they used.
ok thanks
Hello, do yourself a favour and please read How to get the best out of this forum and post accordingly (including code with code tags and necessary documentation for your ask like your exact circuit and power supply, links to components etc).
ā It would be appreciated if you were to edit your existing post and fix it by adding the code tags where they belong.