it is certainly possible to port code from another microcontroller to an ESP32 - recently ported a very large program from a PIC24 to an ESP32
assuming you have a number of sensors, devices, etc attached to the Mega
for each of the sensors, devices, etc implement a separate test program on the ESP32  to ensure it works correctly
- you may be able to use the same libraries
 - the Mega uses 5V logic the ESP32 3.3V logic - you may have to use potential dividers or level converters interfacing some devices
 
you may have to change some of the devices to suit the ESP32
once you know everything works you can start implementing the complete progrm
with regard to the ADC it depends on your requirements - see fixing-the-non-linear-adc-of-an-esp32