55
Chapter 1 LED
Code
According to the circuit, when the GPIO17 of RPi output high level, LED is turned on. Conversely, when the
GPIO17 RPi output low level, LED is turned off. Therefore, we can let GPIO17 output high and low level in
cycle to make LED blink. We will use both C code and Python code to achieve the target.
C Code 1.1.1 Blink
First, execute command into the terminal one by one. Then observe the project result, and analyze the code.
1.
Use cd command to enter 01.1.1_Blink directory of C code.
cd ~/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/C_Code/01.1.1_Blink
2.
Use the following command to compile the code “Blink.c” and generate executable file “Blink”.
“l” of “lwiringPi” is low case of “L”.
gcc Blink.c -o Blink -lwiringPi
3.
Then run the generated file “blink”.
sudo ./Blink
Now, LED start blink.
You can press “Ctrl+C” to end the program. The following is the program code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <wiringPi.h>
#include <stdio.h>
#define ledPin 0
int
main
(
void
)
{
if
(
wiringPiSetup
()
==
-
1
){
//when initialize wiring failed, print message to screen
printf
(
"setup wiringPi failed !"
);
return
1
;
}
//when initialize wiring successfully, print message to screen
printf
(
"wiringPi initialize successfully, GPIO %d(wiringPi pin) \n"
,
ledPin
);
pinMode
(
ledPin
,
OUTPUT
);
while
(
1
){
digitalWrite
(
ledPin
,
HIGH
);
//led on
Содержание 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 ...