Part One of my Project Course. Implementation of simple I/O and a custom defined protocol over UDP/IP.

Dependencies:   C12832 LM75B mbed EthernetInterface mbed-rtos

buzzer_music.cpp

Committer:
bertgereels
Date:
2018-02-26
Revision:
0:88d3b9015f7c
Child:
1:b5c534165dfe

File content as of revision 0:88d3b9015f7c:

#include "buzzer_music.h"
#include "master.h"

namespace ProjectOne{
    
    const int BuzzerMusic::frequencies[] = {110,110,110,98,130,110,98,130,110,165,165,165,175,130,104,98,130};
    const int BuzzerMusic::lengths[] = {480,480,480,360,120,480,360,120,960,480,480,480,360,120,480,360,120};
    const int BuzzerMusic::delays[] = {100,100,100,75,100,100,75,100,100,100,100,100,75,100,100,75,100};
    
    //PwmOut speaker(NC);
    
    BuzzerMusic::BuzzerMusic(PinName speakerPin) : speaker(speakerPin){
        
    }

    void BuzzerMusic::playMusic(int x, int y){
        for(int i = x; i < y; i ++){
            speaker = 0.5;
            speaker.period(1.0/frequencies[i]);
            wait((float)lengths[i]/1000);
            speaker = 0.0;
            wait((float)delays[i]/1000);
        }
        printf("Played Music");
    }

}