Hi, i am trying to control an air system and i want to power an air valve until a condition is met. This condition is the PSI from a sensor. This is for a preset for my suspension. ideally i can run this code and it will power the air valve UNTIL the psi is met. For instance, if the PSI i want to meet is 30 and the current psi is 0, i want to run the air valve until the 30psi is met. Thanks in advance!
Pseudo code:
if(psi < 30)
{
open air valve
}
else
{
close air valve
}
michelecioccarelli:
Interrupts are a bit advanced but nothing out of this world, in a nutshell they are a function (chunk of code) which are executed when a certain pin (pin 2 for arduino UNO and NANO) detects a change of voltage.
Interrupts are indeed advanced, and also absolutely no need for them to solve the problems you present.
Far better not having loops and delays in Arduino code at all if you want your sketch to be responsive and/or do more than one thing at once.
michelecioccarelli: Showing a beginner how to use delay and then offering interrupts as a sticking plaster for blocking code is no help at all. Especially so when their post doesn’t even require an internal loop or blocking in the first place.
To the OP: the blink without delay and state machine examples in the sticky tutorials thread are the correct place to start, should you need to address these problems.
boolean thing_is_on = false;
loop() {
boolean thing_should_be_on = /*
do whatever you have to do to work out if the thing is supposed to be on right now
*/;
if(!thing_is_on && thing_should_be_on) {
/* do whatever you have to do to turn the thing on */
thing_is_on = true;
}
else
if(thing_is_on && !thing_should_be_on) {
/* do whatever you have to do to turn the thing off */
thing_is_on = false;
}
}
michelecioccarelli:
There are 2 loops: for loops and while loops
and do...while loops.
That's three.
Hi yourwhyphy,
there is no way around learning hwo to pogram except paying somebody for developing a program for you.
I recommend reading this tutorial
It is easy to understand and a good mixture between writing about important concepts
and get you going.
best regards Stefan