Sleep and WiFi Connecting

The problem was that WiFi has some calls (like credentials, connect) that block the loop kind of long. This made my application seem unresponsive, because it didn’t directly respond.

I’ve ended up using a Timer that calls a readInputs function. In this function I do all the digitalRead/analogReads and act based on that. This function is called each ms, also when WiFi is busy.

I’ve found out that interrupts don’t work good with debouncing a switch, so this will let me implement the ClickButton library as well.

It also makes it possible to read analog sensors.

If the WiFi calls are done the Photon is set the sleep in the loop (based on a flag set in the readInputs function.