Pi pico functions

Thread Starter


Joined Feb 26, 2021
I bought my first microcontroller a few months ago, for a project of mine.
I'm using Thonny to program it.
I've managed to work out some simple functions, but I just can't get my head around how to combine functions. I believe this should be possible?
Can someone please help me with the programming?

I have one load that should be controlled by one vibrationsensor and one photoresistor.

The Vibrationsensor is 1/0
When the vibrationsensor gets triggered it should hold for (x)seconds and if it gets triggered again under the (x)seconds it should restart the counting.

the photoresistor is an resistance based sensor.
an photoresistor should use the ADC port. Ive made it work fine to power the load when the photoresistor are in my disired value.
but how do i put this function in "series" with the vibrationsensor?

When both of these functions are TRUE the load shuld be powered

Sorry for an messy explanation.
// Nisse


Joined Jan 30, 2016
You need to use an "if" statement with combinatorial logic, eg

* the below assumes two
* variables ldrTriglevel and
* vibTriglevel which are the
* values above which the load
* should be energised, and two
* functions to get the current
* ldr and vib values from the
* hardware.
// get readings
ldrValue = getLDRreading();
vibValue = getVibreading();

// compare each with trigger level
// and combine with "and" logic &&

if ((ldrValue >= ldrTrigLevel)  && (vibValue >= vibTriglevel)) {

// do something interesting
else //optional
// do something else

//if your functions both return true
// or false then it's even simpler

if (getLDRreading() && getVibreading() ) {
// do something interesting
// do something else
Last edited: