hrv_himna

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 PwmOut buzzer(p21);
00003 //frekvencija melodije "Lijepa naša"
00004 float frequency[]= {659.3, 659.3, 659.3, 587.3, 587.3, 523.3, 523.3, 392, 349.2, 329.6, 349.2,
00005                     392, 440, 392, 349.2, 329.6, 349.2, 392, 659.3, 659.3, 659.3, 587.3, 587.3, 523.3, 523.3, 392,
00006                     349.2, 329.6, 349.2, 392, 440, 493.9, 493.9, 587.3, 523.3, 493.9, 493.9, 493.9, 440, 493.9,
00007                     493.9, 523.3, 587.3, 493.9, 587.3, 587.3, 587.3, 587.3, 587.3, 523.3, 493.9, 440, 392, 659.3,
00008                     659.3, 659.3, 587.3, 587.3, 523.3, 523.3, 392, 349.2, 329.6, 349.2, 392, 440, 493.9, 493.9,
00009                     587.3, 523.3, 0
00010                    };
00011 //trajanje nota
00012 float beat[]= {1, 1, 1.5, 0.5, 0.5, 0.5, 1, 2, 0.5, 0.5, 0.5, 0.5, 2, 0.5, 0.5, 0.5, 0.5, 2, 1, 1, 1.5, 0.5,
00013                0.5, 0.5, 1, 2, 0.5, 0.5, 0.5, 0.5, 2, 0.5, 0.5, 1, 2, 1, 1, 1.5, 0.5, 1, 0.5, 0.5, 1.5, 0.5, 0.5, 0.5, 0.5,
00014                0.5, 1, 1, 1, 1, 2, 1, 1, 1.5, 0.5, 0.5, 0.5, 1, 2, 0.5, 0.5, 0.5, 0.5, 2, 0.5, 0.5, 1, 2, 0.5
00015               };
00016 int main()
00017 {
00018     while (1) {
00019         for (int i=0; i<=70; i++) {
00020             buzzer.period(1/(frequency[i])); // set PWM period
00021             buzzer=0.5; // set duty cycle
00022             wait(0.5*beat[i]); // hold for beat period
00023         }
00024     }
00025 }