Pages: 1 [2]   Go Down
Author Topic: blink 1.05  (Read 2845 times)
0 Members and 1 Guest are viewing this topic.
Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 91
Posts: 4690
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Offline Offline
Sr. Member
****
Karma: 1
Posts: 462
I am a amateur.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged


Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 91
Posts: 4690
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

- 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.

Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1328
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


   Nice contribution! I am going to try it out this weekend and see if my Novice level can grasp full use of it. smiley
Logged


Offline Offline
Sr. Member
****
Karma: 1
Posts: 462
I am a amateur.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

- 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?
Logged


Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 91
Posts: 4690
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Offline Offline
Sr. Member
****
Karma: 1
Posts: 462
I am a amateur.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1328
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


 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.
Logged


Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 91
Posts: 4690
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1328
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged


Pages: 1 [2]   Go Up
Jump to: