Pages: 1 ... 4 5 [6]   Go Down
Author Topic: why no curly brackets in blink without delay ?  (Read 5782 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Offline Offline
Brattain Member
*****
Karma: 480
Posts: 18732
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I attempted to address that a while back with an "elapsed time" class:

http://www.gammon.com.au/forum/?id=11094

That handles the subtracting method of calculating delays (correctly doing wrap-around) and is fairly simple. The example also illustrates doing two delays. I think showing at least two delays makes it more obvious how to handle three or more.

Probably the main objection is that it hides the "real" technique behind a library, but then don't most low-level functions do the same thing? For example, delay() itself. (OK a function rather than a library, but there are time you don't really need to know the low-level detail).
Logged


New Jersey
Online Online
Faraday Member
**
Karma: 67
Posts: 3679
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
At least two, but many if it doesn't add too much complexity to use as a good self-teaching tool. More just to show that millis() can be used to track multiple time intervals used by multiple processes within a sketch. I just think the existing blink without delay example sketch is 'too simple' to show off the power and usefullness of the millis() function.
Sounds more like a case for adding another example - leave the simple version as it is to make it as easy as possible to follow.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17293
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Probably the main objection is that it hides the "real" technique behind a library, but then don't most low-level functions do the same thing? For example, delay() itself. (OK a function rather than a library, but there are time you don't really need to know the low-level detail).

Very nice implementation Nick. I would not hesitate to recommend it's usage. It would be best if a beginner at least tried to study the .cpp code to understand proper usage of millis() and how and why to properly subtract the interval amount, before using this library, but either way it sure might help in the fight against the nasty delay() function.  smiley-wink
Logged

London, GB
Offline Offline
Sr. Member
****
Karma: 8
Posts: 332
Nothing works.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I’d reach into the microprocessor’s whatsit accumulator register thingy where it keeps things in consciousness, and put my foot over all the most significant bits except the least three, to stop the big ones moving, then using my hands, rotate the least three significant bits just once. Then step back and make a cup of tea.
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dragging this back to the initial topic, when considering when to and not to use curly brackets, I always ask "WWDRD?"
Logged

0
Offline Offline
Faraday Member
**
Karma: 23
Posts: 3480
20 LEDs are enough
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

IMHO millis should not be used to control multiple process. Something like the mstimer2 library seems *much* more appropriate to me. Unfortunately it requires timer2. However I think we should go along the line of a suitable library.
Logged

Check out my experiments http://blog.blinkenlight.net

Pages: 1 ... 4 5 [6]   Go Up
Jump to: