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 #62 background imageLoading...
Page #62 background image
Chapter 2 Button & LED
62
www.freenove.com
support@freenove.com
28
29
30
31
}
}
return 0;
}
In the circuit connection, LED and Button are connected with GPIO17 and GPIO18 respectively, which
correspond to 0 and 1 respectively in wiringPI. So define ledPin and buttonPin as 0 and 1 respectively.
#define ledPin 0 //define the ledPin
#define buttonPin 1 //define the buttonPin
In the while cycle of main function, use digitalRead(buttonPin) to determine the state of Button. When the
button is pressed, the function returns low level, the result of “if is true, and then turn on LED. Or, turn off
LED.
if(digitalRead(buttonPin) == LOW){ //button has pressed down
digitalWrite(ledPin, HIGH); //led on
printf("led on...\n");
}
else { //button has released
digitalWrite(ledPin, LOW); //led off
printf("...led off\n");
}
About digitalRead():
int digitalRead (int pin);
This function returns the value read at the given pin. It will be HIGH or LOW(1 or 0) depending on the
logic level at the pin.

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