Download Print this page

Intel Galileo Hardware Manual page 9

Biobots
Hide thumbs Also See for Galileo:

Advertisement

Hardware
1.6: Using delay
We want our microcontroller to blink, but right now it just stays on. We have to tell the microcontroller to
turn on and off. But, we have to leave some time in between so that we can actually see the blinking.
One way to do this is to use the "
this:
delay(500);
delay
The arguments for
500
telling it to wait
milliseconds, or half of a second.
In our program we want to turn on the LED, then wait, then turn it off, then wait. This means our program
will look like this:
void setup() {
// put your setup code here, to run once:
//set pin 13 to output, pin 13 is the built-in
led
}
void loop() {
// put your main code here, to run repeatedly:
}
Now we can try verifying again. If there are errors try putting slashes before a line, making it a comment,
and verifying again. If the error goes away, you know it was in the line you commented out, otherwise you
can look at other lines.
We can upload again. If everything is correct, you should see your microcontroller's LED blinking once a
second. (Refer to Lesson 1 Figure 3)
Try changing things around in the program, such as the blinking time. See what works, and what doesn't.
(You can also look at the program under file->examples->01.Basics->Blink.
delay
" function. Delay means to wait, or to stop for a time. You use it like
are the time in milliseconds (1/1000th of a second) that you want to wait for. I'm
pinMode(13, OUTPUT);
digitalWrite(13, HIGH); //turn on the led
delay(500); //wait
digitalWrite(13, LOW); //turn off the led
delay(500); //wait
Hardware 9

Advertisement

loading