USB Speak with Digital Volume Control

Dependencies:   AD5206 USBDevice mbed

Fork of USBAUDIO_speaker by Samuel Mokrani

Files at this revision

API Documentation at this revision

Comitter:
taoqiuyang
Date:
Sat Oct 17 22:14:31 2015 +0000
Parent:
9:a7a9d8e8a740
Child:
11:d62d67b930f7
Commit message:
Working demo;

Changed in this revision

AD5206.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AD5206.lib	Sat Oct 17 22:14:31 2015 +0000
@@ -0,0 +1,1 @@
+AD5206#843bc5c95021
--- a/main.cpp	Fri Mar 01 13:21:37 2013 +0000
+++ b/main.cpp	Sat Oct 17 22:14:31 2015 +0000
@@ -2,6 +2,15 @@
 
 #include "mbed.h"
 #include "USBAudio.h"
+#include "AD5206.h"
+
+AD5206 digipot(p5, p6, p7,p8);
+int val=150;
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalIn  but1(p22);
+DigitalIn  but2(p21);
+
 
 // frequency: 48 kHz
 #define FREQ 48000
@@ -20,6 +29,8 @@
 
 // ticker to send data to the speaker at the good frequency
 Ticker tic;
+Ticker tic2;
+
 
 // buffer where will be store one audio packet (LENGTH_AUDIO_PACKET/2 because we are storing int16 and not uint8)
 int16_t buf[AUDIO_LENGTH_PACKET/2];
@@ -65,11 +76,23 @@
     speaker.write_u16((uint16_t)speaker_value);
 }
 
+void tic_handler2() {
+    led1=0;
+    led2=0;
+    if (!but1){led1=1;val+=20;}
+    if (!but2){led2=1;val-=20;}
+    digipot.write_AD5206(0,val);
+    
+    if (val>255){val=255;}
+    if (val<0)  {val=0;}
+}
+
 int main() {
 
     // attach a function executed each 1/FREQ s
     tic.attach_us(tic_handler, 1000000.0/(float)FREQ);
-
+    tic2.attach(tic_handler2, 0.2);
+    
     while (1) {
         // read an audio packet
         audio.read((uint8_t *)buf);