I had programming to use LiquidCrystal_I2C, and integrated find I2C address and use LCD. So I use class, but it has something wrong. I made just one object, but the program loop back a specific part
Here is my code
//main.ino
#include "LCD.h"
LCD_CUSTOM LCD;
void setup() {
}
void loop() {
// put your main code here, to run repeatedly:
}
//LCD.h
#ifndef LCDLibrary_H
#define LCDLibrary_H
#include "Arduino.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
class LCD_CUSTOM {
public:
uint8_t address;
LCD_CUSTOM() {
Serial.begin(9600);
address = 0;
init();
running();
};
private:
void init();
void running();
};
#endif
// LCD.cpp
#include "LCD.h"
void LCD_CUSTOM::init() {
Wire.begin();
Serial.println("\n--------------------I2C Scanner--------------------");
Serial.println(LCD_CUSTOM::address);
byte error = 0;
int nDevices;
Serial.println("active"); // loop back point.
for(LCD_CUSTOM::address = 1; LCD_CUSTOM::address < 127; LCD_CUSTOM::address++)
{
Wire.beginTransmission(LCD_CUSTOM::address);
error = Wire.endTransmission();
if(error == 0)
{
Serial.print("I2C device found at :address 0x");
if(LCD_CUSTOM::address < 16)
Serial.println(" !");
Serial.print(LCD_CUSTOM::address, HEX);
Serial.println(" !");
break;
}
else if(error==4) {
Serial.print("Unknow error at address 0x");
if(LCD_CUSTOM::address<16)
Serial.print("0");
Serial.println(LCD_CUSTOM::address, HEX);
}
}
if(LCD_CUSTOM::address == 127)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
Serial.println("\n--------------------I2C Scanner End--------------------");
Serial.println("Init complete. Running LCD");
}
void LCD_CUSTOM::running() {
LiquidCrystal_I2C lcd(address, 16, 2);
lcd.begin();
lcd.print("Hello, World!");
}