/*
* Name: lf_7_2.ino
* Date: 2023/01/11
* Author: heimvon2
* Version 1.0
* Wokwi-Simulation Arduino-Modul
*
* https://wokwi.com/projects/353549335887311873
*/
#include <LiquidCrystal.h>
#define PIN_TRIG 3
#define PIN_ECHO 2
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
byte warning_icon[8] = {B00100, B00100, B01110, B01010, B11011, B11111, B11011, B11111};
void setup() {
Serial.begin(115200);
pinMode(PIN_TRIG, OUTPUT);
pinMode(PIN_ECHO, INPUT);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("Fuellstand");
lcd.createChar(0, warning_icon);
}
void loop() {
// Start a new measurement:
digitalWrite(PIN_TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(PIN_TRIG, LOW);
// Read the result:
int duration = pulseIn(PIN_ECHO, HIGH);
if ((duration / 58.475 / 4) < 25) {
lcd.setCursor(12, 0);
lcd.print("Acht");
lcd.setCursor(12, 1);
lcd.print("ung");
lcd.write(byte(0));
} else {
lcd.setCursor(12, 0);
lcd.print(" ");
lcd.setCursor(12, 1);
lcd.print(" ");
}
lcd.setCursor(0, 1);
lcd.print(duration / 58.475 + String(" cm "));
delay(1000);
lcd.setCursor(0, 1);
lcd.print(duration / 58.475 / 4 + String(" % "));
delay(1000);
lcd.setCursor(0, 1);
lcd.print(duration / 58.475 * 500 + String(" l "));
delay(1000);
}