I want to trigger 2 things to happen at different millisecond intervals after i have taken my finger off a button.. I want the first command to happen within 500 milliseconds of taking my finger off the button and the second to happen between 500 and 1000 milliseconds..
I can get the first one happening up to 500 milliseconds with this code..
But realise there's no way to know for sure whether this code actually fires. If - due to some unknown delay - the loop takes longer than a second to repeat, the code will never actually be run. It's unlikely, but very possible.
Oh, and also, without some countermeasure, it's very likely the SendCode() statement will be exectuted multiple times. This may be exactly what you want, but you should be aware of it.
Cool that worked.. So is it ok to add multiple "&&" queries when using if controls ? For instance, could i add say 4 or 5 "&&" to create a really specific question ?
Also is there a way i can do something for a certain period of time without needing to put millis() into a variable and subtract it again to determine a count ? Is there a way to use SendCode() for 500 milliseconds ?
i should note its not totally critical if something held up the loop and it didnt run that code one time, as long as it worked 99% of the time..
I am working on a customised controller for a video camera.. I will be using buttons on a joystick to control zoom and other functions but for this bit of code i wanted the zoom to behave more fluently so when the user takes their finger off the button it eases back to a stop over a set amount of milliseconds, rather than just a dead stop..
Now that it looks like its working i can tweak the values to get it looking good.. I have already added 4 steps instead of 2 and its looking good. its got a kind of "rubbery" feel, but i'll keep it subtle and it will work well..
Cool that worked.. So is it ok to add multiple "&&" queries when using if controls ? If i had an If control could i add say 4 or 5 "&&" to c reate a really specific question ?
Yes, you can do that. Try reading up on some basic C/C++ syntax, that should solve a lot of your problems before you actually have them.
Also is there a way i can do something for a certain period of time without needing to put millis() into a variable and subtract it again to determine a count ? Is there a way to use SendCode() for 500 milliseconds ?
With the code you have now, you are not executing SendCode() for 500 milliseconds. It would be more accurate to say that there is a 500 ms window in which zero, one or multiple calls to SendCode() can be made.
If you really want to execute some specific command an unknown number of times in the next 500 ms, you should use a loop:
unsigned long start = millis();
while (millis() - start < 500) {
// Code in here is exectuted n times during the next 500 ms (n >= 0)
}
Edit:
I am working on a customised controller for a video camera.. I will be using buttons on a joystick to control zoom and other functions but for this bit of code i wanted the zoom to behave more fluently so when the user takes their finger off the button it eases back to a stop over a set amount of milliseconds, rather than just a dead stop..
Ah. In that case, it might be too much trouble to even consider using milliseconds. That's human thinking. Thinking in code, it's much easier and robuster to, say, keep zooming for 100 iterators after a user takes the finger off the button. You could slowly decrease the zoom speed to zero after the button is raised. This is simpeler and better defined than messing around with time intervals.
I actually have a line of code before the one you helped me with that does call SendCode() before the 500 milliseconds point.. The problem i had was, i wasnt able to get anything between 500 and 1000 or subsequent intervals after that but now i have this.. I have tweaked the times bit and added extra stages to get it looking better..
the values in send code are specific for the camera and that portion of the code is adapted from someone elses work who had already gotten arduino working with the camera protocol.. im so grateful that portion was done because i wouldnt have gotten that going on my own..
You have to excuse me, im really fumbling along at the moment so im not sure what iterators are ? the only way i thought of doing this was with millis()..
You have to excuse me, im really fumbling along at the moment so im not sure what iterators are ?
In this case, 'iterators' is a typo, I'm sorry to say. I meant to type 'iterations'. Which, in the context, would of course just mean doing something 100 times.
But if the code now works to your satisfaction, that's all you can hope for, right?
yeah its all good, thanks for your help.. Maybe down the track i will enahnce it as i get better.. i like to make things work as efficiently as possible, but as long as its functioning thats the main thing.