CSE: Pitch Pot

This sketch plays an intermittent tone in loop(), varying the pitch and delay according to potentiometer settings.

// pitch_pot - vary delay and pitch, using a potentiometer

int ij_lc     =   2;  // pin A2 senses left pot
int ij_rc     =   3;  // pin A3 senses right pot
int oj_rc     =   9;  // pin D9 drives right channel

void setup() {
  pinMode(oj_rc, OUTPUT);

void loop() {
  int delay_ms = analogRead(ij_rc) / 4;
  int pitch_hz = analogRead(ij_lc) + 100;
  tone(oj_rc, pitch_hz, delay_ms);
  delay(delay_ms * 2);



By setting the pitch to 100 more than the measured analog value (0..1023), we bring it up into a range that is easily audible (100-1123 Hz).

This wiki page is maintained by Rich Morin, an independent consultant specializing in software design, development, and documentation. Please feel free to email comments, inquiries, suggestions, etc!

Topic revision: r9 - 05 Mar 2016, RichMorin
This site is powered by Foswiki Copyright © by the contributing authors. All material on this wiki is the property of the contributing authors.
Foswiki version v2.1.6, Release Foswiki-2.1.6, Plugin API version 2.4
Ideas, requests, problems regarding CFCL Wiki? Send us email