Skip to content

Instantly share code, notes, and snippets.

@campaul
Created July 25, 2014 06:22
Show Gist options
  • Save campaul/14c56e1b7791bb13e18f to your computer and use it in GitHub Desktop.
Save campaul/14c56e1b7791bb13e18f to your computer and use it in GitHub Desktop.
Blind attempt at controlling the frequency of a 555 timer
int pin = 0; // The pin we will read the audio signal from
volatile int last = 0; // The time of the last sample
volatile int expected = 2272; // Roughly 440Hz
volatile int data = 0; // The direction to change the digi-pot
void setup() {
pinMode(pin, INPUT);
last = micros();
attachInterrupt(0, adjust, FALLING);
}
void loop() {
// TODO: On midi input change the expected time
}
void adjust() {
int elapsed = micros() - last;
last += elapsed;
if (elapsed > expected) {
data = 1;
} else {
data = 0;
}
// TODO: Clock the digi-pot
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment