Вы находитесь на странице: 1из 15

INGENIRÍA ELECTRÓNICA

COMUNICACIONES INALMBRICAS 2019 – 1

Aplicación creada online en http://ai2.appinventor.mit.edu con desarrollo


basado en bloques de programación básica para dispositivos Android. Se
realizo la comunicación por medio del modulo bluetooth HC-05. Buzer
conectado al pin 9 configurado como PWM. Para la comunicación con el
modulo HC-05 se realiza por medio de puerto serial creado por software
usando la librería SoftwareSerial.h.
En el modo de compositor se realiza usando la librería EEPROM.h la cual
permite guardar en la memoria del Arduino y leerla.

FIGURA 1: diseño de los objetos de la aplicación.

FIGURA 2: programación con bloques de cada objeto.

JAVIER ZABALA VERDUGO


INGENIRÍA ELECTRÓNICA
COMUNICACIONES INALMBRICAS 2019 – 1

FIGURA 3: aplicación modo teclado

FIGURA 4: diagrama de conexiones de Arduino con buzer y bluetooth.

JAVIER ZABALA VERDUGO


INGENIRÍA ELECTRÓNICA
COMUNICACIONES INALMBRICAS 2019 – 1

/* XILOFONO ANDUINO Y ANDROID


APLICACION ANDROID PARA COMUNICACION BLUETOOTH
POR: javier47.zabala@gmail.com
modos:
modo teclado: tocan teclado da notas
modo toca disco: boton tocan musica
modo compositor: oprimen teclas sonido oprimen otro boton play
(reproducir)
*/

#include <SoftwareSerial.h>
#include <EEPROM.h>
int addr = 0;
char val = 0;
int address = 0;
char value;
/*
CONEXIONES:
ARDUINO BLUETOOTH
5V VCC
GND GND
PIN 4 TX
PIN 5 RX
*/

SoftwareSerial Myserial(4, 5); //Crea conexion al bluetooth - PIN 4 a


TX y PIN 5 a RX

char valor;

////////////////////////////////
/* DECLARAION DE NOTAS */
int spk = 9; // altavoz a GND y pin 13
int c[5] = {131, 262, 523, 1046, 2093}; // Do
int cs[5] = {139, 277, 554, 1108, 2217}; // Do#
int d[5] = {147, 294, 587, 1175, 2349}; // Re
int ds[5] = {156, 311, 622, 1244, 2489}; // Re#
int e[5] = {165, 330, 659, 1319, 2637}; // Mi
int f[5] = {175, 349, 698, 1397, 2794}; // Fa
int fs[5] = {185, 370, 740, 1480, 2960}; // Fa#
int g[5] = {196, 392, 784, 1568, 3136}; // Sol
int gs[5] = {208, 415, 831, 1661, 3322}; // Sol#
int a[5] = {220, 440, 880, 1760, 3520}; // La
int as[5] = {233, 466, 932, 1866, 3729}; // La#
int b[5] = {247, 494, 988, 1976, 3951}; // Si

/* DATOS RECIBIDOS POR MODULO BLUETOOTH

JAVIER ZABALA VERDUGO


INGENIRÍA ELECTRÓNICA
COMUNICACIONES INALMBRICAS 2019 – 1
NOTA CARACTER
DO D
RE R
MI M
FA F
SOL S
LA L
SI C
DO# d
RE# r
FA# f
SOL# s
LA# l

TONO CARACTER
HARRY POTTER 1
ENTRE DOS AGUAS 2
STAR WARS 3
MARCHA DEL IMPERIO 4
*/

///////////////////////////////
void setup()
{
Serial.begin(9600);
Myserial.begin(9600); // inicialmente la comunicacion serial a 9600
Baudios
pinMode(9, OUTPUT); // declara el pin 9 como salida
pinMode(13, OUTPUT); // declara el pin 13 como salida
pinMode(2, INPUT_PULLUP);

digitalWrite(13, LOW);
}
void loop()
{
if (Myserial.available()) { //si el puerto serial eesta disponoble
//valor = Myserial.read(); // asigna el dato recibido por el puerto
serial por software a la variable valor
val = Myserial.read();
}

if (val == 'D') {
tone(9, c[1], 400);
EEPROM.write(addr, val);
addr = addr + 1;
if (addr == EEPROM.length()) {
addr = 0;
}
}
if (val == 'R') {
tone(9, d[1], 400);
EEPROM.write(addr, val);
addr = addr + 1;
if (addr == EEPROM.length()) {
addr = 0;
}
}

JAVIER ZABALA VERDUGO


INGENIRÍA ELECTRÓNICA
COMUNICACIONES INALMBRICAS 2019 – 1
if (val == 'M') {
tone(9, e[1], 400);
EEPROM.write(addr, val);
addr = addr + 1;
if (addr == EEPROM.length()) {
addr = 0;
}
}
if (val == 'F') {
tone(9, f[1], 400);
EEPROM.write(addr, val);
addr = addr + 1;
if (addr == EEPROM.length()) {
addr = 0;
}
}
if (val == 'S') {
tone(9, g[1], 400);
EEPROM.write(addr, val);
addr = addr + 1;
if (addr == EEPROM.length()) {
addr = 0;
}
}
if (val == 'L') {
tone(9, a[1], 400);
EEPROM.write(addr, val);
addr = addr + 1;
if (addr == EEPROM.length()) {
addr = 0;
}
}
if (val == 'C') {
tone(9, b[1], 400);
EEPROM.write(addr, val);
addr = addr + 1;
if (addr == EEPROM.length()) {
addr = 0;
}
}
if (val == 'd') {
tone(9, cs[1], 400);
EEPROM.write(addr, val);
addr = addr + 1;
if (addr == EEPROM.length()) {
addr = 0;
}
}
if (val == 'r') {
tone(9, ds[1], 400);
EEPROM.write(addr, val);
addr = addr + 1;
if (addr == EEPROM.length()) {
addr = 0;
}
}
if (val == 'f') {

JAVIER ZABALA VERDUGO


INGENIRÍA ELECTRÓNICA
COMUNICACIONES INALMBRICAS 2019 – 1
tone(9, fs[1], 400);
EEPROM.write(addr, val);
addr = addr + 1;
if (addr == EEPROM.length()) {
addr = 0;
}
}
if (val == 's') {
tone(9, gs[1], 400);
EEPROM.write(addr, val);
addr = addr + 1;
if (addr == EEPROM.length()) {
addr = 0;
}
}
if (val == 'l') {
tone(9, as[1], 400);
EEPROM.write(addr, val);
addr = addr + 1;
if (addr == EEPROM.length()) {
addr = 0;
}
}

///////////////////lectura
if (val == 'Q') {
address = 0;
addr = 0;
}
if (val == 'P') {

// read a byte from the current address of the EEPROM


value = EEPROM.read(address);
if (value == 'D') {
tone(9, c[1], 400);
delay(100);
address = address + 1;
if (address == EEPROM.length()) {
address = 0;
}
}
if (value == 'R') {
tone(9, d[1], 400);
delay(100);
address = address + 1;
if (address == EEPROM.length()) {
address = 0;
}
}
if (value == 'M') {
tone(9, e[1], 400);
delay(100);
address = address + 1;
if (address == EEPROM.length()) {
address = 0;
}

JAVIER ZABALA VERDUGO


INGENIRÍA ELECTRÓNICA
COMUNICACIONES INALMBRICAS 2019 – 1
}
if (value == 'F') {
address = address + 1;
tone(9, f[1], 400);
delay(100);
if (address == EEPROM.length()) {
address = 0;
}
}
if (value == 'S') {
address = address + 1;
tone(9, g[1], 100);
delay(100);
if (address == EEPROM.length()) {
address = 0;
}
}
if (value == 'L') {
address = address + 1;
tone(9, a[1], 400);
delay(100);
if (address == EEPROM.length()) {
address = 0;
}
}
if (value == 'C') {
address = address + 1;
tone(9, b[1], 400);
delay(100);
if (address == EEPROM.length()) {
address = 0;
}
}
if (val == 'd') {
address = address + 1;
tone(9, cs[1], 400);
delay(100);
if (address == EEPROM.length()) {
address = 0;
}
}
if (value == 'r') {
address = address + 1;
tone(9, ds[1], 400);
delay(100);
if (address == EEPROM.length()) {
address = 0;
}
}
if (value == 'f') {
address = address + 1;
tone(9, fs[1], 400);
delay(100);
if (address == EEPROM.length()) {
address = 0;
}
}

JAVIER ZABALA VERDUGO


INGENIRÍA ELECTRÓNICA
COMUNICACIONES INALMBRICAS 2019 – 1
if (value == 's') {
address = address + 1;
tone(9, gs[1], 400);
delay(100);
if (address == EEPROM.length()) {
address = 0;
}
}
if (value == 'l') {
address = address + 1;
tone(9, as[1], 400);
delay(100);
if (address == EEPROM.length()) {
address = 0;
}
}
}

if (val == '1') {
/* HARRY POTTER */
tone(9, b[2], 500);
tone(9, e[3], 1000);
tone(9, g[3], 250);
tone(9, fs[3], 250);
tone(9, e[3], 1000);
tone(9, b[3], 500);
tone(9, a[3], 1250);
tone(9, fs[3], 1000);
tone(9, b[2], 500);
tone(9, e[3], 1000);
tone(9, g[3], 250);
tone(9, fs[3], 250);
tone(9, d[3], 1000);
tone(9, e[3], 500 );
tone(9, b[2], 1000 );
noTone(9); delay(1000);
tone(9, b[2], 500);
tone(9, e[3], 1000);
tone(9, g[3], 250);
tone(9, fs[3], 250);
tone(9, e[3], 1000);
tone(9, b[3], 500);
tone(9, d[4], 1000);
tone(9, cs[4], 500);
tone(9, c[4], 1000);
tone(9, a[3], 500);
tone(9, c[4], 1000);
tone(9, b[3], 250);
tone(9, as[3], 250);
tone(9, b[2], 1000);
tone(9, g[3], 500);
tone(9, e[3], 1000);
noTone(spk);

}
if (val == '2') {

JAVIER ZABALA VERDUGO


INGENIRÍA ELECTRÓNICA
COMUNICACIONES INALMBRICAS 2019 – 1
/* entre dos aguas */
tone(9, a[1], 400); noTone(spk); delay(400);
tone(9, e[1], 400); noTone(spk); delay(400);
tone(9, a[1], 400); noTone(spk); delay(200);
tone(9, e[1], 200); noTone(spk); delay(200);
tone(9, a[1], 200); noTone(spk); delay(200);
tone(9, as[1], 100); noTone(spk); delay(100);
tone(9, b[1], 400); noTone(spk); delay(400);
tone(9, fs[1], 400); noTone(spk); delay(400);
tone(9, b[1], 400); noTone(spk); delay(200);
tone(9, fs[1], 200); noTone(spk); delay(200);
tone(9, b[1], 200); noTone(spk); delay(200);
tone(9, as[1], 100); noTone(spk); delay(100);
tone(9, a[1], 400); noTone(spk); delay(400);
tone(9, e[1], 400); noTone(spk); delay(400);
tone(9, a[1], 400); noTone(spk); delay(400);
}
if (val == '3') {
/* STAR WARS */
tone(9, d[1], 150); noTone(spk); delay(50);
tone(9, d[1], 150); noTone(spk); delay(50);
tone(9, d[1], 150); noTone(spk); delay(50);
tone(9, g[1], 900); noTone(spk); delay(150);
tone(9, d[2], 900); noTone(spk); delay(50);
tone(9, c[2], 150); noTone(spk); delay(50);
tone(9, b[1], 150); noTone(spk); delay(50);
tone(9, a[1], 150); noTone(spk); delay(50);
tone(9, g[2], 900); noTone(spk); delay(150);
tone(9, d[2], 900); noTone(spk); delay(100);
tone(9, c[2], 150); noTone(spk); delay(50);
tone(9, b[1], 150); noTone(spk); delay(50);
tone(9, a[1], 150); noTone(spk); delay(50);
tone(9, g[2], 900); noTone(spk); delay(150);
tone(9, d[2], 900); noTone(spk); delay(100);
tone(9, c[2], 150); noTone(spk); delay(50);
tone(9, b[1], 150); noTone(spk); delay(50);
tone(9, c[2], 150); noTone(spk); delay(50);
tone(9, a[1], 1200); noTone(spk); delay(2000);
}
if (val == '4') {
/**** marcha del imperio ****/
tone(9, g[2], 500); noTone(spk); delay(100);
tone(9, g[2], 500); noTone(spk); delay(100);
tone(9, g[2], 500); noTone(spk); delay(100);
tone(9, ds[2], 500); noTone(spk); delay(1);
tone(9, as[2], 125); noTone(spk); delay(25);
tone(9, g[2], 500); noTone(spk); delay(100);
tone(9, ds[2], 500); noTone(spk); delay(1);
tone(9, as[2], 125); noTone(spk); delay(25);
tone(9, g[2], 500);
noTone(spk);

}
if (val == '5') {
tone(9, 293.66, 200);
delay(200);
tone(9, 293.66, 100);

JAVIER ZABALA VERDUGO


INGENIRÍA ELECTRÓNICA
COMUNICACIONES INALMBRICAS 2019 – 1
delay(100);
tone(9, 293.66, 200);
delay(200);
tone(9, 293.66, 100);
delay(100);
tone(9, 293.66, 200);
delay(200);
tone(9, 293.66, 100);
delay(100);
tone(9, 293.66, 100);
delay(100);
tone(9, 293.66, 100);
delay(100);
tone(9, 293.66, 100);
delay(100);
tone(9, 293.66, 200);
delay(200);
tone(9, 293.66, 100);
delay(100);
tone(9, 293.66, 200);
delay(200);
tone(9, 293.66, 100);
delay(100);
tone(9, 293.66, 200);
delay(200);
tone(9, 293.66, 100);
delay(100);
tone(9, 293.66, 100);
delay(100);
tone(9, 293.66, 100);
delay(100);
tone(9, 293.66, 100);
delay(100);
tone(9, 293.66, 200);
delay(200);
tone(9, 293.66, 100);
delay(100);
tone(9, 293.66, 200);
delay(200);
tone(9, 293.66, 100);
delay(100);
tone(9, 293.66, 200);
delay(200);
tone(9, 293.66, 100);
delay(100);
tone(9, 293.66, 100);
delay(100);
tone(9, 440, 100);
delay(100);
tone(9, 523.25, 100);
delay(100);
tone(9, 587.33, 100);
delay(200);
tone(9, 587.33, 100);
delay(200);
tone(9, 587.33, 100);
delay(100);

JAVIER ZABALA VERDUGO


INGENIRÍA ELECTRÓNICA
COMUNICACIONES INALMBRICAS 2019 – 1
tone(9, 659.25, 100);
delay(100);
tone(9, 698.45, 100);
delay(200);
tone(9, 698.45, 100);
delay(200);
tone(9, 698.45, 100);
delay(100);
tone(9, 783.99, 100);
delay(100);
tone(9, 659.25, 100);
delay(200);
tone(9, 659.25, 100);
delay(200);
tone(9, 587.33, 100);
delay(100);
tone(9, 523.25, 100);
delay(100);
tone(9, 523.25, 100);
delay(100);
tone(9, 587.33, 100);
delay(300);
tone(9, 440, 100);
delay(100);
tone(9, 523.25, 100);
delay(100);
tone(9, 587.33, 100);
delay(200);
tone(9, 587.33, 100);
delay(200);
tone(9, 587.33, 100);
delay(100);
tone(9, 659.25, 100);
delay(100);
tone(9, 698.45, 100);
delay(200);
tone(9, 698.45, 100);
delay(200);
tone(9, 698.45, 100);
delay(100);
tone(9, 783.99, 100);
delay(100);
tone(9, 659.25, 100);
delay(200);
tone(9, 659.25, 100);
delay(200);
tone(9, 587.33, 100);
delay(100);
tone(9, 523.25, 100);
delay(100);
tone(9, 587.33, 100);
delay(400);
tone(9, 440, 100);
delay(100);
tone(9, 523.25, 100);
delay(100);
tone(9, 587.33, 100);

JAVIER ZABALA VERDUGO


INGENIRÍA ELECTRÓNICA
COMUNICACIONES INALMBRICAS 2019 – 1
delay(200);
tone(9, 587.33, 100);
delay(200);
tone(9, 587.33, 100);
delay(100);
tone(9, 698.45, 100);
delay(100);
tone(9, 783.99, 100);
delay(200);
tone(9, 783.99, 100);
delay(200);
tone(9, 783.99, 100);
delay(100);
tone(9, 880, 100);
delay(100);
tone(9, 932.33, 100);
delay(200);
tone(9, 932.33, 100);
delay(200);
tone(9, 880, 100);
delay(100);
tone(9, 783.99, 100);
delay(100);
tone(9, 880, 100);
delay(100);
tone(9, 587.33, 100);
delay(300);
tone(9, 587.33, 100);
delay(100);
tone(9, 659.25, 100);
delay(100);
tone(9, 698.45, 100);
delay(200);
tone(9, 698.45, 100);
delay(200);
tone(9, 783.99, 100);
delay(200);
tone(9, 880, 100);
delay(100);
tone(9, 587.33, 100);
delay(300);
tone(9, 587.33, 100);
delay(100);
tone(9, 698.45, 100);
delay(100);
tone(9, 659.25, 100);
delay(200);
tone(9, 659.25, 100);
delay(200);
tone(9, 698.45, 100);
delay(100);
tone(9, 587.33, 100);
delay(100);
tone(9, 659.25, 100);
delay(400);
tone(9, 880, 100);
delay(100);

JAVIER ZABALA VERDUGO


INGENIRÍA ELECTRÓNICA
COMUNICACIONES INALMBRICAS 2019 – 1
tone(9, 1046.50, 100);
delay(100);
tone(9, 1174.66, 100);
delay(200);
tone(9, 1174.66, 100);
delay(200);
tone(9, 1174.66, 100);
delay(100);
tone(9, 1318.51, 100);
delay(100);
tone(9, 1396.91, 100);
delay(200);
tone(9, 1396.91, 100);
delay(200);
tone(9, 1396.91, 100);
delay(100);
tone(9, 1567.98, 100);
delay(100);
tone(9, 1318.51, 100);
delay(200);
tone(9, 1318.51, 100);
delay(200);
tone(9, 1174.66, 100);
delay(100);
tone(9, 1046.50, 100);
delay(100);
tone(9, 1046.50, 100);
delay(100);
tone(9, 1174.66, 100);
delay(300);
tone(9, 880, 100);
delay(100);
tone(9, 1046.50, 100);
delay(100);
tone(9, 1174.66, 100);
delay(200);
tone(9, 1174.66, 100);
delay(200);
tone(9, 1174.66, 100);
delay(100);
tone(9, 1318.51, 100);
delay(100);
tone(9, 1396.91, 100);
delay(200);
tone(9, 1396.91, 100);
delay(200);
tone(9, 1396.91, 100);
delay(100);
tone(9, 1567.98, 100);
delay(100);
tone(9, 1318.51, 100);
delay(200);
tone(9, 1318.51, 100);
delay(200);
tone(9, 1174.66, 100);
delay(100);
tone(9, 1046.50, 100);

JAVIER ZABALA VERDUGO


INGENIRÍA ELECTRÓNICA
COMUNICACIONES INALMBRICAS 2019 – 1
delay(100);
tone(9, 1174.66, 100);
delay(400);
tone(9, 880, 100);
delay(100);
tone(9, 1046.50, 100);
delay(100);
tone(9, 1174.66, 100);
delay(200);
tone(9, 1174.66, 100);
delay(200);
tone(9, 1174.66, 100);
delay(100);
tone(9, 1396.91, 100);
delay(100);
tone(9, 1567.98, 100);
delay(200);
tone(9, 1567.98, 100);
delay(200);
tone(9, 1567.98, 100);
delay(100);
tone(9, 1760, 100);
delay(100);
tone(9, 1864.66, 100);
delay(200);
tone(9, 1864.66, 100);
delay(200);
tone(9, 1760, 100);
delay(100);
tone(9, 1567.98, 100);
delay(100);
tone(9, 1760, 100);
delay(100);
tone(9, 1174.66, 100);
delay(300);
tone(9, 1174.66, 100);
delay(100);
tone(9, 1318.51, 100);
delay(100);
tone(9, 1396.91, 100);
delay(200);
tone(9, 1396.91, 100);
delay(200);
tone(9, 1567.98, 100);
delay(200);
tone(9, 1760, 100);
delay(100);
tone(9, 1174.66, 100);
delay(300);
tone(9, 1174.66, 100);
delay(100);
tone(9, 1396.91, 100);
delay(100);
tone(9, 1318.51, 100);
delay(200);
tone(9, 1318.51, 100);
delay(200);

JAVIER ZABALA VERDUGO


INGENIRÍA ELECTRÓNICA
COMUNICACIONES INALMBRICAS 2019 – 1
tone(9, 1174.66, 100);
delay(100);
tone(9, 1108.73, 100);
delay(100);
tone(9, 1174.66, 100);
delay(200);
tone(9, 1174.66, 100);
delay(200);
tone(9, 1318.51, 100);
delay(200);
tone(9, 1396.91, 100);
delay(200);
tone(9, 1396.91, 100);
delay(100);
tone(9, 1396.91, 100);
delay(100);
tone(9, 1567.98, 100);
delay(200);
tone(9, 1760, 300);
delay(400);
tone(9, 1396.91, 100);
delay(100);
tone(9, 1174.66, 100);
delay(100);
tone(9, 880, 300);
delay(600);
tone(9, 1864.66, 300);
delay(400);
tone(9, 1396.91, 100);
delay(100);
tone(9, 1174.66, 100);
delay(100);
tone(9, 932.33, 300);
delay(600);
tone(9, 587.33, 100);
delay(100);
tone(9, 440, 100);
delay(200);
tone(9, 587.33, 100);
delay(300);
tone(9, 554.36, 100);
delay(400);
tone(9, 1567.98, 100);
delay(100);
tone(9, 1567.98, 100);
delay(100);
}

} // end void loop

JAVIER ZABALA VERDUGO

Вам также может понравиться