Arduino program not incrementing loop counter
Is the variable i declared as a global variable? i.e. at the top of the file outside all methods?

It may be getting overwritten by the loop inside your turnon_layer() method.

To test, just change the variable to letter k inside just one of your loops.