Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
AkitaSM.cpp
00001 /** 00002 * ... 00003 * @author Kazushi Mukaiyama 00004 */ 00005 00006 #include "AkitaSM.h" 00007 #include "mbed.h" 00008 00009 #define AKITA_AICTRL0 0x0C // Current song number / Song change 00010 #define AKITA_AICTRL1 0x0D // Number of songs on MMC 00011 #define AKITA_AICTRL2 0x0E // Number of songs on MMC (VS1103b) 00012 #define AKITA_AICTRL3 0x0F // Play mode 00013 00014 AkitaSM::AkitaSM(int addr, PinName sda, PinName scl) 00015 : _i2c(sda, scl) { 00016 00017 _addr = addr<<1; 00018 00019 // Set up the i2c interface 00020 //_i2c.frequency(1000000); 00021 } 00022 00023 void AkitaSM::play(int index, bool loop) 00024 { 00025 char p = 0; 00026 if(loop) p = 1; else p = 3; 00027 _cmd[0] = AKITA_AICTRL3; 00028 _cmd[1] = 0; 00029 _cmd[2] = p << 1; 00030 _i2c.write(_addr, _cmd, 3); 00031 wait(0.01); 00032 int n = 0x8000 + index; 00033 _cmd[0] = AKITA_AICTRL0; 00034 _cmd[1] = (n >> 8) & 0xFF; 00035 _cmd[2] = n & 0xFF; 00036 _i2c.write(_addr, _cmd, 3); 00037 //_cmd[0] = index & 0xFF; 00038 //_i2c.write(_addr, _cmd, 1); 00039 } 00040 00041 void AkitaSM::stop() 00042 { 00043 _cmd[0] = AKITA_AICTRL3; 00044 _cmd[1] = 0; 00045 _cmd[2] = 1<<4; 00046 _i2c.write(_addr, _cmd, 3); 00047 } 00048 00049 void AkitaSM::control(char r, int cmd) 00050 { 00051 //r is resistor 0x00-0x0f 00052 _cmd[0] = r; 00053 _cmd[1] = (cmd >> 8) & 0xFF; 00054 _cmd[2] = cmd & 0xFF; 00055 _i2c.write(_addr, _cmd, 3); 00056 } 00057 00058 char* AkitaSM::isPlaying() 00059 { 00060 //_i2c.read(_addr, _cmd, 4); 00061 _i2c.read(_addr, _cmd, 4); 00062 return _cmd; 00063 }
Generated on Tue Jul 12 2022 19:55:09 by
1.7.2