Library for SOMO II sound module (http://www.4dsystems.com.au/product/SOMO_II/) For use with stateScript (https://developer.mbed.org/users/mkarlsso/code/stateScript_v2/)

Dependents:   stateScript_v2_karpovalab Nucleo_statescript stateScript_v2

Committer:
alustig3
Date:
Wed Apr 26 19:02:16 2017 +0000
Revision:
1:5a7359b415c8
Parent:
0:a4f14eadd0df
Removed unused definitions

Who changed what in which revision?

UserRevisionLine numberNew contents of line
alustig3 0:a4f14eadd0df 1 // SOMO II sound module http://www.4dsystems.com.au/product/SOMO_II/
alustig3 0:a4f14eadd0df 2 // Datasheet http://www.4dsystems.com.au/productpages/SOMO-II/downloads/SOMO-II_datasheet_R_1_2.pdf
alustig3 0:a4f14eadd0df 3 #include "mbed.h"
alustig3 0:a4f14eadd0df 4 #include "SOMO.h"
alustig3 0:a4f14eadd0df 5
alustig3 0:a4f14eadd0df 6 //constructor
alustig3 0:a4f14eadd0df 7 SOMO::SOMO(PinName TXPin, PinName RXPin): _serialSOMO(TXPin,RXPin){
alustig3 0:a4f14eadd0df 8 init();
alustig3 0:a4f14eadd0df 9 }
alustig3 0:a4f14eadd0df 10
alustig3 0:a4f14eadd0df 11
alustig3 0:a4f14eadd0df 12 void SOMO::init(){ //configure the mbed for SOMO board
alustig3 0:a4f14eadd0df 13 _serialSOMO.baud(9600);
alustig3 0:a4f14eadd0df 14 }
alustig3 0:a4f14eadd0df 15
alustig3 0:a4f14eadd0df 16 void SOMO::playTrackName(char name[]){ //added so SOMO and smartWAV have same functions and can therefore be used interchangeably
alustig3 0:a4f14eadd0df 17 }
alustig3 0:a4f14eadd0df 18
alustig3 0:a4f14eadd0df 19 /*
alustig3 0:a4f14eadd0df 20 mp3 sound files should be placed in "01" folder in the root directory of SD card. The filenames should start with number between 001 and 099
alustig3 0:a4f14eadd0df 21 followed by up to 5 characters (the freakin' datasheet says up to 32 characters, don't listen to it, it's a liar and a con artist!)
alustig3 0:a4f14eadd0df 22 examples: root/01/001left.mp3, root/01/002right.mp3, root/01/099abcde.mp3
alustig3 0:a4f14eadd0df 23 */
alustig3 0:a4f14eadd0df 24 void SOMO::playTrackNum(unsigned char track){ //play specific track number
alustig3 0:a4f14eadd0df 25 unsigned char play[8] = {0x7E, 0x0F, 0x00, 0x01, track, 0xFF, (240-track), 0xEF};
alustig3 0:a4f14eadd0df 26 for (int i = 0; i <8; i++){
alustig3 0:a4f14eadd0df 27 _serialSOMO.putc(play[i]);
alustig3 0:a4f14eadd0df 28 }
alustig3 0:a4f14eadd0df 29 }
alustig3 0:a4f14eadd0df 30
alustig3 0:a4f14eadd0df 31 void SOMO::stopTrack(){ //Stop playing any active song
alustig3 0:a4f14eadd0df 32 unsigned char stop[8] = {0x7E, 0x16, 0x00, 0x00, 0x00, 0xFF, 0xEA, 0xEF};
alustig3 0:a4f14eadd0df 33 for (int i = 0; i <8; i++){
alustig3 0:a4f14eadd0df 34 _serialSOMO.putc(stop[i]);
alustig3 0:a4f14eadd0df 35 }
alustig3 0:a4f14eadd0df 36 }
alustig3 0:a4f14eadd0df 37
alustig3 0:a4f14eadd0df 38 void SOMO::volume(unsigned char vol){ //change volume between 0 and 30
alustig3 0:a4f14eadd0df 39 if (vol>0 && vol<31){
alustig3 0:a4f14eadd0df 40 unsigned char changeVol[8] = {0x7E, 0x06, 0x00, 0x00, vol, 0xFF, (250-vol), 0xEF};
alustig3 0:a4f14eadd0df 41 for (int i = 0; i <8; i++){
alustig3 0:a4f14eadd0df 42 _serialSOMO.putc(changeVol[i]);
alustig3 0:a4f14eadd0df 43 }
alustig3 0:a4f14eadd0df 44 }
alustig3 0:a4f14eadd0df 45 }
alustig3 0:a4f14eadd0df 46
alustig3 0:a4f14eadd0df 47 void SOMO::reset(){ //reset SOMO module
alustig3 0:a4f14eadd0df 48 unsigned char reset[8] = {0x7E, 0x0C, 0x00, 0x00, 0x00, 0xFF, 0xF4, 0xEF};
alustig3 0:a4f14eadd0df 49 for (int i = 0; i <8; i++){
alustig3 0:a4f14eadd0df 50 _serialSOMO.putc(reset[i]);
alustig3 0:a4f14eadd0df 51 }
alustig3 0:a4f14eadd0df 52 }