Sei sulla pagina 1di 12

AMA COMPUTER COLLEGE

OLONGAPO CAMPUS
OLONGAPO CITY

ARDUINO TONE MELODY

SUBMITTED BY:
DIAZ, OSMUNDO
PERMIT NUMBER: PRELIM: 00127 MIDTERM: 00129
ALMAZAN, CRISTINA
PERMIT NUMBER: 00039 MIDTERM: 00040

SUBMITTED TO:
ENGR. ALLEN JOSEPH J. HORVIDALLA
INSTRUCTOR
MARCH 24, 2015
DATE

OBJECTIVES:
1. To learn more about an Arduino functions purpose , programs and
arguments.
2.To enhance experience on actual arduino combine with other actuators .
3.To create basic and useful project and program with arduino.

MATERIALS AND COSTING:


QTY.

PRICE

SUBTOTAL

LED

3.00

9.00

RESISTOR

1.00

4.00

SWITCH

20.00

20.00

SPEAKER

40.00

40.00

POTENTIOMETER

15.00

15.00

PCB

20.00

20.00
TOTAL: 108.00

DISCUSSION:
Arduino hardware and Software program like tone and pin selection interact with the
pcb board and into a speaker. Tone synchronize to a led every bit and by using
potentiometer you can adjust a tone volume minimum or maximum and connected with
a switch that could switch on and off.

GALLERY:

CONCLUSION AND RECOMMENDATION:

Using Arduinos hardware and software program we create a simple project, combine
with electronic parts like resistors, switch, led, speaker and potentiometer that could
give us an output into a tone or melody synchronise with the led. Arduino is an opensource electronics prototyping platform based on flexible, easy-to-use hardware and
software. It's intended for artists, designers, hobbyists, and anyone interested in creating
interactive objects or environments.

APPENDIX SOURCE CODE


#include "pitches.h"
#define NO_SOUND 0

const int piezoPin = 12; //piezo


const int rPin = 5; //red LED
const int gPin = 4; //green LED
const int bPin = 3; //blue LED
const int pPin = 2; //pushbutton

int ledState = 0;

int ledOn = false;

// notes
int melody[] = {
F6, G6, Ab6, Eb6, Eb6, Bb6,
Ab6, F6, F6, F6, F6, G6, Ab6,
F6, G6, Ab6, Eb6, Eb6, C7,
Bb6, Ab6, Bb6, C7, C7, Db7, C7, Bb6, Ab6,
Eb7, C7, Bb6, Ab6, Ab6, Eb7, C7, Ab6,
Ab6, Ab6, G6, Eb6, Eb6,
C6, Db6, Db6, C6, Db6, C6, Db6, Db6, C6, Ab5 };

unsigned int duration[] = { E, E, H, E, E, H,


Q, E, E, Q, E, Q, H,
E, E, H, E, E, Q,
H, E, E, Q, E, Q, Q, Q, H,
T, T, H, Q, Q, M, L, Q,
Q, Q, T, T, H,
E, Q, E, E, E, E, E, E, E, H };
// durations: 2 = half note, and 8/3,4,6,8,12. It appears that 8/2.9 is more accurate than
8/3.
float noteDurations[] = {
8,16,16,8,4,8,8,8,

8,16,16,8,4,8,8,8,
8,16,16,8,4,8,8,8,
8,16,16,8,4,8,8,8,
8,2,8,8,1,
8,4,8,4,8,8,
8,8,4,8,4,8,
4,8,4,8,3
};

// calculates the number of elements in the melody array.


int musicLength=sizeof(melody)/sizeof('NOTE_F5');

void setup() {
pinMode(pPin, INPUT);
pinMode(rPin, OUTPUT);
pinMode(gPin, OUTPUT);
pinMode(bPin, OUTPUT);
}

void loop() {

int pPinState=digitalRead(pPin);
if(pPinState==HIGH) {

ledState = 1;
}
if (pPinState==LOW and ledState ==1) {
ledState = 2;
ledOn = not ledOn;
}
if (ledOn && pPinState!=HIGH) {
for (int thisNote = 0; thisNote < musicLength; thisNote++) {
// blink the three LEDs in sequence
if (thisNote%3==0){
digitalWrite(rPin, HIGH);
digitalWrite(gPin, LOW);
digitalWrite(bPin, LOW);
}
else if (thisNote%3==1){
digitalWrite(rPin, LOW);
digitalWrite(gPin, HIGH);
digitalWrite(bPin, LOW);
}
else if (thisNote%3==2){
digitalWrite(rPin, LOW);
digitalWrite(gPin, LOW);
digitalWrite(bPin, HIGH);

}
// calculate the note duration. change tempo by changing 2000 to other values
int noteDuration = 2000/noteDurations[thisNote];
tone(piezoPin, melody[thisNote],noteDuration);

// to distinguish the notes, set a minimum time between them.


// the note's duration + 30% seems to work well
float pauseBetweenNotes = noteDuration * 1.30;

//split the delay into two parts and check to see


//whether the pushbutton is pressed to turn off
//the sound and light
delay(pauseBetweenNotes/2);
if(digitalRead(pPin)==HIGH) {
break;
}
delay(pauseBetweenNotes/2);
if(digitalRead(pPin)==HIGH) {
break;
}
}
}
else if (not ledOn) {
digitalWrite(rPin, LOW);

digitalWrite(gPin, LOW);
digitalWrite(bPin, LOW);
}
}

FONT: Times New Roman


PAPER: 8.5 by 11
SIZE: 12
SPACING: double space
PAGE NUMBER: Bottom Center not included the title Page must be within the text
area
DEADLINE OF SUBMISSION: March 24, 2015 (6 PM) Tuesday with the working
prototype.

Potrebbero piacerti anche