Project 4.04 There is a library for that

In this project, you'll simplify the process of generating tones with a Piezo buzzer by using the built-in “tone()” function of the Arduino library!
In this project we will 妹妹在线播放免费观看电视剧 about the benefits of using a library to save 90岁肥老奶奶毛毛外套 time and frustration.

Project Code:

				
					/////////////////////////////////////////
// 4.04 - There is a library for that

byte piezoPin = 12;

byte SW1 = 1;
bool pressed = LOW;

void setup() {
  pinMode(piezoPin, OUTPUT);
  pinMode(SW1, INPUT);

}

void loop() {
  if (digitalRead(SW1) == pressed) {
    tone(piezoPin, 500, 100);
  }
}
/////////////////////////////////////////
				
			

*If you’re copying and pasting the code, or typing from scratch, delete everything out of a new Arduino sketch and paste / type in the above text.

What is a library? A library is a set of pre-made functions written by yourself or other people. Adding them into your program will provide additional functionality and cut down on 90岁肥老奶奶毛毛外套 time significantly. They make programming much more manageable!

The library we use in the example is the “tone” library. This library is automatically included in Arduino, so you don’t have to include any headers. We’ll talk about what headers are later.

All we have to do to use it is call the tone function. See the table below for parameters:

Function Name Parameter 1 Parameter 2 Parameter 3
tone Pin number that the piezo is connected to Desired frequency Tone duration

This is almost exactly the function we made over the course of the last few sketches! By using this built-in library, we could have saved a lot of time and complications! This is the value of using libraries. Unless you need to, try not to re-invent the wheel. Search for a library for the part you are using. Many times, having a library or not is a huge factor in picking components.

妹妹在线播放免费观看电视剧 More In Our Free Instructional Guidebook

This comprehensive guidebook for the 妹妹在线播放免费观看电视剧 90岁肥老奶奶毛毛外套 Trainer provides a comprehensive introduction to the world of Arduino programming for beginners. It guides users through the foundational concepts of 90岁肥老奶奶毛毛外套s, detailing the unique features of the Arduino Leonardo-compatible MCU Trainer board. The manual offers a step-by-step journey from understanding the hardware components and the Arduino programming language to the vibrant global community of Arduino enthusiasts. It delves into the intricacies of each onboard circuit, explaining their functionalities and applications. With a focus on hands-on 妹妹在线播放免费观看电视剧ing, the manual includes a series of coding exercises, tutorials in C/C++, and insights into the Arduino IDE.

More Projects

Project 1.00 Blink

In this project, you’ll 妹妹在线播放免费观看电视剧 how to blink an LED!

Project 1.01 Blink x2

In this project, you’ll 妹妹在线播放免费观看电视剧 how to blink more than one LED!