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 #67 background image
SunFounder ESP32 Starter Kit
pin: The GPIO pin number that the servo is connected to.
The min and max: the minimum and maximum pulse widths, respectively, in microseconds.
These values define the range of motion of the servo motor.
setPeriodHertz(int hertz): This function sets the PWM frequency for the servo motor in
hertz.
hertz: The desired PWM frequency in hertz. The default PWM frequency for servos is
50Hz, which is suitable for most applications.
5. The loop function is the main part of the code that continuously runs. It rotates the servo motor from 0 to
180 degrees, then back to 0 degrees. This is done by mapping the angle to the corresponding pulse width and
updating the servo motor with the new pulse width value.
void loop() {
// Rotate the servo from 0 to 180 degrees
for (int angle = 0; angle <= 180; angle++) {
int pulseWidth = map(angle, 0, 180, minPulseWidth, maxPulseWidth);
myServo.writeMicroseconds(pulseWidth);
delay(15);
}
// Rotate the servo from 180 to 0 degrees
for (int angle = 180; angle >= 0; angle--) {
int pulseWidth = map(angle, 0, 180, minPulseWidth, maxPulseWidth);
myServo.writeMicroseconds(pulseWidth);
delay(15);
}
}
writeMicroseconds(int value): This function sets the pulse width of the servo motor in
microseconds.
value: The desired pulse width in microseconds.
The writeMicroseconds(int value) function takes an integer value as its argu-
ment, representing the desired pulse width in microseconds. This value should typ-
ically fall within the range specified by the minimum and maximum pulse widths
(minPulseWidth and maxPulseWidth) defined earlier in the code. The function then
sets the pulse width for the servo motor, causing it to move to the corresponding position.
5. Sensors
1.17 5.1 Reading Button Value
In this interactive project, we’ll venture into the realm of button controls and LED manipulation.
The concept is straightforward yet effective. We’ll be reading the state of a button. When the button is pressed down,
it registers a high voltage level, or ‘high state. This action will then trigger an LED to light up.
Required Components
In this project, we need the following components.
Its definitely convenient to buy a whole kit, heres the link:
1.17. 5.1 Reading Button Value 61

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