![]() ![]() If you want it to trigger once, then not trigger again until the interval has passed then you'll need to change it like this. the function put the number + millis() into a variable, and does a while loop as long as the millis() is smaller than the variable. The way I've written it above it will keep on triggering and resetting the 0.5s timer if the light level stays above the threshold value. The first problem, while loop doesnt stop at all, and the second is if it starts with a. In pseudo code: interval = 500 // 500 milliseconds = 0.5 seconds Im trying to create a robot that follows a line but only after you press the button, and when both sensors read stop then stop the while loop. But, if the number of times to do something is unknown, a for loop is not the right construct to use. There are circumstances that can change that fixed number of times. This loop will continue to execute over and. If a sufficient interval has passed compared with your first time then you do something. In the sketch above, the first time loop() is called, the delay(10000) stops everything for 10secs before turning the led off and continuing. A for loop is meant to iterate a fixed number of times. Since event1 is equal to 1000, the if statement condition is false, and the code in the curly brackets doesnt run. Is the entire sketch slowed to the time period in this millis function I am using TinyGPS as well as code for reading an HMC6352 magnetic compass in a first attempt at making a 'Marine Autopilot. The basic idea is your code makes a note of the current time (using millis), carries on looping round doing whatever it wants but each time through the loop you check what the current time is now. TinyGPS has a millis function in a 'while' loop, to assure new data is available before trying to write lat, lon etc. ![]() Try looking at one of the example sketches that comes with the IDE - I think it's called "BlinkWithoutDelay" or something like that. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |