Tutorial.Tone History

Hide minor edits - Show changes to output

April 08, 2013, at 05:15 PM by Roberto Guido - corrected link to image, thanks nid69ita for feedback
Changed lines 28-30 from:
%height=300px%[[Attach:speaker_bb.png | Attach:speaker_schem.png]]

to:
%height=300px%[[Attach:speaker_schem.png | Attach:speaker_schem.png]]

May 02, 2012, at 03:40 AM by Scott Fitzgerald -
Changed lines 39-40 from:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/2.Digital/toneMelody/toneMelody.ino lang=arduino tabwidth=4:)
to:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/02.Digital/toneMelody/toneMelody.ino lang=arduino tabwidth=4:)
May 02, 2012, at 03:39 AM by Scott Fitzgerald -
May 02, 2012, at 03:36 AM by Scott Fitzgerald -
Changed lines 50-51 from:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/2.Digital/toneMelody/pitches.h lang=arduino tabwidth=4:)
to:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/02.Digital/toneMelody/pitches.h lang=arduino tabwidth=4:)
November 16, 2011, at 04:07 AM by Scott Fitzgerald -
Changed lines 39-40 from:
(:source http://arduino.cc/en/pub/code/new-extension/build/shared/examples/2.Digital/toneMelody/toneMelody.ino lang=arduino tabwidth=4:)
to:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/2.Digital/toneMelody/toneMelody.ino lang=arduino tabwidth=4:)
Changed lines 50-51 from:
(:source http://arduino.cc/en/pub/code/new-extension/build/shared/examples/2.Digital/toneMelody/pitches.h lang=arduino tabwidth=4:)
to:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/2.Digital/toneMelody/pitches.h lang=arduino tabwidth=4:)
September 30, 2011, at 03:04 AM by Scott Fitzgerald -
Changed lines 39-40 from:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/2.Digital/toneMelody/toneMelody.pde lang=arduino tabwidth=4:)
to:
(:source http://arduino.cc/en/pub/code/new-extension/build/shared/examples/2.Digital/toneMelody/toneMelody.ino lang=arduino tabwidth=4:)
Changed lines 50-51 from:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/2.Digital/toneMelody/pitches.h lang=arduino tabwidth=4:)
to:
(:source http://arduino.cc/en/pub/code/new-extension/build/shared/examples/2.Digital/toneMelody/pitches.h lang=arduino tabwidth=4:)
September 23, 2010, at 10:30 PM by Christian Cerrito -
Changed lines 3-4 from:
!!!Play Melody using the tone() function
to:
!!!Play a Melody using the tone() function
September 23, 2010, at 10:30 PM by Christian Cerrito -
Changed lines 3-4 from:
!!Play Melody using the tone() function
to:
!!!Play Melody using the tone() function
September 16, 2010, at 07:11 PM by Tom Igoe -
Changed lines 39-40 from:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/2.Digital/toneMelody/toneMelody.pde lang=c tabwidth=4:)
to:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/2.Digital/toneMelody/toneMelody.pde lang=arduino tabwidth=4:)
Changed lines 50-51 from:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/2.Digital/toneMelody/pitches.h lang=arduino tabwidth=4:)
to:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/2.Digital/toneMelody/pitches.h lang=arduino tabwidth=4:)
September 16, 2010, at 01:58 PM by Tom Igoe -
Changed lines 38-41 from:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/1.Basics/Blink/Blink.pde lang=C linenum tabwidth=4 :)

(:source lang=c http://arduino.cc/en/pub/code/master/build/shared/examples/2.Digital/toneMelody/toneMelody.pde tabwidth=4:)
to:

(:source http://arduino.cc/en/pub/code/master/build/shared/examples/2.Digital/toneMelody/toneMelody.pde lang=c tabwidth=4:)
Changed lines 50-51 from:
(:source lang=c http://arduino.cc/en/pub/code/master/build/shared/examples/2.Digital/toneMelody/pitches.h tabwidth=4:)
to:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/2.Digital/toneMelody/pitches.h lang=c tabwidth=4:)
September 16, 2010, at 01:57 PM by Tom Igoe -
Added lines 38-39:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/1.Basics/Blink/Blink.pde lang=C linenum tabwidth=4 :)
September 16, 2010, at 01:56 PM by Tom Igoe -
Changed lines 36-39 from:
(:div class=code :)

(:source lang=c http://arduino.cc/en/pub/code/master/build/shared/examples/2.Digital/toneMelody/toneMelody.pde tabwidth=4:)
to:
(:div class=code:)

(:source lang=c http://arduino.cc/en/pub/code/master/build/shared/examples/2.Digital/toneMelody/toneMelody.pde tabwidth=4:)
Changed line 48 from:
(:div class=code :)
to:
(:div class=code:)
September 16, 2010, at 01:56 PM by Tom Igoe -
Added lines 36-37:
(:div class=code :)
Added lines 40-41:
(:divend:)
September 16, 2010, at 01:54 PM by Tom Igoe -
Changed lines 35-36 from:
(:div class=code :)
to:
Changed lines 37-39 from:
(:divend:)

to:
September 16, 2010, at 01:54 PM by Tom Igoe -
Changed lines 50-51 from:
(:div:)
to:
(:divend:)
September 16, 2010, at 01:54 PM by Tom Igoe -
Changed lines 34-39 from:
To make this file, click on the "new Tab" button in the upper right hand corner of the window. It looks like this:

Attach:newTab.png

The paste in the following code:
to:
The main sketch is as follows:
Changed lines 36-44 from:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/2.Digital/toneMelody/pitches.h border=0:)

(:div:)

The main sketch is as follows:
(:div class=code :)


(:source http://arduino.cc/en/pub/code/master/build/shared/examples/2.Digital/toneMelody/toneMelody.pde tabwidth=4:)
to:

(:source lang=c http://arduino.cc/en/pub/code/master/build/shared/examples/2.Digital/toneMelody/toneMelody.pde tabwidth=4:)
Added lines 40-51:

To make the pitches.h file, click on the "new Tab" button in the upper right hand corner of the window. It looks like this:

Attach:newTab.png

The paste in the following code:

(:div class=code :)
(:source lang=c http://arduino.cc/en/pub/code/master/build/shared/examples/2.Digital/toneMelody/pitches.h tabwidth=4:)

(:div:)
September 16, 2010, at 01:51 PM by Tom Igoe -
Changed lines 47-49 from:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/2.Digital/toneMelody/toneMelody.pde lang=arduino tabwidth=4:)
to:


(:source http://arduino.cc/en/pub/code/master/build/shared/examples/2.Digital/toneMelody/toneMelody.pde tabwidth=4:)
August 25, 2010, at 04:54 AM by Christian Cerrito -
Changed lines 9-10 from:
* Arduino Board
* Small Speaker
to:
* Arduino board
* 8 ohm small speaker
August 25, 2010, at 04:54 AM by Christian Cerrito -
Changed lines 55-56 from:
* [[PitchFollower]] - play a pitch on a piezo speaker depending on an analog input
* [[SimpleKeyboard]] - a three-key musical keyboard using force sensors and a piezo speaker.
to:
* [[Tone2 | PitchFollower]] - play a pitch on a piezo speaker depending on an analog input
* [[Tone3 | SimpleKeyboard]] - a three-key musical keyboard using force sensors and a piezo speaker.
August 25, 2010, at 04:52 AM by Christian Cerrito -
Changed lines 55-56 from:
* [[Pitch Follower]] - play a pitch on a piezo speaker depending on an analog input
* [[Simple Keyboard]] - a three-key musical keyboard using force sensors and a piezo speaker.
to:
* [[PitchFollower]] - play a pitch on a piezo speaker depending on an analog input
* [[SimpleKeyboard]] - a three-key musical keyboard using force sensors and a piezo speaker.
August 25, 2010, at 04:52 AM by Christian Cerrito -
Changed lines 51-52 from:
* [[(Tutorial/)Array]]()
* [[(Tutorial/)for]]()
to:
* [[(Reference/)Array]]()
* [[(Reference/)for]]()
August 25, 2010, at 04:49 AM by Christian Cerrito -
Added line 7:
Added line 14:
Changed lines 52-54 from:
* [[(Tutorial/)Forloop]]()
* [[(Reference/)tone]()
to:
* [[(Tutorial/)for]]()
* [[(Reference/)tone]]()
August 24, 2010, at 11:50 PM by Christian Cerrito -
Changed lines 46-54 from:
(:divend:)
to:
(:divend:)

!!!See Also:
* [[(Tutorial/)Array]]()
* [[(Tutorial/)Forloop]]()
* [[(Reference/)tone]()

* [[Pitch Follower]] - play a pitch on a piezo speaker depending on an analog input
* [[Simple Keyboard]] - a three-key musical keyboard using force sensors and a piezo speaker.
August 24, 2010, at 11:34 PM by Christian Cerrito -
Added lines 7-12:
!!!Hardware Required
* Arduino Board
* Small Speaker
* 100 ohm resistor
* hook-up wire
Changed lines 19-21 from:
to:
Connect one terminal of your speaker to digital pin 8 through a 100 ohm resistor. Connect the other terminal to ground.

August 24, 2010, at 08:09 AM by Christian Cerrito -
Changed lines 31-32 from:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/Digital/toneMelody/pitches.h border=0:)
to:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/2.Digital/toneMelody/pitches.h border=0:)
Changed line 37 from:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/Digital/toneMelody/toneMelody.pde lang=arduino tabwidth=4:)
to:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/2.Digital/toneMelody/toneMelody.pde lang=arduino tabwidth=4:)
January 22, 2010, at 12:04 AM by Tom Igoe -
Changed lines 31-120 from:
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978
to:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/Digital/toneMelody/pitches.h border=0:)
Changed lines 37-67 from:

#include %color=#006699%"pitches.h"

%color=#7e7e7e%// notes in the melody:
%color=#cc6600%int%% melody[] = {
  NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};

%color=#7e7e7e%// note durations: 4 = quarter note, 8 = eighth note, etc.:
%color=#cc6600%int%% noteDurations[] = {
  4, 8, 8, 4,4,4,4,4 };

%color=#cc6600%void%% %color=#cc6600%'''setup'''%%() {
  %color=#7e7e7e%// iterate over the notes of the melody:
  %color=#cc6600%for%% (%color=#cc6600%int%% thisNote = 0; thisNote < 8; thisNote++) {

    %color=#7e7e7e%// to calculate the note duration, take one second
    %color=#7e7e7e%// divided by the note type.
    %color=#7e7e7e%//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    %color=#cc6600%int%% noteDuration = 1000/noteDurations[thisNote];
    %color=#cc6600%tone%%(8, melody[thisNote],noteDuration);

    %color=#7e7e7e%// to distinguish the notes, set a minimum time between them.
    %color=#7e7e7e%// the note's duration + 30% seems to work well:
    %color=#cc6600%int%% pauseBetweenNotes = noteDuration * 1.30;
    %color=#cc6600%delay%%(pauseBetweenNotes);
  }
}

%color=#cc6600%void%% %color=#cc6600%'''loop'''%%() {
  %color=#7e7e7e%// no need to repeat the melody.
}
to:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/Digital/toneMelody/toneMelody.pde lang=arduino tabwidth=4:)
January 21, 2010, at 08:00 PM by Tom Igoe -
Changed lines 3-4 from:
!!Debounce
to:
!!Play Melody using the tone() function
January 21, 2010, at 05:49 PM by Tom Igoe -
Changed lines 31-120 from:
&hash;define NOTE_B0 31
&hash;define NOTE_C1 33
&hash;define NOTE_CS1 35
&hash;define NOTE_D1 37
&hash;define NOTE_DS1 39
&hash;define NOTE_E1 41
&hash;define NOTE_F1 44
&hash;define NOTE_FS1 46
&hash;define NOTE_G1 49
&hash;define NOTE_GS1 52
&hash;define NOTE_A1 55
&hash;define NOTE_AS1 58
&hash;define NOTE_B1 62
&hash;define NOTE_C2 65
&hash;define NOTE_CS2 69
&hash;define NOTE_D2 73
&hash;define NOTE_DS2 78
&hash;define NOTE_E2 82
&hash;define NOTE_F2 87
&hash;define NOTE_FS2 93
&hash;define NOTE_G2 98
&hash;define NOTE_GS2 104
&hash;define NOTE_A2 110
&hash;define NOTE_AS2 117
&hash;define NOTE_B2 123
&hash;define NOTE_C3 131
&hash;define NOTE_CS3 139
&hash;define NOTE_D3 147
&hash;define NOTE_DS3 156
&hash;define NOTE_E3 165
&hash;define NOTE_F3 175
&hash;define NOTE_FS3 185
&hash;define NOTE_G3 196
&hash;define NOTE_GS3 208
&hash;define NOTE_A3 220
&hash;define NOTE_AS3 233
&hash;define NOTE_B3 247
&hash;define NOTE_C4 262
&hash;define NOTE_CS4 277
&hash;define NOTE_D4 294
&hash;define NOTE_DS4 311
&hash;define NOTE_E4 330
&hash;define NOTE_F4 349
&hash;define NOTE_FS4 370
&hash;define NOTE_G4 392
&hash;define NOTE_GS4 415
&hash;define NOTE_A4 440
&hash;define NOTE_AS4 466
&hash;define NOTE_B4 494
&hash;define NOTE_C5 523
&hash;define NOTE_CS5 554
&hash;define NOTE_D5 587
&hash;define NOTE_DS5 622
&hash;define NOTE_E5 659
&hash;define NOTE_F5 698
&hash;define NOTE_FS5 740
&hash;define NOTE_G5 784
&hash;define NOTE_GS5 831
&hash;define NOTE_A5 880
&hash;define NOTE_AS5 932
&hash;define NOTE_B5 988
&hash;define NOTE_C6 1047
&hash;define NOTE_CS6 1109
&hash;define NOTE_D6 1175
&hash;define NOTE_DS6 1245
&hash;define NOTE_E6 1319
&hash;define NOTE_F6 1397
&hash;define NOTE_FS6 1480
&hash;define NOTE_G6 1568
&hash;define NOTE_GS6 1661
&hash;define NOTE_A6 1760
&hash;define NOTE_AS6 1865
&hash;define NOTE_B6 1976
&hash;define NOTE_C7 2093
&hash;define NOTE_CS7 2217
&hash;define NOTE_D7 2349
&hash;define NOTE_DS7 2489
&hash;define NOTE_E7 2637
&hash;define NOTE_F7 2794
&hash;define NOTE_FS7 2960
&hash;define NOTE_G7 3136
&hash;define NOTE_GS7 3322
&hash;define NOTE_A7 3520
&hash;define NOTE_AS7 3729
&hash;define NOTE_B7 3951
&hash;define NOTE_C8 4186
&hash;define NOTE_CS8 4435
&hash;define NOTE_D8 4699
&hash;define NOTE_DS8 4978
to:
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978
January 21, 2010, at 05:48 PM by Tom Igoe -
Changed lines 31-32 from:
&hash;define NOTE_B0 31
&hash;define NOTE_C1 33
to:
&hash;define NOTE_B0 31
&hash;define NOTE_C1 33
January 21, 2010, at 05:48 PM by Tom Igoe -
Changed lines 31-121 from:
<pre>
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978
</pre>
to:
&hash;define NOTE_B0 31
&hash;define NOTE_C1 33
&hash;define NOTE_CS1 35
&hash;define NOTE_D1 37
&hash;define NOTE_DS1 39
&hash;define NOTE_E1 41
&hash;define NOTE_F1 44
&hash;define NOTE_FS1 46
&hash;define NOTE_G1 49
&hash;define NOTE_GS1 52
&hash;define NOTE_A1 55
&hash;define NOTE_AS1 58
&hash;define NOTE_B1 62
&hash;define NOTE_C2 65
&hash;define NOTE_CS2 69
&hash;define NOTE_D2 73
&hash;define NOTE_DS2 78
&hash;define NOTE_E2 82
&hash;define NOTE_F2 87
&hash;define NOTE_FS2 93
&hash;define NOTE_G2 98
&hash;define NOTE_GS2 104
&hash;define NOTE_A2 110
&hash;define NOTE_AS2 117
&hash;define NOTE_B2 123
&hash;define NOTE_C3 131
&hash;define NOTE_CS3 139
&hash;define NOTE_D3 147
&hash;define NOTE_DS3 156
&hash;define NOTE_E3 165
&hash;define NOTE_F3 175
&hash;define NOTE_FS3 185
&hash;define NOTE_G3 196
&hash;define NOTE_GS3 208
&hash;define NOTE_A3 220
&hash;define NOTE_AS3 233
&hash;define NOTE_B3 247
&hash;define NOTE_C4 262
&hash;define NOTE_CS4 277
&hash;define NOTE_D4 294
&hash;define NOTE_DS4 311
&hash;define NOTE_E4 330
&hash;define NOTE_F4 349
&hash;define NOTE_FS4 370
&hash;define NOTE_G4 392
&hash;define NOTE_GS4 415
&hash;define NOTE_A4 440
&hash;define NOTE_AS4 466
&hash;define NOTE_B4 494
&hash;define NOTE_C5 523
&hash;define NOTE_CS5 554
&hash;define NOTE_D5 587
&hash;define NOTE_DS5 622
&hash;define NOTE_E5 659
&hash;define NOTE_F5 698
&hash;define NOTE_FS5 740
&hash;define NOTE_G5 784
&hash;define NOTE_GS5 831
&hash;define NOTE_A5 880
&hash;define NOTE_AS5 932
&hash;define NOTE_B5 988
&hash;define NOTE_C6 1047
&hash;define NOTE_CS6 1109
&hash;define NOTE_D6 1175
&hash;define NOTE_DS6 1245
&hash;define NOTE_E6 1319
&hash;define NOTE_F6 1397
&hash;define NOTE_FS6 1480
&hash;define NOTE_G6 1568
&hash;define NOTE_GS6 1661
&hash;define NOTE_A6 1760
&hash;define NOTE_AS6 1865
&hash;define NOTE_B6 1976
&hash;define NOTE_C7 2093
&hash;define NOTE_CS7 2217
&hash;define NOTE_D7 2349
&hash;define NOTE_DS7 2489
&hash;define NOTE_E7 2637
&hash;define NOTE_F7 2794
&hash;define NOTE_FS7 2960
&hash;define NOTE_G7 3136
&hash;define NOTE_GS7 3322
&hash;define NOTE_A7 3520
&hash;define NOTE_AS7 3729
&hash;define NOTE_B7 3951
&hash;define NOTE_C8 4186
&hash;define NOTE_CS8 4435
&hash;define NOTE_D8 4699
&hash;define NOTE_DS8 4978
January 21, 2010, at 05:47 PM by Tom Igoe -
Changed line 31 from:
to:
<pre>
Added line 121:
</pre>
January 21, 2010, at 05:44 PM by Tom Igoe -
Changed lines 9-10 from:
%height=400px%[[Attach:speaker_bb.png | Attach:speaker_bb.png]]
to:
%height=300px%[[Attach:speaker_bb.png | Attach:speaker_bb.png]]
Changed lines 18-20 from:
%height=400px%[[Attach:speaker_bb.png | Attach:speaker_schem.png]]

to:
%height=300px%[[Attach:speaker_bb.png | Attach:speaker_schem.png]]

January 21, 2010, at 05:42 PM by Tom Igoe -
Changed lines 9-10 from:
%width=400px%[[Attach:speaker_bb.png | Attach:speaker_bb.png]]
to:
%height=400px%[[Attach:speaker_bb.png | Attach:speaker_bb.png]]
Changed lines 18-20 from:
%width=400px%[[Attach:speaker_bb.png | Attach:speaker_schem.png]]

to:
%height=400px%[[Attach:speaker_bb.png | Attach:speaker_schem.png]]

January 21, 2010, at 05:40 PM by Tom Igoe -
Added lines 1-156:
''Examples > Digital I/O''

!!Debounce

This example shows how to use the tone() command to generate notes. It plays a little melody you may have heard before.

!!!Circuit

%width=400px%[[Attach:speaker_bb.png | Attach:speaker_bb.png]]

[-image developed using [[http://www.fritzing.org |Fritzing]]. For more circuit examples, see the [[http://fritzing.org/projects/|Fritzing project page]] -]


!!!Schematic

[-click the image to enlarge-]

%width=400px%[[Attach:speaker_bb.png | Attach:speaker_schem.png]]


!!! Code
The code below uses an extra file, pitches.h. This file contains all the pitch values for typical notes. For example, NOTE_C4 is middle C. NOTE_FS4 is F sharp, and so forth. This note table was originally written by Brett Hagman, on whose work the tone() command was based. You may find it useful for whenever you want to make musical notes.

To make this file, click on the "new Tab" button in the upper right hand corner of the window. It looks like this:

Attach:newTab.png

The paste in the following code:

(:div class=code :)

#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978
(:div:)

The main sketch is as follows:
(:div class=code :)

#include %color=#006699%"pitches.h"

%color=#7e7e7e%// notes in the melody:
%color=#cc6600%int%% melody[] = {
  NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};

%color=#7e7e7e%// note durations: 4 = quarter note, 8 = eighth note, etc.:
%color=#cc6600%int%% noteDurations[] = {
  4, 8, 8, 4,4,4,4,4 };

%color=#cc6600%void%% %color=#cc6600%'''setup'''%%() {
  %color=#7e7e7e%// iterate over the notes of the melody:
  %color=#cc6600%for%% (%color=#cc6600%int%% thisNote = 0; thisNote < 8; thisNote++) {

    %color=#7e7e7e%// to calculate the note duration, take one second
    %color=#7e7e7e%// divided by the note type.
    %color=#7e7e7e%//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    %color=#cc6600%int%% noteDuration = 1000/noteDurations[thisNote];
    %color=#cc6600%tone%%(8, melody[thisNote],noteDuration);

    %color=#7e7e7e%// to distinguish the notes, set a minimum time between them.
    %color=#7e7e7e%// the note's duration + 30% seems to work well:
    %color=#cc6600%int%% pauseBetweenNotes = noteDuration * 1.30;
    %color=#cc6600%delay%%(pauseBetweenNotes);
  }
}

%color=#cc6600%void%% %color=#cc6600%'''loop'''%%() {
  %color=#7e7e7e%// no need to repeat the melody.
}
(:divend:)

Share