fixed mapAnalogtoPWM

I was setting the wrong flag for the main loop. Code needs significant
cleaning.