Calling All Master Code Writers!

Hello, I need some help with writing a portion of code for a project I am working on. I am pretty familiar with the basics and normally have good luck searching the web to find ways to write what I am trying to do, but I am stuck on Write(RE)Writing values for temporary use. And holding that temporary value for a certain amount of time until its wrote over with a new value.

So here is what I am trying to do so whoever can knock this out for me that would be awesome!

*** I have values x, y, and z. x is the raw data from an input, y is the average data value of x, z
is range between two values. I want to freeze/hold/save; y's value in 2 second
increments while within the z range & void any value to use to average if out of this range. If the x value
becomes a value of +100 over the held y value I want to trigger an event, but also void holding a new value
until the x value returns to within the z range.***

I know what I want to do just don't know how to go about doing it. Might be easy for someone that is proficient in writing code but not for me.
Any help will be greatly appreciated!

Anyone? Or if what I am trying to do is even possible?

It sounds entirely possible, but you need to more clearly state what you are trying to do, what the project is, and post any code you have (Don't forget code tags). Also, this forum is generally used more for offering to pay for help or otherwise become a major collaborator on a larger project, not just answer quests. I would possibly look in the programming questions forum, and delete this thread from here so you aren't cross-posting (Don't forget all of the above information).

That sounds as if it's just a matter of including some logic to decide when to update some saved values from the live values. The logic you describe doesn't seem as if it would be especially difficult to code. I'm not going to code it for you - if you want that, you could post a request for help in the Gigs and Collaborations section. Note that most people would expect to be paid to work for you.

Sound like someone's homework!

Thanks for the replies.

If anyone can point me to where I can find information on how to save information and choose when to update again that would be helpful too.

For example.

if(sensorvalue is between 50&-50);
{
Save SensorValue to temp, Keep in temp for xx seconds;
}
else if(sensorValue is not between 50 & -50);
{
Do not save to temp, keep last saved sensorValue until sensorValue is between 50&-50;
}
}

Ok, Compile! :slight_smile:
I'm sure its not that easy but I don't know what functions/statements/variables/ to use to accomplish it.

I thought you were familiar with the basics? If your only storing the value when it is within the range of +-z, then you don't need an ELSE statement, unless you do want to do something if it is out of range.

if( x >= (z *-1) && x <= z)
{
//store value, temp = y
}

HazardsMind:
I thought you were familiar with the basics? If your only storing the value when it is within the range of +-z, then you don't need an ELSE statement, unless you do want to do something if it is out of range.

if( x >= (z *-1) && x <= z)
{
//store value, temp = y
}

I am already using a similar version of your example in my program right now . I just don't know the correct way to save data and hold that data for a specific amount of time is all.

Why do you want to clear the variable after X time, why not just overwrite it when a new value is in range?

Anyway, you want to look at the example sketch blink without delay to see how things can be done after X time has passed.

I actually got it to work.

Supposedly when you are averaging values within a range and when it leaves that range the number stops at the last value it averaged until it is back in that range. So it actually does what I wanted to do automatically without creating hold times and writing/saving. Pretty cool!