Hardware 8
Hardware
1.5: Using digitalWrite
Okay, so our program still doesn’t actually do anything. (So far, we have only ‘setup the pin’.) We need to tell
the microcontroller to actually interact with the LED. A way to do this is a function “digitalWrite”.
The word ‘digital’, in computers, means it can be on or o, low or high, 1 or 0. There are no in betweens
(later you’ll see analogWrite, which has in-between values). ‘Writing’ is computer-speak for output-
ting, or making something do something.
Here’s how digitalWrite might look:
digitalWrite(13,HIGH);
digitalWrite is the function name.
‘13’ is the pin number
‘HIGH’ is the output, which usually means to turn that pin on. The other option is ‘LOW’, which means to turn
the pin o.
Again, we have similar parentheses, commas and semi-colons.
Our overall goal is to get the LED to turn on and o repeatedly so this will go in our “loop” function.
voidsetup(){
//putyoursetupcodehere,torunonce:
pinMode(13,OUTPUT);
//setpin13tooutput,pin13isthebuilt-in
LED
}
voidloop(){
//putyourmaincodehere,torunrepeatedly:
digitalWrite(13,HIGH);//turnontheled
}
This is another good time to verify our program. As you get more experience, you can write more without
having to check, but it can get harder to gure out where errors come from.
After making sure the program is correct, we can upload, which is the arrow button next to verify. The
“upload” button moves the program onto the Galileo, from your computer, so that the microcontroller actu-
ally does something.
Some things may blink on the microcontroller as it is uploading, but you should see “upload complete” in
the bottom black window and your LED should turn on.