Pages: [1] 2   Go Down
Author Topic: Very confused about timing.  (Read 2764 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 28
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay guys, say i want Arduino to run a function for about 8 hours, ( from 8am to about 3pm, every day.

how would i do that?

Ive been reading about the millis() function, but i cant seem to get a grasp of it, not a single bit. i dont even have any sample code to show :/

any help is much appreciated!
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 241
Posts: 24480
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Eight hours in milliseconds:
8L * 60L * 60L * 1000L
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 28
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm... Lost. >_<

:/
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 241
Posts: 24480
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm... Lost
Post your code, and we'll draw you a map.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 28
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As i have it right now theres only the function code:
Code:
int readPin = A0;
int Value;
int Strobe = 6;

void setup() {
  pinMode(readPin, INPUT);
  pinMode(8, OUTPUT);
  pinMode(Strobe, OUTPUT);
  
  attachInterrupt(0, light, LOW);
  
}

void loop() {
  Value = analogRead(readPin);

     if ( Value >= 1) {
       digitalWrite(8, HIGH);
       delay(3000);
     }
     else {
       digitalWrite(8, LOW);
     }
  }
  
  void light() {
    digitalWrite(Strobe, HIGH);
  }
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 241
Posts: 24480
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And what do you want to do?

(Why hasn't poor pin 8 got a nice name?)
« Last Edit: January 14, 2011, 03:09:33 pm by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 553
Posts: 46299
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Arduino is a bit like a stop watch. When it powers up, or is reset, it starts the stop watch going.

The millis() function returns how long it has been since the stop watch was started.

What time does that correspond to? The Arduino has no idea, unless you tell it when you start it up, or connect a real time clock that can keep track of the real time.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 28
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hahah, code was drawn up in a hurry, as i need the prototype working smiley-razz

i need my Arduino to run the function inside loop() from 8:30 am to 5pm exactly, then shut down until the next day, and start again.

thanks a lot guys, for the attention and help smiley cheers!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 28
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

well im thinking about it like this, start the function ( when the arduino first powers up) run it for 8 1/2 hours, then stop for 15 1/2 hours, then run again, etc...

it doesnt need to know what time it is, just how long to run it for, and how long to stop running it for.

thats what gets me complicated >_<
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 553
Posts: 46299
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If the stop watch starts at the on time for a day, then record the first on time:

unsigned long onTime = millis();

Then, in loop, see if the current time minus the onTime is greater than 8/2 hours. If not, do the ON thing. If so, do the OFF thing.

Also, in loop, see if the current time minus the onTime is greater than 24 hours. If so, reset onTime to the current time.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 28
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sounds great. ill try and get it working, thank yoU!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 28
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

k guys, i still cant figure out the millis() function, does anyone have any code that could help? :S

im sorry for my noobness :/
Logged

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

You'd think there'd be a halfhour() function, wouldn't you?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 241
Posts: 24480
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i still cant figure out the millis() function

It just returns a number each time it is called.
That number is the number (roughly) of milliseconds since the processor was reset.

Say it returns 765, and you want to wait until another second has elapsed.
So, keep calling "millis" until the value returned, minus the number you first read (765) is greater than or equal to 1000.

Have a look at, and more importantly experiment with, the "blink without delay" example.

Quote
You'd think there'd be a halfhour() function, wouldn't you?
Now, just you wait a minute.
« Last Edit: January 14, 2011, 04:09:49 pm by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 553
Posts: 46299
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
You'd think there'd be a halfhour() function, wouldn't you?
What would this mythical function do? You're not thinking in terms of delayHalfHour() are you?
Logged

Pages: [1] 2   Go Up
Jump to: