Skip to content

Instantly share code, notes, and snippets.

@moonmilk
Created February 12, 2015 04:41
Show Gist options
  • Save moonmilk/4b665daab2e4f1965128 to your computer and use it in GitHub Desktop.
Save moonmilk/4b665daab2e4f1965128 to your computer and use it in GitHub Desktop.
instrument-a-day 2015, day 11: cacophony organ.
/* jeltone-style synth for arduino mega with a heap of LEDs crammed into the expansion port
* output 16 tones in accordion bass button layout for some reason
* See video at moonmilk.com or flickr.com/ranjit
*/
const int num = 16;
int increment = 15;
int pins[] = {52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22};
// divisors for just intonation scale on 2, 3, and 5 <http://en.wikipedia.org/wiki/Just_intonation#The_twelve_tone_scale>
// C G D A E B F# C#
int tones[] ={2880,3600,1920,2400,1280,1620,866,1080, 576,720, 384,480, 253, 320, 337, 216};
// Ab Eb Bb F C G D A
int counters[num];
int states[num];
int analogSkip = 0;
void setup() {
int i;
for (i=0; i<num; i++) {
pinMode(pins[i], OUTPUT);
counters[i] = 0;
states[i] = 0;
// set the cheat sinks (each led has its cathode plugged into the next pin up)
pinMode(pins[i]+1, OUTPUT);
digitalWrite(pins[i]+1, 0);
}
}
void loop() {
int i, j;
int t;
for (i=0; i<num; i++) {
if ((counters[i]+=increment) > tones[i]) {
counters[i] -= tones[i];
states[i] = !states[i];
digitalWrite(pins[i], states[i]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment