Chapter 4 Analog & PWM
78
The wiringPi library of C provides a hardware PWM method, while wiringPi library of Python doesn’t provide
hardware PWM method. There is only software PWM for Python.
The hardware PWM only needs to be configured, does not occupy CPU resources, and is more precise in time
control. The software PWM requires the CPU to work all the time, using the code to output high level and low
level. This part of the code is carried out in multi-thread, and the time precision is relatively not high enough.
In Python, you can set its frequency. The duty cycle range is 0-100. You can set duty cycle with decimals, so
although it is 0-100, you set more than 100 levels.
For more details, please refer
http://wiringpi.com/reference/software-pwm-library/
Circuit
Schematic diagram
Hardware connection
Code
This project is designed to make PWM output GPIO18 with pulse width increasing from 0% to 100%, and then
reducing from 100% to 0% gradually.
C Code 4.1.1 BreathingLED
First observe the project result, and then analyze the code.
1.
Use cd command to enter 04.1.1_BreathingLED directory of C code.
cd ~/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/C_Code/04.1.1_BreathingLED
2.
Use following command to compile “BreathingLED.c” and generate executable file “BreathingLED”.
gcc BreathingLED.c -o BreathingLED -lwiringPi
3.
Then run the generated file “BreathingLED”
sudo ./ BreathingLED
Содержание Ultimate Starter Kit
Страница 1: ...Free your innovation Freenove is an open source electronics platform www freenove com ...
Страница 116: ...Chapter 9 Potentiometer RGBLED 116 www freenove com support freenove com Circuit Schematic diagram ...
Страница 117: ...117 Chapter 9 Potentiometer RGBLED www freenove com support freenove com Hardware connection ...
Страница 136: ...Chapter 12 Joystick 136 www freenove com support freenove com Circuit Schematic diagram Hardware connection ...
Страница 155: ...155 Chapter 14 Relay Motor www freenove com support freenove com Hardware connection OFF 3 3V ...
Страница 173: ...173 Chapter 16 Stepping Motor www freenove com support freenove com Hardware connection ...
Страница 182: ...Chapter 17 74HC595 LEDBar Graph 182 www freenove com support freenove com Circuit Schematic diagram Hardware connection ...
Страница 197: ...197 Chapter 18 74HC595 7 segment display www freenove com support freenove com Circuit Schematic diagram ...
Страница 198: ...Chapter 18 74HC595 7 segment display 198 www freenove com support freenove com Hardware connection ...
Страница 239: ...239 Chapter 22 Matrix Keypad www freenove com support freenove com Circuit Schematic diagram ...
Страница 240: ...Chapter 22 Matrix Keypad 240 www freenove com support freenove com Hardware connection ...
Страница 270: ...Chapter 26 WebIOPi IOT 270 www freenove com support freenove com Circuit Schematic diagram Hardware connection ...