This is the No Sleep Pillow! I used four capacitive touch sensors to control the volume of a battery powered speaker unit.
I simply drove a transistor to short the input audio connection to ground to lower the voltage.
I tried initially to do this in a digital manner but the results weren’t great. I based my code mostly on this example from GitHub, with a few important changes.
descriptor.srcaddr = (uint32_t) &ADC->RESULT.reg;
descriptor.btcnt = HWORDS;
descriptor.dstaddr = (uint32_t)&DAC->DATA.reg; // end address
I pulled the ADC results into the DAC, instead of into memory.
descriptor.btctrl = DMAC_BTCTRL_BEATSIZE_HWORD | DMAC_BTCTRL_VALID;
I also removed the DMAC_BTCTRL_DSTINC
flag in the btctrl
register. This was causing the controller to auto-increment the memory addresses it was writing to, creating invalid memory writes. I also played around with the number of half-words in the buffer, but ultimately keeping to one seemed to work as well as other values.
Still, the sound quality was terrible, so I decided to not go the digital route and pursued my analog solution. Potentially, more filtering on the input could have solved some of these issues but the Arduino’s DAC isn’t as high resolution as used in most audio-quality products.