That command will create an executable file – "blinker". The "-l wiringPi"
part is important, it loads the wiringPi library. A successful compilation won't
produce any messages; if you got any errors, try to use the messages to
track them down.
Type this to execute your program:
pi@raspberrypi ~/code/c_example $ sudo ./blinker
The blinker program should begin doing it's thing. Make sure you've set up
the circuit just as modeled on the hardware setup page. Press the button to
blink the LED, release to have it turn off. The PWM-ing LED will be
brightest when the button is released, and dim when the button is pressed.
If typing all of that code in a bland, black-and-white, non-highlighting editor
hurt your brain, check out the next page where we introduce a simple IDE
that makes your programming more efficient.
Using an IDE!
Thus far we've been using simple text-editors – Leafpad or Nano – to write
our Python and C programs. So seasoned programmers are probably
missing a whole lot of features assumed of even the most basic editors:
auto-tabbing, context-highlighting, even automated building. If you want to
incorporate any of those features, we recommend using an IDE (integrated
development environment). One of our favorite Pi IDE's is Geany, here's
how to get it up and running.
Download and Install Geany
Geany isn't included with Raspbian, so you'll need an Internet connection to
download it. You can use the magical
command:
pi@raspberrypi ~/code $ sudo apt-get update
pi@raspberrypi ~/code $ sudo apt-get install geany
Once installed, you can run Geany by going to the "Start" menu, and
looking under the "Programming" tab.
Or, from the terminal, you can type
in Geany, directly from the command line. To open our previous C file, for
example, type
sudo geany blinker.c
Using Geany...
Once Geany is running, you can create a new file by going to File > New.
Saving the file as either ".c" or ".py" (or any other common language file
extension) will immediately inform Geany what kind of language you're
working with, so it can start highlighting your text.
Geany can be used with most languages, including the Python and C
examples we've just examined. Some tweaks to the default IDE options are
necessary, though. Here's an overview of using Geany with each language.
utility to install it with this
aptget
. You can even open a file
sudo geany
.
Page 15 of 17
Need help?
Do you have a question about the Raspberry gPIo and is the answer not in the manual?
Questions and answers