Pages: [1]   Go Down
Author Topic: An LED flash question!  (Read 442 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How do I flash an LED on for 100ms and off for 3000ms without using delay?

Thanks in advance.
Logged

Sydney, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1285
Big things come in large packages
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Look at the blink without delay example.
Logged

Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

Johannesburg. UTC+2
Online Online
Faraday Member
**
Karma: 108
Posts: 4729
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Look at the blink without delay example.

But you'll need to think about how to have two different intervals for on = 100ms and off = 3000ms. As that example stands, the led is off and on for the same interval...
Logged

The Elders of the Internet know who I am
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could someone point me in the right direction. I have uploaded the blink without delay, but cannot see how to get the 'short on' and 'long off'
Logged

UK
Offline Offline
God Member
*****
Karma: 17
Posts: 569
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You'll need to keep two delays, timers and a state record

E.g.

delayBlinkOn
delayBlinkOff
timerBlinkOn
timerBlinkOff
stateBlinkOn
stateBlinkOff

1) Turn your LED on and set stateBlinkOn to True and timerBlinkOn to the current millis().
2) While stateBlinkOn is true then you want to check timerBlinkOn each loop until it's equal or greater than millis() + delayBlinkOn.
3) Once the condition is met, turn your LED off and set stateBlinkOff to True and timerBlinkOff to current millis().
4) While stateBlinkOff is true then check the timerBlinkOff each loop until it's equal or greater than millis() +  delayBlinkOff.
5) Once the condition is met, you're back to turn your LED on at Step 1 above and the sequence repeats.

Now, go code that up. ;-)
Logged

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

All you need to do in the blink without delay is change the value of "interval" when you change the LED state.
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.

Pages: [1]   Go Up
Jump to: