Skip to content

Instantly share code, notes, and snippets.

@spilth
Created October 20, 2014 02:24
Show Gist options
  • Save spilth/8b40c130d1bd857ee76f to your computer and use it in GitHub Desktop.
Save spilth/8b40c130d1bd857ee76f to your computer and use it in GitHub Desktop.
littleBits EasyJam w/Scale Selector
const int noteSelector = A0;
const int oscillator = 5;
const int scaleSelector = A1;
const int barGraph = 9;
int scaleA[] = {0, 2, 4, 5, 7, 9, 11, 12, 12 + 2, 12 + 4, 12 + 5, 12 + 7, 12 + 9, 12 + 11, 12 + 12};
int scaleB[] = {0, 2, 3, 5, 7, 8, 10, 12, 12 + 2, 12 + 3, 12 + 5, 12 + 7, 12 + 8, 12 + 10, 12 + 12};
int scaleC[] = {0, 2, 5, 7, 9, 12, 12 + 2, 12 + 5, 12 + 7, 12 + 9, 12 + 12};
int scaleD[] = {0, 3, 5, 6, 7, 10, 12, 12 + 3, 12 + 5, 12 + 6, 12 + 7, 12 + 10, 12 + 12};
int scaleE[] = {0, 1, 4, 5, 7, 8, 10, 12, 12 + 1, 12 + 4, 12 + 5, 12 + 7, 12 + 8, 12 + 10, 12 + 12};
int* scales[5];
int* scale;
unsigned int lengths[5];
int pitch;
int scaleIndex;
int scaleSize;
int scaleReading;
int scaleNumber;
int graphValue;
int noteReading;
void setup() {
scales[0] = scaleA;
scales[1] = scaleB;
scales[2] = scaleC;
scales[3] = scaleD;
scales[4] = scaleE;
lengths[0] = (sizeof(scaleA) / sizeof(int)) - 1;
lengths[1] = (sizeof(scaleB) / sizeof(int)) - 1;
lengths[2] = (sizeof(scaleC) / sizeof(int)) - 1;
lengths[3] = (sizeof(scaleD) / sizeof(int)) - 1;
lengths[4] = (sizeof(scaleE) / sizeof(int)) - 1;
pinMode(oscillator, OUTPUT);
pinMode(barGraph, OUTPUT);
Serial.begin(9600);
}
void loop() {
scaleReading = analogRead(scaleSelector);
scaleNumber = map(scaleReading, 7, 1016, 0, 4);
scale = scales[scaleNumber];
scaleSize = lengths[scaleNumber];
noteReading = analogRead(noteSelector);
scaleIndex = map(noteReading, 7, 1016, 0, scaleSize);
graphValue = (scaleNumber + 1) * 50;
analogWrite(barGraph, graphValue);
pitch = (scale[scaleIndex] * 4) + 12;
analogWrite(oscillator, pitch);
delay(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment