I2C Library for LCD 0x27 or Ax07

Hello,

it doesn’t matter about sensor and motor but most important informations are missing.

  • What display are you using?
  • Did you test the library with the example program? That is, from my point of view, very good practice. I mean, try every library of each component separately with recommended example and when you know it works, then you can implement it to your project.

However i do not know why you choose exactly this library because most popular library for LCD under Mbed is TextLCD. HD44780 Text Display - #2 by JohnnyK

// Delay to avoid message spam

This is nor related to your issue but maybe try to use another variable for detection of sensor state change.

int main() {
	// Initial setup
	ThisThread::sleep_for(100ms); // Wait 100ms to ensure hardware is ready
	const char* startup_message = “mbed Fire Module Test\n”;
	pc.write(startup_message, 23); // Using known length to avoid strlen

	// Initialize the LCD
	lcd.setBacklight(TextLCD::LightOn);  // Turn on the backlight
	lcd.cls();  // Clear the screen
	lcd.printf("Flame Sensor Ready");

	int fire = 0;
	int fireLast = 0;

	while (true) {
		// Read the flame sensor
		fire = flame_sensor.read();
		if(fire != fireLast){  //will trigger necessary code only when it is needed
			if (fire == 1) {  // If high, fire is detected
				alarm = 1;  // Turn on the alarm
				motor_in1 = 1;  // Set motor direction (example)
				motor_in2 = 0;  // Set motor direction (example)
				motor_pwm = 0.8;  // Set motor speed (example: 80% duty cycle)
				const char* fire_msg = "Fire! Fire!\n";
				pc.write(fire_msg, 12);  // Using known length
				lcd.cls();
				lcd.locate(0, 0);  // Move to the first line, first column
				lcd.printf("Fire! Fire!");
			} else {
				alarm = 0;  // Turn off the alarm
				motor_pwm = 0;  // Stop the motor
				const char* no_fire_msg = "No Fire\n";
				pc.write(no_fire_msg, 8);  // Using known length
				lcd.cls();
				lcd.locate(0, 0);  // Move to the first line, first column
				lcd.printf("No Fire");
			}
		}
		fireLast = fire;

		// Delay to avoid message spam
		ThisThread::sleep_for(200ms);
	}
}

BR, Jan