Oooooo. What about having the knob change the tone of the speaker? No prob. Same idea as the previous sketch. Just map the knob values to tone frequencies.

The Circuit Playground speaker is really only usable over a range of about 100Hz to 10000Hz, which leads us to the following code.

///////////////////////////////////////////////////////////////////////////////
// Circuit Playground Analog In - Speaker Fun ?
//
// Author: Carter Nelson
// MIT License (https://opensource.org/licenses/MIT)

#include <Adafruit_CircuitPlayground.h>

uint16_t value;
uint16_t freq;

///////////////////////////////////////////////////////////////////////////////
void setup() {
  Serial.begin(9600);
  CircuitPlayground.begin();
}

///////////////////////////////////////////////////////////////////////////////
void loop() {
  value = analogRead(10);
  freq = map(value, 0, 1023, 100, 10000);

  CircuitPlayground.playTone(freq, 100, false);
}

Load that code up and run it. Spin the knob. Make some weird outer space theremin like music sounds. Hopefully the dogs don't start howling.

This guide was first published on Feb 11, 2017. It was last updated on Feb 11, 2017.

This page (Speaker Fun) was last updated on Oct 22, 2021.

Text editor powered by tinymce.