Loop() to read input and cloud function calls?

Dear All,

I am working on a project that uses a sparkfun capacitive touchpad as a button to control a light switch. In the firmware loop() i listen to the input from the button and when it’s touched I call a function to turn on the relay, close the circuit and turn on/of the light. I also have a function to turn on/off the light to be called remotely from the cloud. The issue I’m having is that the photon device doesn’t always respond to the cloud call. What’s the best way to write a firmware that uses the loop to listen to input from a pin and at the same time responds to any cloud function call?


I don’t know why your cloud call would not work every time, unless your code in loop is blocking. The best way to pick up an asynchronous event, like a button touch, would be to use an interrupt. Just set a flag in your ISR, that the button was touched, and check that flag in loop.

1 Like