Adafruit Library
Public Member Functions | List of all members
Adafruit_CPlay_Speaker Class Reference

Class that stores state and functions for the speaker on CircuitPlayground boards. More...

#include <Adafruit_CPlay_Speaker.h>

Public Member Functions

void begin (void)
 Sets up Circuit Playground speaker for PWM audio output: enables 48 KHz high-speed PWM mode, configures Timer/Counter 4, sets PWM duty cycle to 50% (speaker idle position).
 
void end (void)
 Turns off PWM output to the speaker.
 
void set (uint8_t value)
 Sets speaker position, enables PWM output if needed. More...
 
void playSound (const uint8_t *data, uint32_t length, uint16_t sampleRate, bool tenBit=false)
 Plays digitized 8-bit audio (optionally 10 bits on Express board) from a PROGMEM (flash memory) buffer. Maybe 1-3 seconds tops depending on sampling rate (e.g. 8000 Hz = 8 Kbytes/second). Max ~20K space avail on Circuit Playground, lots more on Circuit Playground Express. This function currently "blocks" – it will not play sounds in the background while other code runs. More...
 
void say (const uint8_t *addr)
 speak the data at the passed location More...
 
void enable (bool e)
 enable or disable the speaker. This function only works on 'Express' boards. More...
 
void off (void)
 disable the speaker. More...
 
void on (void)
 enable the speaker. More...
 

Detailed Description

Class that stores state and functions for the speaker on CircuitPlayground boards.

Member Function Documentation

◆ set()

void Adafruit_CPlay_Speaker::set ( uint8_t  value)

Sets speaker position, enables PWM output if needed.

Parameters
valuethe value to set (0-255; 127=idle)

◆ playSound()

void Adafruit_CPlay_Speaker::playSound ( const uint8_t *  data,
uint32_t  len,
uint16_t  sampleRate,
bool  tenBit = false 
)

Plays digitized 8-bit audio (optionally 10 bits on Express board) from a PROGMEM (flash memory) buffer. Maybe 1-3 seconds tops depending on sampling rate (e.g. 8000 Hz = 8 Kbytes/second). Max ~20K space avail on Circuit Playground, lots more on Circuit Playground Express. This function currently "blocks" – it will not play sounds in the background while other code runs.

Parameters
datapointer to the audio data to play
lenthe length of the data in samples
sampleRatethe sample rate of the data in samples per second
tenBitOptional flag if true 10-bit mode is enabled. AVR ONLY

◆ say()

void Adafruit_CPlay_Speaker::say ( const uint8_t *  addr)

speak the data at the passed location

Parameters
addrpointer to the data

◆ enable()

void Adafruit_CPlay_Speaker::enable ( bool  e)

enable or disable the speaker. This function only works on 'Express' boards.

Parameters
epass true to enable, false to disable

◆ off()

void Adafruit_CPlay_Speaker::off ( void  )
inline

disable the speaker.

Note
this function only has an effect on 'Express' boards

◆ on()

void Adafruit_CPlay_Speaker::on ( void  )
inline

enable the speaker.

Note
this function only has an effect on 'Express' boards

The documentation for this class was generated from the following files: