# Lesson goal: Introduction to making sound

Previous: Drawing polylines in 3D | Home | Next: Compose music

Sounds we hear are made by when air is made to vibrate back and forth at a particular frequency. The speakers in your computer are made to do just this, having a moveable diaphram that pushes on the air when an electrical signal is applied to them. If you want to make sounds as a programmer, all you need is the ability to send signals to your speakers. Here we introduce the sound function, that allows you to do just that--send a signal to your speakers, so you can make them play a sound of any given frequency.
sound(freq,duration)
play()
Move the mouse over a dotted box for more information.

# Now you try. Try putting in any frequency and duration you want, which can be a number from 100 to 10,000 or so.

Type your code here:

See your results here:

Remember, you are coding now, so you don't have to program in sounds one at a time. You can use a for-loop to make all kinds of interesting sequences, like this

 for f=500,600,10 do sound(f,0.5) end play() 

or

 for f=100,5000,100 do sound(f,0.01) end play() 

Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

3. Then click the "Use on iPhone" button that you'll see.