This repository goes hand in hand with this blog post and contains some basic examples of controlling GPIO lines on the Raspberry Pi with the use of an RGB LED using C and C++.
This is all very basic stuff, but should provide a very simple starting block for anyone new to the world of Raspberry Pi.
This repository contains a very small number of files:
- led_demo.cpp - Demo C++ application source
- led_select.c - Code used within the blog post
- Makefile - The makefile for the C and C++ applications
- Readme.md - This Readme file
This repository contains a Makefile, which should allow a simple call to make
:
pi@raspberrypi:~ $ make
Building led_demo
Successfully built led_demo
Building led_select
Successfully built led_select
and to clean, simply run make clean
:
pi@raspberrypi:~ $ make clean
Clean complete.
To build just the blog application (led_select), run:
pi@raspberrypi:~ $ make led_select
Building led_select
Successfully built led_select
or
pi@raspberrypi:~ $ gcc led_select.c -Wall -Wshadow -Wpedantic -lwiringP -o led_select
If you wish to build the demo application (led_demo), run:
pi@raspberrypi:~ $ make led_demo
Building led_demo
Successfully built led_demo
or
pi@raspberrypi:~ $ g++ led_demo.cpp -Wpedantic -Wshadow -Wall -lwiringPi -lpthread -o led_demo
Note the library requirements: wiringPi and pthread (required for software PWM)
This is the source used to build the blog example C application. This provides a very basic application that takes a single argument: red, green or blue.
pi@raspberrypi:~ $ ./led_select red
Turning the red LED on.
This is the source used to build a C++ application, which gives a more detailed example of things that can be done with an LED, including:
- mixing colours
- hardware PWM
- software PWM
Run the application ./led_demo
and follow the instructions on screen.
pi@raspberrypi:~ $ ./led_demo
Enter a letter from the following:
* R (Red)
* G (Green)
* B (Blue)
* C (Cyan)
* M (Magenta)
* Y (Yellow)
* W (White)
* F Free run - changes colour forever.
* P Pulse - pulses the green LED forever (hardware PWM).
* S Software PWM pulse - changes colour forever with software PWM fades.
* X Exit