#include <Arduino.h>
/*
* Name: lf_7_2_themenwoche_2.ino
* Date: 2023/04/26
* Author: heimvon2
* Version 1.0
* Wokwi-Simulation Arduino-Modul
*
* https://wokwi.com/projects/363049828620075009
*/
#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};
int id = 0;
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);
Serial.print("id;Fuellstand;Prozent;Liter");
Serial.println();
}
void loop() {
// Start a new measurement:
digitalWrite(PIN_TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(PIN_TRIG, LOW);
// Read the result:
float duration = pulseIn(PIN_ECHO, HIGH);
float abstand_cm = duration / 58.475 ;
float fuellstand_cm = 8 - abstand_cm ;
if (((fuellstand_cm / 8) * 100) < 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(fuellstand_cm + String(" cm "));
delay(1500);
lcd.setCursor(0, 1);
lcd.print((fuellstand_cm / 8) * 100 + String(" % "));
delay(1500);
lcd.setCursor(0, 1);
lcd.print(fuellstand_cm * 25000 + String(" l "));
delay(1500);
Serial.print(id);
Serial.print(";");
Serial.print(fuellstand_cm);
Serial.print(";");
Serial.print((fuellstand_cm / 8) * 100);
Serial.print(";");
Serial.print(fuellstand_cm * 25000);
Serial.println();
id++;
delay(1000);
}