/* Inspired by Uri Shaked project at
  https://wokwi.com/arduino/projects/305193627138654786
  Layout used as starting point
*/

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);  //define I2C address 0x27, 16 column and 2 rows

void setup() {
  Serial.begin(9600); // enabling this line freezes program on lcd prints
  lcd.init();
  lcd.clear();
  lcd.backlight();
}

void loop() {
  int analogValue = analogRead(A0);
  Serial.println(analogValue);
  float flamelevel = map(analogValue, 0, 1024, 100, 0);
  Serial.print(flamelevel, 2);
  Serial.println("%");

  // disabling the lcd commands makes serial print work
  lcd.setCursor(2, 0);
  lcd.print(F("Flame: "));
  if (flamelevel > 50) {
    lcd.print("Bright");
  } else {
    lcd.print("Dim   ");
  }

  lcd.setCursor(0, 1);
  lcd.print("Level: ");
  lcd.print(flamelevel, 2);
  lcd.print("%    ");

  delay(100);
}