Hi i want to run a motor if a part of my code runs continuously for 1 minute how should i modify my code.code attached
final2.ino (1.82 KB)
Hi i want to run a motor if a part of my code runs continuously for 1 minute how should i modify my code.code attached
final2.ino (1.82 KB)
The loop() does run continously. So if the temp is above 20 it will run continously. Your code misses a closing }
the motor should only run if the distance crosses certain threshold continuously for a minute,not less than it.
I glanced at your code, meaning that I have not analyzed each line - which is usually what is needed to find all the bugs and misunderstandings. So the advice is prehaps a bit off.
You seem to be on the right track with your counter logic - but you have both count
and counter
; you increment and test on one and reset the other ... Instead of delay()
'ing seconds at a time, compare the millis to 60000UL
directly. Yes, that is spelled right - the UL at the end of the number makes it a Unsigned-Long-Integer
. Make sure your "counter" you compare to is unsigned long (as you have done to one).
I have no idea what you are trying to do with
int current_values[3] = [x1,y1,z1];
as your compiler said, that's non-parsable, errenous code.
So I cant fix this. (Of course rewrite it, but then I am not a developer-for-hire) You're close, so I suggest you start with writing down the steps. Well, I'll do my shorted version.
Loop
Check temp
Temp<20
reset timer
else (no need to test, we KNOW it is >=20)
is millis-timer < 60000UL
yes - set the vibrator motor on
else (we know the timer has expired)
set motor off