Using Multiple Sensors with a button using CircuitPython

Hi Guys.

I have received my Circuit Playground Express and strip lighting in the mail. I have managed to get quite a few of the sensors working and my lights to work now. However, I was hoping to have a few different modes. So when I press a button on the board, that it switches mode. So for example I could have a mode that uses the sound sensor, and a mode that uses the accelerometer and a mode that uses the thermometer etc. Then the colours and sequence of the lights will change based on the values of the data. Is this possible using CircuitPython? I have tried this is so many different ways without success.

Thank you.

Hi Claire,

I’d recommend making a state machine to do this.

I would separate your ‘modes’ into functions which you would want run in a particular state. By the sounds of it you’ll want 3 (sound, accelerometer, temperature). In your main micro-controller loop (while True:), check to see if the button of interest has been pressed and if so, let it increment a variable or set a flag. A couple of if-else statements below that should control the ‘flow’ of the state machine, namely which specific function(s) to call.

I’d also repeat the if-else string in your LED strip so that it can select the correct variable to display/sequence.

Hope this helps,
Christian

2 Likes