Go Down

Topic: blink 1.05 (Read 3319 times) previous topic - next topic

GoForSmoke

From Blink.h, but the bolds are mine:
Quote

int schd(time_t,fptr_t);              /* Call a function at a specific time  */
int aftr(time_t,fptr_t);              /* Call a function after spec delay    */


BTW Morris, I downloaded from your link and while the file name is blink105.ino.. well, the comments are always the last thing to change, lol, right? My copy, the comment says 1.04.

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

dkl65

I saw that in the code. I looked there before asking. The problem is that I don't know the difference between "specific time" and "specific delay". I don't know how to use schd() either. For aftr(), I think that the aftr() statement needs to be inside the function with no parameters, and called in the setup. The function idle() must be put in the loop. That is shown in the example. Then, if you want to stop the function somewhere in the loop when some condition is met, how is that done?
Visit http://www.glenof.webs.com/!

GoForSmoke

- It's the difference between specific time '3 PM tomorrow' and specific delay 'an hour from now'.
One is absolute and the other is relative.

- Specific just means putting a value on it. '3 PM tomorrow' is specific, 'sometime later' is not. When someone asks "can you get more specific" they are asking for more details. In tech docs you will see the word 'Specifications', it's a certain class of details.

Mostly though I'd say go by the code and only use comments and variable names as guides at best, but be prepared to see differences even if only subtle. English is not Logic.

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

cyclegadget


   Nice contribution! I am going to try it out this weekend and see if my Novice level can grasp full use of it. :)
Good links: Eagle tutorial= http://www.youtube.com/playlist?list=PLDE1858BD83D19C70
General Arduion tutorials = http://tronixstuff.wordpress.com
http://www.gammon.com.au/forum/bbshowpost.php?bbtopic_id=123

dkl65


- It's the difference between specific time '3 PM tomorrow' and specific delay 'an hour from now'.
One is absolute and the other is relative.

So aftr() calls the function X milliseconds later. But, Arduino doesn't use hours, minutes, seconds, etc. like we do (e.g. 2012/06/08 3:18 PM EST) as absolute values. Then, how does one use schd()? Is the absolute time at a particular millis() value (e.g. run function when millis() hits 5000), or what?
Visit http://www.glenof.webs.com/!

GoForSmoke

Arduino millis clock starts up when the Arduino does. It is a clock with one hand that counts from zero to over 4 billion before circling back to zero again. With every tick at 1 ms the clock takes almost 50 days to cycle.

So what is the difference in code between do something 5000 millis from "now" and do something when the millis reaches 1 million?
In the code itself what is being compared is always millis and some number.  When we want something to happen in 1 hour we look at the time, add an hour and when the time reaches then it's time to do the thing. Events are run on a clock schedule, aftr() is a convenient way to set the time for an event without knowing when "now" is, and that makes it easier to use, but the code itself runs by the clock and aftr() uses schd() to work.

BTW if you're worried what happens when the millis clock rolls over, goes from 4,294,967,295 to 0 and what happens when you try to find the difference between 10 minutes "after midnight" and 10 minutes "before midnight" -- with unsigned math the small number minus the big number still gives the difference because the result is unsigned, in effect unsigned numbers go in circles like a clock dial so the difference (subtraction) between the two doesn't matter what part of the clock they are on it is still the difference.
Not that you need to understand how it works, the Event routines take care of that. But if you dig into the bit level of how it works, you should smile when you see the simplicity.
Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

dkl65

So schd() is just a function used by aftr()? So I should only care about aftr()?
Visit http://www.glenof.webs.com/!

cyclegadget


I have a question. This part of the code prints char "n" and increments it by 1 on each pass. It starts at 0 and rolls over after 255. Why is n not reset to 0 on each function call? The part that says n = 0; should reset n each time, am I mistaken?

void print(void)
{  static unsigned char n = 0;         /* Something to print                  */
   Serial.println(n++);                /* Send a caracter to serial monitor   */
   aftr(ss(1)/3,print);


If I could understand what is happening I would like to replace char n with an array like byte n[6] and print the array out piece by piece in a timed fashion. I would then later have to reset the array to 0 and start the process again.

Can anyone explain this.
Good links: Eagle tutorial= http://www.youtube.com/playlist?list=PLDE1858BD83D19C70
General Arduion tutorials = http://tronixstuff.wordpress.com
http://www.gammon.com.au/forum/bbshowpost.php?bbtopic_id=123

dxw00d

It's declared as static, which means its contents are maintained across functions calls.

http://arduino.cc/en/Reference/Static

GoForSmoke


So schd() is just a function used by aftr()? So I should only care about aftr()?


That depends on what you want to do. Using only aftr(), you won't be changing what you've scheduled to happen in any clean way.

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

cyclegadget


It's declared as static, which means its contents are maintained across functions calls.

http://arduino.cc/en/Reference/Static


Thank you for that! I am going to have to try out static declarations in the future, I have some ideas that need that solution!
Good links: Eagle tutorial= http://www.youtube.com/playlist?list=PLDE1858BD83D19C70
General Arduion tutorials = http://tronixstuff.wordpress.com
http://www.gammon.com.au/forum/bbshowpost.php?bbtopic_id=123

Go Up