-
- Arduíno
- Arquitetura
- Banco de Dados
- Programação
- Segurança
- Curiosidades
-
Mais sobre o Professor
Sites e arquivos históricos +
-
Recomendações de boa leitura
-
Cursos Extras
Codigos HTML - Exemplos
Isaac Asimov
Aprender inteligência - Prof. Pier
Funcionamento do computador
Evolução da informática
Diferença entre entender e saber
Futuro da realizda aumentada
Guerra dos navegadores
-
Mostrando postagens com marcador microcontrolador. Mostrar todas as postagens
Mostrando postagens com marcador microcontrolador. Mostrar todas as postagens
Marcha imperial usando Buzzer
Ola Pessoal, vou fazer uma postagem de como tocar a Marcha imperial fazer um buzzer igual ao vídeo abaixo. Mas antes, vamos definir o que um buzzer:
Buzzer é um componente eletrônico que é composto por 2 camadas de Metal e uma terceira camada interna de cristal Piezoeléctrico, este componente recebe uma fonte de energia e através dela emite uma frequência sonora. Usando o PWM podemos criar notas musicais.
Circuito utilizado no projeto
![]() |
Figura 1. Circuito para ligação do Buzzer - crédito da imagem. |
Código para criação das notas musicais e melodia.
int ledPin = 13;
// Led ligada a porta 13
int speakerPin = 9;
//buzzer conectado a porta PWM 9
// Criando as notas musicais (C,D,E,F,G,A,B e derivações ) em função da sua frequência
#define c 261
#define d 294
#define e 329
#define f 349
#define g 391
#define gS 415
#define a 440
#define aS 455
#define b 466
#define cH 523
#define cSH 554
#define dH 587
#define dSH 622
#define eH 659
#define fH 698
#define fSH 740
#define gH 784
#define gSH 830
#define aH 880
//Referencia das notas http://home.mit.bme.hu/~bako/tonecalc/tonecalc.htm
void setup()
{
pinMode(ledPin, OUTPUT);
// definindo o pino onde o LED está ligado como saida
pinMode(speakerPin, OUTPUT);
// definindo o pino onde o Buzzer está ligado como saida
}
void loop() =
{
march();
}
void beep (unsigned char speakerPin, int frequencyInHertz, long timeInMilliseconds)
{
digitalWrite(ledPin, HIGH);
//LED acompanhando notas tocas
int x;
long delayAmount = (long)(1000000/frequencyInHertz);
long loopTime = (long)((timeInMilliseconds*1000)/(delayAmount*2));
for (x=0;x<loopTime;x++)
{
digitalWrite(speakerPin,HIGH);
delayMicroseconds(delayAmount);
digitalWrite(speakerPin,LOW);
delayMicroseconds(delayAmount);
}
digitalWrite(ledPin, LOW);
delay(20);
//a little delay to make all notes sound separate
}
void march()
{
//for the sheet music see:
//http://www.musicnotes.com/sheetmusic/mtd.asp?ppn=MN0016254
//this is just a translation of said sheet music to frequencies / time in ms
//used 500 ms for a quart note
beep(speakerPin, a, 500);
beep(speakerPin, a, 500);
beep(speakerPin, a, 500);
beep(speakerPin, f, 350);
beep(speakerPin, cH, 150);
beep(speakerPin, a, 500);
beep(speakerPin, f, 350);
beep(speakerPin, cH, 150);
beep(speakerPin, a, 1000);
//first bit
beep(speakerPin, eH, 500);
beep(speakerPin, eH, 500);
beep(speakerPin, eH, 500);
beep(speakerPin, fH, 350);
beep(speakerPin, cH, 150);
beep(speakerPin, gS, 500);
beep(speakerPin, f, 350);
beep(speakerPin, cH, 150);
beep(speakerPin, a, 1000);
//second bit...
beep(speakerPin, aH, 500);
beep(speakerPin, a, 350);
beep(speakerPin, a, 150);
beep(speakerPin, aH, 500);
beep(speakerPin, gSH, 250);
beep(speakerPin, gH, 250);
beep(speakerPin, fSH, 125);
beep(speakerPin, fH, 125);
beep(speakerPin, fSH, 250);
delay(250);
beep(speakerPin, aS, 250);
beep(speakerPin, dSH, 500);
beep(speakerPin, dH, 250);
beep(speakerPin, cSH, 250);
//start of the interesting bit
beep(speakerPin, cH, 125);
beep(speakerPin, b, 125);
beep(speakerPin, cH, 250);
delay(250);
beep(speakerPin, f, 125);
beep(speakerPin, gS, 500);
beep(speakerPin, f, 375);
beep(speakerPin, a, 125);
beep(speakerPin, cH, 500);
beep(speakerPin, a, 375);
beep(speakerPin, cH, 125);
beep(speakerPin, eH, 1000);
//more interesting stuff (this doesn't quite get it right somehow)
beep(speakerPin, aH, 500);
beep(speakerPin, a, 350);
beep(speakerPin, a, 150);
beep(speakerPin, aH, 500);
beep(speakerPin, gSH, 250);
beep(speakerPin, gH, 250);
beep(speakerPin, fSH, 125);
beep(speakerPin, fH, 125);
beep(speakerPin, fSH, 250);
delay(250);
beep(speakerPin, aS, 250);
beep(speakerPin, dSH, 500);
beep(speakerPin, dH, 250);
beep(speakerPin, cSH, 250);
//repeat... repeat
beep(speakerPin, cH, 125);
beep(speakerPin, b, 125);
beep(speakerPin, cH, 250);
delay(250);
beep(speakerPin, f, 250);
beep(speakerPin, gS, 500);
beep(speakerPin, f, 375);
beep(speakerPin, cH, 125);
beep(speakerPin, a, 500);
beep(speakerPin, f, 375);
beep(speakerPin, c, 125);
beep(speakerPin, a, 1000);
}
// O blog é logica é fácil agradece o site http://dragaosemchama.com.br/ pelo desenvolvimento
//do código aqui apresentado
Ainda ta com duvida, curta nossa pagina no facebook no link abaixo e poste sua duvida lá.
Assinar:
Postagens (Atom)