Hello, i am trying to figure out the //best\ way to rework my code. I am making changes to how things are done. I currently have each condition setup like this:
if( sensorDifMin>=cfg.snd_no_readings ) {
Lots of code that is messy and unorganzided talking about
setting the lcd font color and passing serial.printin(no new data for 20 minutes or more)
if( (alarmDifference>alarm_repeat) && (snoozeRemaining<=0) checks for snooze if no snooze then
sndnoreadings(); (sound and led event)
no_reading_event = true;
what i want to do is have a if else statement in loop.
if(no_reading_event)
change lights to cyan
else
(check if condition b is true if not keep going to the next condition check (would be doing if else for all statements at any time 1 statement has to be true I know how to do it multiple ways but i want opinions. my overall goal is once the condition is set and done with its action (set led to cyan) do not repeat that action while looking for other conditions t be true. is that making sense?
It would be easier to see how your code is structured if you posted all of it. For instance, it is not clear from your description whether the if statements are nested within each other or not
This part
if( sensorDifMin>=cfg.snd_no_readings ) {
the second if is nested, however it closes right after that. so its structure is
if statement1
if time event different
else
if statement 2
if timbe event different2..
however the other section would be not nested in the loop()
I would upload my code but i have 2 conditions that stop me. This is a work project while eventually going to be open source for the time being i havn't been givne permission to share it in its entirty, i can give a lot of snippets where ever needed....and 2 the whole ino file is over 3k sloppy lines of code hehe
If(condition 1
if condition time is met 1
change leds to red
while condition1==true,
if condition2
if condition time is met 2
change led to green
while condition2==true?
Wouldn't that make it so as long as 1 is true it wont run that red command again but also wait for condition 2 to become true?
I think the way im going to do this is forget the while or for loops.
im going to do a loop like this and if memory it will work. as in the none loop function that gets signaled once and only once unless called upon again set the related condition to true. my idea was this..
if(condition1) {
code abc.....
condition1 = false; (at the end of its function/code block)
thinking that way next loop it wont be true anymore and it wont adjust say the red led. until 1 or any other condition is set true then this will run its function and set it back to false. is my assumption right?
It sounds a lot like you want to do something when a condition becomes true, not if a condition is true. Check out the State Change detection example in the IDE (File->examples->02.digital->State Change Detection) to learn how to accomplish this.