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 #56 background imageLoading...
Page #56 background image
Chapter 1 LED
56
www.freenove.com
support@freenove.com
19
20
21
22
23
24
25
26
27
printf("led on...\n");
delay(1000);
digitalWrite(ledPin, LOW); //led off
printf("...led off\n");
delay(1000);
}
return 0;
}
GPIO connected to ledPin in the circuit is GPIO17. And GPIO17 is defined as 0 in the wiringPi numbering. So
ledPin should be defined as 0 pin. You can refer to the corresponding table in Chapter 0.
#define ledPin 0
In the main function main(), initialize wiringPi first, and then print out the initial results. Once the initialization
fails, exit the program.
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);
After the wiringPi is initialized successfully, set the ledPin to output mode. And then enter the while cycle,
which is an endless loop. That is, the program will always be executed in this cycle, unless it is ended outside.
In this cycle, use digitalWrite (ledPin, HIGH) to make ledPin output high level, then LED is turned on. After a
period of time delay, use digitalWrite(ledPin, LOW) to make ledPin output low level, then LED is turned off,
which is followed by a delay. Repeat the cycle, then LED will start blinking.
pinMode(ledPin, OUTPUT);
while(1){
digitalWrite(ledPin, HIGH); //led is turned on
printf("led on...\n");
delay(1000);
digitalWrite(ledPin, LOW); //led is turned off
printf("...led off\n");
delay(1000);
}
Among them, the configuration function for GPIO is shown below as:
vo id p inMode(int pin, int mode);
This sets the mode of a pin to either INPUT, OUTPUT, PWM_OUTPUT or GPIO_CLOCK. Note that only
wiringPi pin 1 (BCM_GPIO 18) supports PWM output and only wiringPi pin 7 (BCM_GPIO 4) supports CLOCK
output modes.
This function has no effect when in Sys mode. If you need to change the pin mode, then you can do it with
the gpio program in a script before you start your program
vo id d igitalWrite ( int pin, int v alue);
Writes the value HIGH or LOW (1 or 0) to the given pin which must have been previously set as an output.
For more related functions, please refer to http://wiringpi.com/reference/

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