Tool for playing 8bit like music on Piezo speaker.
PlayTone.h@0:b8d34e475dd9, 2016-10-01 (annotated)
- Committer:
- TeaPack_CZ
- Date:
- Sat Oct 01 20:48:12 2016 +0000
- Revision:
- 0:b8d34e475dd9
- Child:
- 1:90161871ad88
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TeaPack_CZ | 0:b8d34e475dd9 | 1 | #ifndef PLAYTONE |
TeaPack_CZ | 0:b8d34e475dd9 | 2 | #define PLAYTONE |
TeaPack_CZ | 0:b8d34e475dd9 | 3 | |
TeaPack_CZ | 0:b8d34e475dd9 | 4 | #include "mbed.h" |
TeaPack_CZ | 0:b8d34e475dd9 | 5 | #include "Piezo.h" |
TeaPack_CZ | 0:b8d34e475dd9 | 6 | |
TeaPack_CZ | 0:b8d34e475dd9 | 7 | #ifndef NOTE |
TeaPack_CZ | 0:b8d34e475dd9 | 8 | #define NOTE |
TeaPack_CZ | 0:b8d34e475dd9 | 9 | |
TeaPack_CZ | 0:b8d34e475dd9 | 10 | struct Note { |
TeaPack_CZ | 0:b8d34e475dd9 | 11 | int idx; |
TeaPack_CZ | 0:b8d34e475dd9 | 12 | float value; |
TeaPack_CZ | 0:b8d34e475dd9 | 13 | }; |
TeaPack_CZ | 0:b8d34e475dd9 | 14 | |
TeaPack_CZ | 0:b8d34e475dd9 | 15 | #endif |
TeaPack_CZ | 0:b8d34e475dd9 | 16 | |
TeaPack_CZ | 0:b8d34e475dd9 | 17 | class PlayTone{ |
TeaPack_CZ | 0:b8d34e475dd9 | 18 | |
TeaPack_CZ | 0:b8d34e475dd9 | 19 | public: |
TeaPack_CZ | 0:b8d34e475dd9 | 20 | PlayTone(PinName PS); |
TeaPack_CZ | 0:b8d34e475dd9 | 21 | |
TeaPack_CZ | 0:b8d34e475dd9 | 22 | int setBPM(int); |
TeaPack_CZ | 0:b8d34e475dd9 | 23 | void transpose(int); |
TeaPack_CZ | 0:b8d34e475dd9 | 24 | |
TeaPack_CZ | 0:b8d34e475dd9 | 25 | void playTone(int,float); |
TeaPack_CZ | 0:b8d34e475dd9 | 26 | void playSequence(int,int[],float[]); |
TeaPack_CZ | 0:b8d34e475dd9 | 27 | void playSequence(int,Note[]); |
TeaPack_CZ | 0:b8d34e475dd9 | 28 | |
TeaPack_CZ | 0:b8d34e475dd9 | 29 | void setStaccatoDuty(float); |
TeaPack_CZ | 0:b8d34e475dd9 | 30 | void playStaccato(int,float); |
TeaPack_CZ | 0:b8d34e475dd9 | 31 | void playStaccatoSequence(int,int[],float[]); |
TeaPack_CZ | 0:b8d34e475dd9 | 32 | void playStaccatoSequence(int,Note[]); |
TeaPack_CZ | 0:b8d34e475dd9 | 33 | |
TeaPack_CZ | 0:b8d34e475dd9 | 34 | void silence(float); |
TeaPack_CZ | 0:b8d34e475dd9 | 35 | void stop(); |
TeaPack_CZ | 0:b8d34e475dd9 | 36 | |
TeaPack_CZ | 0:b8d34e475dd9 | 37 | private: |
TeaPack_CZ | 0:b8d34e475dd9 | 38 | Piezo _speaker; |
TeaPack_CZ | 0:b8d34e475dd9 | 39 | float tone[85]; |
TeaPack_CZ | 0:b8d34e475dd9 | 40 | |
TeaPack_CZ | 0:b8d34e475dd9 | 41 | int offset; |
TeaPack_CZ | 0:b8d34e475dd9 | 42 | int _bpm; |
TeaPack_CZ | 0:b8d34e475dd9 | 43 | float _bpm_ms; |
TeaPack_CZ | 0:b8d34e475dd9 | 44 | |
TeaPack_CZ | 0:b8d34e475dd9 | 45 | float max_BPM; |
TeaPack_CZ | 0:b8d34e475dd9 | 46 | float min_BPM; |
TeaPack_CZ | 0:b8d34e475dd9 | 47 | |
TeaPack_CZ | 0:b8d34e475dd9 | 48 | float _duty; |
TeaPack_CZ | 0:b8d34e475dd9 | 49 | }; |
TeaPack_CZ | 0:b8d34e475dd9 | 50 | |
TeaPack_CZ | 0:b8d34e475dd9 | 51 | #endif |