Difference between revisions of "Arduino: PCM Audio Play"
Jump to navigation
Jump to search
Onnowpurbo (talk | contribs) |
Onnowpurbo (talk | contribs) |
||
Line 42: | Line 42: | ||
if( tmrpcm.isPlaying()==1 ) Serial.println("is playing"); | if( tmrpcm.isPlaying()==1 ) Serial.println("is playing"); | ||
} | } | ||
+ | |||
+ | |||
+ | ==Fungsi TMPpcm== | ||
+ | |||
+ | |||
+ | TMRpcm audio; | ||
+ | audio.play("filename"); plays a file | ||
+ | audio.play("filename",30); plays a file starting at 30 seconds into the track | ||
+ | audio.speakerPin = 11; set to 5,6,11 or 46 for Mega, 9 for Uno, Nano, etc. | ||
+ | audio.disable(); disables the timer on output pin and stops the music | ||
+ | audio.stopPlayback(); stops the music, but leaves the timer running | ||
+ | audio.isPlaying(); returns 1 if music playing, 0 if not | ||
+ | audio.pause(); pauses/unpauses playback | ||
+ | audio.quality(1); Set 1 for 2x oversampling | ||
+ | audio.volume(0); 1(up) or 0(down) to control volume | ||
+ | audio.setVolume(0); 0 to 7. Set volume level | ||
+ | audio.loop(1); 0 or 1. Can be changed during playback for full control of looping. |
Revision as of 17:41, 28 May 2018
Install TMRpcm library
cd ~/Arduino/libraries/ wget https://github.com/TMRh20/TMRpcm/archive/master.zip unzip master.zip mv TMRpcm-master/ TMRpcm
Edit
cd ~/Arduino/libraries/TMRpcm vi pcmConfig.h
Pastikan,
#define DISABLE_SPEAKER2
Code
#include "SD.h" #define SD_ChipSelectPin 4 #include "TMRpcm.h" #include "SPI.h" TMRpcm tmrpcm; void setup(){ tmrpcm.speakerPin = 9; Serial.begin(9600); if (!SD.begin(SD_ChipSelectPin)) { Serial.println("SD fail"); return; } tmrpcm.quality(1); tmrpcm.setVolume(2); tmrpcm.play("morat.wav"); }
void loop(){ if( tmrpcm.isPlaying()==1 ) Serial.println("is playing"); }
Fungsi TMPpcm
TMRpcm audio; audio.play("filename"); plays a file audio.play("filename",30); plays a file starting at 30 seconds into the track audio.speakerPin = 11; set to 5,6,11 or 46 for Mega, 9 for Uno, Nano, etc. audio.disable(); disables the timer on output pin and stops the music audio.stopPlayback(); stops the music, but leaves the timer running audio.isPlaying(); returns 1 if music playing, 0 if not audio.pause(); pauses/unpauses playback audio.quality(1); Set 1 for 2x oversampling audio.volume(0); 1(up) or 0(down) to control volume audio.setVolume(0); 0 to 7. Set volume level audio.loop(1); 0 or 1. Can be changed during playback for full control of looping.