EasyManua.ls Logo

Keyestudio ESP32 - 4. Test Result; 6. Code Explanation; Project 7: Active Buzzer; 1. Description

Keyestudio ESP32
344 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
ESP32 Starter Kit
(continued from previous page)
digitalWrite(i,HIGH);
delay(200);
digitalWrite(i,LOW);
}
for(int i = 15; i >= 12; i--){ //Use "for" loop statement to light up
˓LED on IO15-IO12 pin in sequence
digitalWrite(i,HIGH);
delay(200);
digitalWrite(i,LOW);
}
}
4. Test Result
After uploading code and powering on, the LEDs go from left to right and then from right to left
6. Code Explanation
for(int i = 12;i <= 15 ;i++){ pinMode(i,OUTPUT); } : We can use “for” statement to define continuous pins. Yet it
features a disadvantage of non-replacement ability of pins, which deteriorates the code portability.
for(int i = 12; i <= 15; i++){ digitalWrite(i,HIGH); delay(200); digitalWrite(i,LOW); }
In the first loop, LED on IO12 pin will light up and off after a 200ms delay. At the second time, LED on IO13 pin will
turn on and off also after a 200ms delay. Until the IO15 pin is extinguished and the for loop is popped out, and the
second for loop is the same except from IO15 pin to IO12 pin.
8.5.8 Project 7 Active Buzzer
1. Description
An active buzzer is a component used as an alarm, a reminder or an entertaining device, which boasts a reliable sound.
Whats more, it empowers to stimulate highly controllable sounds, making our projects more interesting.
62 Chapter 8. Arduino Tutorial

Table of Contents