Este es el esquema de montaje de la segunda practica
Este es el diagrama esquemático
Montaje basico se puede emplear un parlante normal de 8 ohm y el transistor puede ser el popular 2n2222 |
#define RunLed PORTAbits.RA4 int speakerPin = 11; #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 #define vua 255 #define vub 127 #define vuc 63 #define vud 31 #define vue 15 #define vuf 7 #define vug 3 long delayAmount; long loopTime; int x; void setup() { pinMode(speakerPin, OUTPUT); TRISB = 0; //establece speakerPin como salida } void beep (unsigned char speakerPin, int frequencyInHertz, long timeInMilliseconds, int vuLed) { frequencyInHertz; timeInMilliseconds; RunLed=LOW; PORTB = vuLed; delayAmount = (long)(1000000/frequencyInHertz); loopTime = (long)((timeInMilliseconds*1000)/(delayAmount*2)); for (x=0;x<loopTime;x++) { digitalWrite(speakerPin,HIGH); delayMicroseconds(delayAmount); digitalWrite(speakerPin,LOW); delayMicroseconds(delayAmount); } RunLed=HIGH; PORTB = 0; delay(20); //una pequeña pausa para que las notas suenen por separado } void march() { //una traducción de una partitura a frecuencia / tiempo (en milisegundos) //se usa 500 ms para un cuarto de nota beep(speakerPin, a, 500,vua); beep(speakerPin, a, 500,vua ); beep(speakerPin, a, 500,vua ); beep(speakerPin, f, 350,vuf ); beep(speakerPin, cH, 150,vuc ); beep(speakerPin, a, 500,vua ); beep(speakerPin, f, 350,vuf ); beep(speakerPin, cH, 150,vuc ); beep(speakerPin, a, 1000,vua ); //first bit beep(speakerPin, eH, 500,vue ); beep(speakerPin, eH, 500,vue ); beep(speakerPin, eH, 500,vue ); beep(speakerPin, fH, 350,vuf ); beep(speakerPin, cH, 150,vuc ); beep(speakerPin, gS, 500,vug ); beep(speakerPin, f, 350,vuf ); beep(speakerPin, cH, 150,vuc ); beep(speakerPin, a, 1000,vua ); //second bit... beep(speakerPin, aH, 500,vua ); beep(speakerPin, a, 350,vua ); beep(speakerPin, a, 150,vua ); beep(speakerPin, aH, 500,vua ); beep(speakerPin, gSH, 250,vug ); beep(speakerPin, gH, 250,vug ); beep(speakerPin, fSH, 125,vuf ); beep(speakerPin, fH, 125,vuf ); beep(speakerPin, fSH, 250,vuf ); delay(250); beep(speakerPin, aS, 250,vua ); beep(speakerPin, dSH, 500,vud ); beep(speakerPin, dH, 250,vud ); beep(speakerPin, cSH, 250,vuc ); //start of the interesting bit beep(speakerPin, cH, 125,vuc); beep(speakerPin, b, 125,vub); beep(speakerPin, cH, 250,vuc); delay(250); beep(speakerPin, f, 125,vuf); beep(speakerPin, gS, 500,vug ); beep(speakerPin, f, 375,vuf); beep(speakerPin, a, 125,vua ); beep(speakerPin, cH, 500,vuc ); beep(speakerPin, a, 375,vua ); beep(speakerPin, cH, 125,vuc ); beep(speakerPin, eH, 1000,vue ); beep(speakerPin, aH, 500,vua ); beep(speakerPin, a, 350,vua); beep(speakerPin, a, 150,vua); beep(speakerPin, aH, 500,vua); beep(speakerPin, gSH, 250,vug); beep(speakerPin, gH, 250,vug); beep(speakerPin, fSH, 125,vuf); beep(speakerPin, fH, 125,vuf); beep(speakerPin, fSH, 250,vuf); delay(250); beep(speakerPin, aS, 250,vua); beep(speakerPin, dSH, 500,vud); beep(speakerPin, dH, 250,vud); beep(speakerPin, cSH, 250,vuc); //repeat... repeat beep(speakerPin, cH, 125,vuc); beep(speakerPin, b, 125,vub); beep(speakerPin, cH, 250,vuc); delay(250); beep(speakerPin, f, 250,vuf); beep(speakerPin, gS, 500,vug); beep(speakerPin, f, 375,vuf); beep(speakerPin, cH, 125,vuc); beep(speakerPin, a, 500,vua); beep(speakerPin, f, 375,vuf); beep(speakerPin, c, 125,vuc); beep(speakerPin, a, 1000,vua); } void loop() // se ejecuta una y otra vez... { march(); }
Montaje |
Diagrama Esquemático |