ee pulse - EEWeb
ee pulse - EEWeb
ee pulse - EEWeb
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
TECHNICAL ARTICLE<br />
Figure 1: Try telnet towels.blinkenlights.nl [2]<br />
Listing 1: BlinkWithoutDelay.ino<br />
/* Blink without Delay<br />
1<br />
2<br />
3<br />
4<br />
5<br />
6<br />
7<br />
8<br />
9<br />
10<br />
11<br />
12<br />
13<br />
14<br />
15<br />
16<br />
17<br />
18<br />
19<br />
20<br />
21<br />
22<br />
Turns on and off a light emitting diode (LED) connected to a digital<br />
pin, without using the delay() function. This means that other code<br />
can run at the same time without being interrupted by the LED code.<br />
The circuit:<br />
* LED attached from pin 13 to ground<br />
* Note: on most Arduinos, there is already an LED on the board<br />
that’s attached to pin 13, so no hardware is n<strong>ee</strong>ded for this example.<br />
created 2005<br />
by David A. Mellis<br />
modified 8 Feb 2010<br />
by Paul Stoffregen<br />
This example code is in the public domain<br />
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay<br />
*/<br />
Figure 2<br />
to understand what you wrote a long time ago. They<br />
(hopefully) explain what the program does, how it<br />
works, or why it’s written the way it is. It’s good practice<br />
to comment on your sketches and to k<strong>ee</strong>p the comments<br />
up-to-date when you modify the code. Remember, as a<br />
good ”open-source citizen,” to share your code so others<br />
can learn from or modify/improve your code.<br />
There’s another style for short, single-line comments.<br />
These start with // (e.g on line 26) and continue to the<br />
end of the line.<br />
To delay() or not to delay()? [5]<br />
The delay() function mentioned on line 4 and the hint<br />
not to use it so other code can run already looks weird<br />
to someone who used a RTOS or Unix/Linux before.<br />
Let’s have a closer look at it. From the Fr<strong>ee</strong>RTOS call<br />
vTaskDelay(500/portTICK RATE MS) [6], you would<br />
expect to delay a task for 500 msec. The fact that this<br />
API call delays/blocks a task for 500 msec means that<br />
it allows tasks with a lower priority to run until the time<br />
expires.<br />
In Linux usl<strong>ee</strong>p(500) [7], it would block the calling<br />
process for 500 msec and allow processes with a lower<br />
priority to run until the time expires – kind of.<br />
Description<br />
The delay() function pauses the program for the amount<br />
of time (in milliseconds) specified as parameter.<br />
(Remember: there are 1000 milliseconds in a second.)<br />
Syntax<br />
delay(ms)<br />
Parameters<br />
ms: the number of milliseconds to pause (unsigned long)<br />
Returns<br />
nothing<br />
(Figure 3)<br />
Caveat<br />
While it is easy to create a blinking LED with the delay()<br />
function, and many sketches use short delays for such<br />
tasks as switch debouncing, the use of delay() in a<br />
sketch has significant drawbacks. No other reading of<br />
sensors, mathematical calculations, or pin manipulation<br />
<strong>EEWeb</strong> | Electrical Engin<strong>ee</strong>ring Community Visit www.<strong>ee</strong>web.com 17<br />
TECHNICAL ARTICLE