Skip to content

Instantly share code, notes, and snippets.

@Kobold
Created October 14, 2010 20:14
Show Gist options
  • Save Kobold/626954 to your computer and use it in GitHub Desktop.
Save Kobold/626954 to your computer and use it in GitHub Desktop.
int potpin = 0;
int speakerPin = 9;
int redPin = 10;
int bluePin = 12;
int high = 0, low = 500;
void setup()
{
pinMode(speakerPin, OUTPUT);
}
void loop()
{
int val = analogRead(potpin);
high = max(high, val);
low = min(low, val);
analogWrite(redPin, map(val, low, high, 0, 255));
analogWrite(bluePin, map(val, low, high, 255, 0));
int tone = map(val, low, high, 1915, 956);
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tone);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment