// Program for attiny3216 to read water level sensor and display it on 4x20 LCD liquid crystal // created by Jans Hendry // Universitas Gadjah Mada, Indonesia // Kamakura Node, Japan // fab academy MIT - 2022 // the directives/predecessor #include #include // create lcd as an object // format: address, num of columns, num of rows LiquidCrystal_I2C lcd(0x27, 20, 4); // sensor pin const int tp_pin = 4; void setup() { // start serial Serial.begin(9600); // setting up lcd.init(); // turn on backlight <- the variable resistor has been adjusted lcd.backlight(); // clear screen lcd.clear(); // static display defDisplay(); // delay delay(500); } void loop() { int sensdata = analogRead(tp_pin); // read analogue data // Serial.print("Sensor reading: "); // Serial.println(sensdata); lcd.setCursor(12, 0); lcd.print(sensdata); // raw value send_sign(sensdata); // turn light indicator delay(1000); // take a break every 1 second } void defDisplay() { lcd.clear(); // clear display // static text lcd.setCursor(0, 0); lcd.print("Read-out "); lcd.setCursor(11, 0); lcd.print(":"); lcd.setCursor(0, 1); lcd.print("Status"); lcd.setCursor(11, 1); lcd.print(":"); } int send_sign(int tmp) { // turn light lcd.setCursor(12, 1); if (tmp >= 500) { lcd.print("HIGH "); } else if (tmp >= 300) { lcd.print("MIDDLE"); } else { lcd.print("LOW "); } return 0; }