EasyManuals Logo

Freenove Ultimate Starter Kit User Manual

Freenove Ultimate Starter Kit
286 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #118 background imageLoading...
Page #118 background image
Chapter 9 Potentiometer & RGBLED
118
www.freenove.com
support@freenove.com
Code
C Code 9.1.1 Colorful Softlight
First observe the project result, and then analyze the code.
1. Use cd command to enter 09.1.1_ColorfulSoftlight directory of C code.
cd ~/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/C_Code/09.1.1_ColorfulSoftlight
2. Use following command to compile "ColorfulSoftlight.c" and generate executable file "ColorfulSoftlight".
gcc ColorfulSoftlight.c -o ColorfulSoftlight -lwiringPi -lpthread
3. Then run the generated file "ColorfulSoftlight".
sudo ./ColorfulSoftlight
After the program is executed, rotate one of potentiometers, then the color of RGBLED will change
consequently. And the terminal window will print out the ADC value of each potentiometer.
The following is the program code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <wiringPi.h>
#include <pcf8591.h>
#include <stdio.h>
#include <softPwm.h>
#define address 0x48 //pcf8591 default address
#define pinbase 64 //any number above 64
#define A0 pinbase + 0
#define A1 pinbase + 1
#define A2 pinbase + 2
#define A3 pinbase + 3
#define ledRedPin 3 //define 3 pins of RGBLED
#define ledGreenPin 2
#define ledBluePin 0
int main(void){
int val_Red,val_Green,val_Blue;
if(wiringPiSetup() == -1){ //when initialize wiring failed, print message to screen
printf("setup wiringPi failed !");
return 1;
}
softPwmCreate(ledRedPin,0,100); //create 3 PWM output pins for RGBLED
softPwmCreate(ledGreenPin,0,100);

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Freenove Ultimate Starter Kit and is the answer not in the manual?

Freenove Ultimate Starter Kit Specifications

General IconGeneral
BrandFreenove
ModelUltimate Starter Kit
CategorySingle board computers
LanguageEnglish