3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Play the French Can Can Using an Arduino and Buzzer

Step 7Understand the Starting Sketch

Understand the Starting Sketch
Here's a quick run down of the code that was just uploaded section by section.

----------------
// Buzzer example function for the CEM-1203 buzzer (Sparkfun's part #COM-07950).
// by Rob Faludi
// http://www.faludi.com
----------------

The above section is ignored by the compiler. Any line starting with '//' is ignored, used for making comments. Commenting the code is great for describing what's going on for your future reference, and for others looking at your code.

----------------
void setup() {
    pinMode(4, OUTPUT); // set a pin for buzzer output
}
----------------

Anything run in the built in setup() funtion is only run once when the Arduino is booted. pinMode(11, OUTPUT); sets pin 11 on the Arduino as an output pin. The guts of every function, setup() included, are held between the opening '{' and closing '}'.

----------------
void loop() {
    buzz(4, 2500, 500); // buzz the buzzer on pin 4 at 2500Hz for 500 milliseconds
    delay(1000); // wait a bit between buzzes
}
----------------

The built in loop() function is run over and over as long as the Arduino is powered. In this example, the custom buzz() function is called (see below), followed by Arduino's built in delay() function. The delay() function pauses the script for a specified number of miliseconds. In this case, 1000 miliseconds, or 1 second.

----------------
void buzz(int targetPin, long frequency, long length) {
    ...
}
----------------

The buzz() function is a custom function that Ron created, requiring three arguments: targetPin, frequency, and length. Each argumant is given a data type (int, long, and long). See Ron's code comments in the sketch (or image in this step) for details on how the buzz is generated. More information about data types and scripting is available here.
« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
2
Followers
1
Author:Ultrus(Christopher Stevens)
Web developer and designer who loves renovating and empowering over-sized web projects. Experience in developing and integrating ground breaking creative solutions online. Enjoys solving complex devel...
more »