CSE: Pitch Tilt

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

// pitch_tilt - vary delay and pitch, using a joystick

int ij_vj     =   0;  // pin A0 senses vertical   joystick pot
int ij_hj     =   1;  // pin A1 senses horizontal joystick pot

int oj_rc     =   9;  // pin D9 drives right channel

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

void loop() {
  int delay_ms = analogRead(ij_hj) / 4;
  int pitch_hz = analogRead(ij_vj) + 100;

  tone(oj_rc, pitch_hz, delay_ms);
  delay(delay_ms * 2);
}

//SYSIN DD DUMMY

Discussion

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: r3 - 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