EasyManuals Logo

SunFounder ESP32 User Manual

Default Icon
771 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 #72 background imageLoading...
Page #72 background image
SunFounder ESP32 Starter Kit
void loop() {
// read the state of the button value
buttonState = digitalRead(buttonPin);
Serial.println(buttonState);
delay(100);
// if the button is pressed, the buttonState is HIGH
if (buttonState == HIGH) {
// turn LED on
digitalWrite(ledPin, HIGH);
} else {
// turn LED off
digitalWrite(ledPin, LOW);
}
}
If the button is pressed and the buttonState is HIGH, the LED is turned on by setting the ledPin
to HIGH. Else, turn the LED off.
int digitalRead(uint8_t pin);: To read the state of a given pin configured as INPUT, the
function digitalRead is used. This function will return the logical state of the selected pin as HIGH
or LOW.
pin select GPIO
Serial.println(): Prints data to the serial port as human-readable ASCII text followed by a
carriage return character (ASCII 13, or ‘r’) and a newline character (ASCII 10, or ‘n’).
1.18 5.2 Tilt It
The tilt switch is a simple yet effective 2-pin device that contains a metal ball in its center. When the switch is in an
upright position, the two pins are electrically connected, allowing current to flow through. However, when the switch
is tilted or tilted at a certain angle, the metal ball moves and breaks the electrical connection between the pins.
In this project, we will utilize the tilt switch to control the illumination of an LED. By positioning the switch in a way
that triggers the tilt action, we can toggle the LED on and off based on the switchs orientation.
Required Components
In this project, we need the following components.
Its definitely convenient to buy a whole kit, heres the link:
Name ITEMS IN THIS KIT LINK
ESP32 Starter Kit 320+
You can also buy them separately from the links below.
66 Chapter 1. For Arduino User

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the SunFounder ESP32 and is the answer not in the manual?

SunFounder ESP32 Specifications

General IconGeneral
BrandSunFounder
ModelESP32
CategoryController
LanguageEnglish