You are on page 1of 9

Home

Arduino Tutorials

About Me

Tw eet

Like

Share

Search

Arduino Tutorial Series The MillisBased Delay


Posted on January 4, 2013 by admin

t opics
android app arduino code do it yourself Extra gadgets hacking gadgets just looking my projects Software
pdfcrowd.com

... A short example of delay based on millis(). I feel like writing a sketch for myself but could not yet think of what applications I can use it. Maybe I just like to sharpen my sketch writing ability. I am sure it will be useful for my future endeavor.

unsigned long timedelay = millis();


open in browser PRO version
Are you a developer? Try out the HTML to PDF API

const int interval = 5000; void setup(){//void setup start Serial.begin(9600); }//void setup end void loop() {//void loop start if ((millis()-timedelay) > interval){ Serial.println("HOORAYYYYYYYYYYYYYYY"); Serial.println("5 seconds have passed"); Serial.println("change the interval value and see"); Serial.println("or replace it with a LED"); timedelay = millis(); } }//void loop end

r ec ent ar t ic les
Western Digital My Passport 1TB Intel RST for Cooler Platform Controller Hub (PCH) I Installed a Lincensed ESET NOD32 Antivirus! The Tale of Impulsive Upgrader | From Windows.3x to Windows 8 / 8.1 Bluetooth File Transfer Protocol Version 2 Blocking The Globe Tattoo Ghost Web Icon A Laptop Cooling Pad Test

Another example of millis-based delay The two LEDs will blink independently. The one will blink every one second and the other for every five seconds. Each led has their own time interval and wont wait for each other.

r ec ent comment s
tan on Fixing the Slow Arduino IDE | More Than 20 Seconds

// DECLARING TWO VARIABLES AND // EQUATING IT TO millis() unsigned long timedelayone = millis();
open in browser PRO version
Are you a developer? Try out the HTML to PDF API

Delay Aldion on The Huawei Mobile Pocket Wifi E5220


pdfcrowd.com

unsigned long timedelaytwo = millis(); // DECLARING TWO TIME // INTERVALS const int intervalone = 1000; const int intervaltwo = 5000; // TWO LEDs on pin to and // pin three const byte ledone = 2; const byte ledtwo = 3; void setup(){//void setup start // DECLARE ledone and ledto // AS OUTPUT pinMode(ledone,OUTPUT); pinMode(ledtwo,OUTPUT); }//void setup end // TURN THE ledone ON // SHORTLY void blinkone(){//blinkone start digitalWrite(ledone,HIGH); delay(50); digitalWrite(ledone,LOW); }//blinkone end // TURN THE ledtwo ON // SHORTLY void blinktwo(){//blinktwo start
open in browser PRO version
Are you a developer? Try out the HTML to PDF API

Pocket Wifi E5220 Aldion on The Huawei Mobile Pocket Wifi E5220 admin on Gizduino Mini on Windows 7 and Windows 8 loreen on Gizduino Mini on Windows 7 and Windows 8

t ags

android arduino
battery camera computer ddwrt

electricity epson fan freedom


plan drive

globe hard disk hard


huawei internet

laptop lcd ldr led leds linux


mmorpg m otor mp3 phone potentiometer pow er supply psu push button

qos router samsung

sd card seven segm ents smart sony


stepper m otor

sun cellular
pdfcrowd.com

void blinktwo(){//blinktwo start digitalWrite(ledtwo,HIGH); delay(50); digitalWrite(ledtwo,LOW); }//blinktwo end void loop() {//void loop start // BLINK THE LED ONE EVERY AFTER // THE SPECIFIED INTERVAL if ((millis()-timedelayone) > intervalone){ blinkone(); timedelayone = millis(); } // BLINK THE LED TWO EVERY AFTER // THE SPECIFIED INTERVAL if ((millis()-timedelaytwo) > intervaltwo){ blinktwo(); timedelaytwo = millis(); } }//void loop end

tattoo toshiba usb wifi


windows w ire wordpress

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Yet another version. I completely removed the delay functions and replaced too with millis.

// DECLARING TWO VARIABLES AND // EQUATING IT TO millis() unsigned long timedelayone = millis(); unsigned long timedelaytwo = millis(); // DECLARING TWO TIME // INTERVALS const int intervalone = 1000; const int intervaltwo = 5000;
open in browser PRO version
Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

const int blinkinterval = 100; // TWO LEDs on pin to and // pin three const byte ledone = 2; const byte ledtwo = 3; void setup(){//void setup start // DECLARE ledone and ledto // AS OUTPUT pinMode(ledone,OUTPUT); pinMode(ledtwo,OUTPUT); }//void setup end

void loop() {//void loop start

// BLINK THE LED ONE EVERY AFTER // THE SPECIFIED INTERVAL if ((millis()-timedelayone) > intervalone){ digitalWrite(ledone,HIGH); timedelayone = millis(); } if ((millis()-timedelayone) > blinkinterval){ digitalWrite(ledone,LOW); } // BLINK THE LED TWO EVERY AFTER // THE SPECIFIED INTERVAL
open in browser PRO version
Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

if ((millis()-timedelaytwo) > intervaltwo){ digitalWrite(ledtwo,HIGH); timedelaytwo = millis(); } if ((millis()-timedelaytwo) > blinkinterval){ digitalWrite(ledtwo,LOW); }

}//void loop end


RE L A T E D P O S T S

1. Arduino Tutorial Series Stay ON LED Using Millis-Based Debouncing 2. Arduino Tutorial Series The On-board Blinking LED 3. Arduino Tutorial Series Seven Segments Part 1 4. Arduino Tutorial Series Running Epson Stepper Motor EM-546 ...
0 Tw eet 0 Like Share 2

This entry was posted in arduino and tagged arduino, millis by admin. Bookmark the permalink.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Leave a Reply
Your email address will not be published. Required fields are marked *

Name

Email

Website

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Post Comment

At Home, Using Huawei E357 Globe 4G USB Stick Arduino Tutorial Series Stay ON LED Using Millis-Based Debouncing

by luntianlaboratory.com 2010-2012 see change log, site rules & stuff posts with pictures of luntiancorner.com were moved articles. they are owned by the same author

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

You might also like