Library API

begin() : initializes the Audio Hacker shield

readADC() : read the voltage on the ADC and return a 12-bit value. Returns an unsigned int in the range [0-4095].

readADC_8bit() : read the voltage on the ADC and return an 8-bit value. Returns an byte in the range [0-255]. The least significant 4 bits of the 12-bit ADC reading are discarded.

writeDAC(unsigned int output) : write a 12-bit value in the range [0-4095] to the DAC.

writeDAC_8bit(byte output) : write an 8-bit value in the range [0-255] to the DAC. The actual value written to the DAC is 12 bits in the range [0-4095] with the lower four bits as 0.

writeSRAM(byte chipNumber, long address, byte data) : write a byte to the memory on one of the two SRAM chips. Chips are numbered 0 and 1. Address range is [0-131071].

writeSRAM(byte chipNumber, long address, unsigned int data) : write a 16-bit value to the memory on one of the two SRAM chips. Chips are numbered 0 and 1. Address range is [0-131070]. The two bytes of the unsigned int will be stored at address addressand address+1.

writeSRAM(byte chipNumber, long address, byte *buf, int len) : write multiple bytes to the memory on one of the two SRAM chips. Chips are numbered 0 and 1. len specifies the number of bytes from the buffer to write. Address range is [0-(131071-(len-1))].

writeSRAMPacked(byte chipNumber, long address, unsigned int data1, unsigned int data2) : store two 12-bit audio samples efficiently in 3 bytes of SRAM by “packing” the data efficiently. The two 12-bit values data1 and data2 will be packed into 3 bytes by discarding the upper 4 bits of each unsigned int. Chips are numbered 0 and 1. Address range is [0-131069]. The data will be stored at addresses address, address+1, and address+2.

address address+1 address+2 data1 data2

readSRAM(byte chipNumber, long address) : read a byte from memory. Chips are numbered 0 and 1. Address range is [0-131071]. The return value is the byte read.

readSRAM(byte chipNumber, long address, byte *buf, int len) : read multiple bytes from memory into buffer buf. Chips are numbered 0 and 1. len specifies the number of bytes to read into the buffer. Address range is [0-(131071-(len-1))].

readSRAMPacked(byte chipNumber, long address, unsigned int *buf) : read two 12-bit audio samples from 3 bytes of SRAM. The two 12-bit values are packed into 3 bytes by discarding the upper 4 bits of each unsigned int. Chips are numbered 0 and 1. Address range is [0-131069]. The data will be read into buf[0] and buf[1].