Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Banana Pi Cookbook

You're reading from   Banana Pi Cookbook Over 25 recipes to build projects and applications for multiple platforms with Banana Pi

Arrow left icon
Product type Paperback
Published in Jun 2015
Publisher
ISBN-13 9781783552443
Length 200 pages
Edition 1st Edition
Arrow right icon
Authors (2):
Arrow left icon
Ryad El-Dajani Ryad El-Dajani
Author Profile Icon Ryad El-Dajani
Ryad El-Dajani
RYAD E DAJANI RYAD E DAJANI
Author Profile Icon RYAD E DAJANI
RYAD E DAJANI
Arrow right icon
View More author details
Toc

Programming the LED

Switching on an LED by a command is one thing. The other is controlling the LED programmatically. In this recipe, we are going to write a real program in C and in Python to switch the LED on and off periodically.

Getting ready

We require the very same breadboard construction from the previous recipe:

  • A Linux system on the Banana Pi
  • Access to the shell
  • A 5 mm LED (forward voltage 2.0 V)
  • A 470 Ω resistor
  • A breadboard
  • Two female to male jumper wires

Construct the circuit as we have seen previously.

How to do it…

Once we have the construction, we can proceed with the steps given in the following sections.

Programming the LED with C

We start by programming the LED in the classic C programming language.

  1. Power on your Banana Pi.
  2. Open a shell.
  3. Create a source code directory and change location to it:
    $ mkdir ~/source
    $ cd ~/source
    
  4. Create a source file using nano:
    $ nano led_test.c
    
  5. The nano editor will open. Write the following code in C:
    #include <wiringPi.h>
    
    int main(void...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image