Analoge Input - Conditional Control based on limits & debounce?

Hey Guys!

I am seeking some help with the following if possible please… This example is for level control - a worked example / suggestions with respect to how to code this would be really appreciated!

A0 set as analogue read (scaled 0-4095) using tag "value"
D0 set as Output using syntax "out_1"
D1 set as Output using syntax “out_2”

If value < 3072 for >5 seconds, D0 = HIGH
If value < 2048 for >5 seconds, D1 = HIGH (D0 still remains HIGH)

If value > 2048 for >5 seconds D1 = LOW
If value > 3072 for >5 seconds D0 = LOW

Any help most appreciated!!

TIA! :smiley:

Do you want us to write it for you, do you want suggestions, is there supposed to be a question to all this? What exactly is it that you want?
If I’m not mistaken, this seems awfully familiar to another question that popped up recently. That example used digital inputs, whereas this uses analog. Shouldn’t be too hard to swap those out and change the HIGH/LOW for the analog levels.
Come to think of it, that topic was yours as well…

1 Like

Hi There,

Firstly , please excuse me as I am new to the particle / C# platform and have come to the community forums to seek assistance to get me started with my project… Not sure what you are getting at as this is quite different from my previous question…?

My previous query was kindly answered by a valued member of the Particle team with which I am most appreciative of and as such the example has assisted me greatly. If you have any worked suggestions / examples that I can use for this TQ I would be grateful.

With Faith

That was kinda the thing, there was no query, there was/is just an explanation of what it is you're trying to achieve. It's quite common for people to ask questions, but those questions generally include... questions.
Are there any specific areas you're having difficulties with?
What have you tried so far?
Are you encountering errors?

The general template of questions we encounter is the following:

I want to do X.
I've tried Y.
It's doing Z.
Any ideas as to what's wrong with Y as to cause it not to do X?

Whereas you've only provided the first item. As such it's hard to see what you're hoping to get from us. Generally we tend to help out with issues and/or problems, not necessarily writing it for people. That's not to say that's a bad thing, but it'd help to know what we're getting into, and what your expectations are.


Actually, they're very similar...
To simplify your previous question:

if (button1_pressed_time > threshold_time){
  LED = HIGH;
}
if (button2_pressed){
  LED = OFF;
}

To simplify your current question:

if (analog_value_below_3072_time > treshold_time){
  D0 = HIGH;
}
if (analog_value_below_2048_time > treshold_time){
  D1 = HIGH
}
if (analog_value_above_3072_time > treshold_time){
  D0 = LOW;
}
if (analog_value_above_2048_time > treshold_time){
  D0 = LOW;
}

With that in mind, how about trying to edit your previous topic to the above and see how far you get. Should you encounter any issues, feel free to ask some (specific) questions :slight_smile: ?

2 Likes

Hey Moors7!

Thanks for your assistance with this mate, most appreciated.

I put together some code based on your recommendations + code example as previously provided by rickkas7 which is working great :smile:

//*** PUMP 1 CONDITIONS ***//

// If tank level PV is < Pump 1 cut-in SP
if (TnkLvlPV_Scl < Pump1_CutIn) {
    // debounce time is zero
	if (P1_Debounce_PV == 0) {
	    // Commence Counting
        P1_Debounce_PV = millis();
        }
        else {
            // If time counted in (ms) is > debounce SP
		    if (millis() - P1_Debounce_PV > P1_Debounce_SP) {
		        // Turn On Pump 1
                digitalWrite(Pump1_EN, HIGH);
            }
        }
    }
else {
	// Conditions are NOT met therefore debounce PV is zero
	P1_Debounce_PV = 0;
}