Pi pico functions

Nisse33

Joined Feb 26, 2021
4
Hello,
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?

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?

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

Sorry for an messy explanation.
Thanks
// Nisse

Irving

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

C-like:
/***
* 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.
***/

// 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

// do something interesting
}
else
{
// do something else
}

Last edited: