0% found this document useful (0 votes)
2K views

Numa Numa Song in Arduino

This Arduino code defines constants for musical notes and plays a song on a piezoelectric buzzer. It contains arrays defining the notes and durations of each note in the song. The setup function initializes the piezo buzzer pin and 7 LED pins as outputs. The loop continuously calls the tocar function, passing each note and duration, which plays the tone and lights the corresponding LED.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

Numa Numa Song in Arduino

This Arduino code defines constants for musical notes and plays a song on a piezoelectric buzzer. It contains arrays defining the notes and durations of each note in the song. The setup function initializes the piezo buzzer pin and 7 LED pins as outputs. The loop continuously calls the tocar function, passing each note and duration, which plays the tone and lights the corresponding LED.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

NumaSong.

15/02/12 14:29

#define #define #define #define #define #define #define #define #define #define

DO 261.626 RE 293.665 MI 329.628 FA 349.228 SOL 391.995 LA 440.000 SI 493.883 DO2 523.251 RE2 587.33 MI2 659.255

// Frecuencia en hercios de las notas musicales

#define SILENCIO 0 int int int int int int int int piezoelectrico = 8; led1 = 1; led2 = 2; led3 = 3; led4 = 4; led5 = 5; led6 = 6; led7 = 7; // Pin 8 para el cable rojo del piezoelctrico

float cancion[]={ DO2,SI,DO2,DO2,LA,LA,SI,LA, SOL, MI, SILENCIO, DO2, MI2, RE2, DO2, SOL, SILENCIO, SOL, RE2, DO2, SI, DO2, SI, LA, DO2,SI,DO2,DO2,LA,LA,SI,LA, SOL, MI, SILENCIO, DO2, MI2, RE2, RE2, SI, RE2, SI, DO2, DO2, SI, LA }; // Cancion int duracion[]={2, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 1, 1, 2}; // Duracion de cada nota void setup() { // El piezoelctrico est en un pin digital de salida pinMode(piezoelectrico,OUTPUT); // Los leds en los pines del 1 al 7 pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); pinMode(led4, OUTPUT); pinMode(led5, OUTPUT); pinMode(led6, OUTPUT); pinMode(led7, OUTPUT); } void loop() { for (int i=0; i<46; i++) { tocar(cancion[i], duracion[i]); } } /* MI -> Led 1 SOL -> Led 2 LA -> Led 3 SI -> Led 4 DO2 -> Led 5 RE2 -> Led 6 MI2 -> Led 7 */

Page 1 of 2

NumaSong.c

15/02/12 14:29

void tocar(float nota, int dur) { apagarLeds(); if (nota == 0) noTone(piezoelectrico); else { tone(piezoelectrico, round(nota)); if (nota == MI) digitalWrite(led1, else if (nota == SOL) digitalWrite(led2, else if (nota == LA) digitalWrite(led3, else if (nota == SI) digitalWrite(led4, else if (nota == DO2) digitalWrite(led5, else if (nota == RE2) digitalWrite(led6, else if (nota == MI2) digitalWrite(led7, } delay(dur*250); } void apagarLeds() { digitalWrite(led1, digitalWrite(led2, digitalWrite(led3, digitalWrite(led4, digitalWrite(led5, digitalWrite(led6, digitalWrite(led7, } LOW); LOW); LOW); LOW); LOW); LOW); LOW); HIGH); HIGH); HIGH); HIGH); HIGH); HIGH); HIGH);

Page 2 of 2

You might also like