Tool for playing 8bit like music on Piezo speaker.

PlayTone.h

Committer:
TeaPack_CZ
Date:
2016-10-01
Revision:
0:b8d34e475dd9
Child:
1:90161871ad88

File content as of revision 0:b8d34e475dd9:

#ifndef PLAYTONE
#define PLAYTONE

#include "mbed.h"
#include "Piezo.h"

#ifndef NOTE
#define NOTE

struct Note {
    int idx;
    float value;
    };

#endif

class PlayTone{

public:
    PlayTone(PinName PS);
    
    int setBPM(int);
    void transpose(int);
    
    void playTone(int,float);
    void playSequence(int,int[],float[]);
    void playSequence(int,Note[]);
    
    void setStaccatoDuty(float);
    void playStaccato(int,float);
    void playStaccatoSequence(int,int[],float[]);
    void playStaccatoSequence(int,Note[]);
    
    void silence(float);
    void stop();
    
private:
    Piezo _speaker;
    float tone[85];
    
    int offset;
    int _bpm;
    float _bpm_ms;
    
    float max_BPM;
    float min_BPM;
    
    float _duty;
};

#endif