forked from microbuilder/LPC810_CodeBase
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample05_toneMelody.c
More file actions
84 lines (60 loc) · 2.01 KB
/
example05_toneMelody.c
File metadata and controls
84 lines (60 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "sketch_ino.h"
/*** LPC810 Arduino compatible library example ***/
/*
Melody
Plays a melody
circuit:
* piezo speaker on digital speaker pin
created 21 Jan 2010
modified 30 Aug 2011
by Tom Igoe
modified and addeptet by ChrisMicro 2014 for LPC810
LPC800 Pining ( Arduino pin numbering )
=======================================
________
| U |
reset -| |- digital 0 / analog in A0 / RX
TX / digital 4 -| LPC |- GND
digital 3 -| 810 |- +3.3V
digital 2 -| |- digital 1 / analog in A1
|_______|
Mini Kit Board ( http://www.lpcware.com/lpc800-mini-kit )
=========================================================
_________
| U |
reset switch -| |-
-| LPC |- GND
speaker pin -| 810 |- +3.3V
test led -| |-
|_______|
This example code is in the public domain.
http://arduino.cc/en/Tutorial/Tone
*/
#include "pitches.h"
int SpeakerPin=3;
// notes in the melody:
int melody[] = {
NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
4, 8, 8, 4,4,4,4,4 };
void setup() {
int thisNote;
// iterate over the notes of the melody:
for (thisNote = 0; thisNote < 8; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration= 1000/noteDurations[thisNote];
tone(SpeakerPin, melody[thisNote]/2,noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 13/10;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(SpeakerPin);
}
}
void loop() {
// no need to repeat the melody.
}