Advice on how to improve my Traffic Light program esp32

It's better to learn the real approved way to do this, but you can find some hacks.

One is to write your own delay function, and have it hang things up for as long as the delay()would have done, whilst checking if you have a button pressed and just return immediately or… whatever, it's all code.

See this thread.

I searched these fora using "myDelay", as that is a popular name for this when it is done.

It is a quick, dirty and clever hack. You may or not care, the Arduino certainly does not.

HTH

a7