Improve code with MQTT option

Hi guys.

I found this code to measure water flow in flowmeter with ir.

The code is here: https://github.com/kenanv/kamstrupmultical66 under multical66.ino

I will like to get this code to work in esphome or just with mqtt, can someone help me out to optimize the code?

Greetings DKAutomater