Show Posts
|
|
Pages: [1]
|
|
2
|
Using Arduino / Project Guidance / Re: Arduino Keyboard
|
on: August 01, 2012, 03:57:46 pm
|
I have another sketch that's a dual sequencer. Same inputs and tempo control, but this time I don't have chords. Here's the code: #include <digitalWriteFast.h> #include <Tone.h>
int Tempo; int noteFreq[] = { 28, 29, 31, //A0-B0 33, 35, 37, 39, 41, 44, 46, 49, 52, 55, 58, 62, //C1-B1 65, 69, 73, 78, 82, 87, 93, 98, 104, 110, 117, 123, //C2-B2 131, 139, 147, 156, 165, 175, 185, 196, 208, 220, 233, 247, //C3-B3 262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 493, //C4-B4 523, 554, 587, 622, 659, 698, 740, 784, 831, 880, 932, 988, //C5-B5 1047, 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, 1864, 1976, //C6-B6 2093, 2217, 2349, 2489, 2637, 2794, 2960, 3136, 3322, 3520, 3729, 3951, //C7-B7 4186, 4435, 4699, 4978, 5274, 5588, 5920, 6272, 6645, 7040, 7459, 7902, //C8-B8 8372, 8870, 9397, 9956, 10548, 11175, 11840, 12544, 13229, 14080, 14917, 15804, //C9-B9 16744}; //C10 int loopDeLoop[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; int loopDeTwo[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; int Octave; int Chord; int i = 0;
Tone tone1; Tone tone2;
void setup(){ pinMode(22, INPUT); pinMode(23, INPUT); pinMode(24, INPUT); pinMode(25, INPUT); pinMode(26, INPUT); pinMode(27, INPUT); pinMode(28, INPUT); pinMode(29, INPUT); pinMode(30, INPUT); pinMode(31, INPUT); pinMode(32, INPUT); pinMode(33, INPUT); pinMode(34, INPUT); pinMode(35, INPUT); pinMode(36, INPUT); pinMode(37, INPUT);
pinMode(7, INPUT); pinMode(6, INPUT); Serial.begin(115200); tone1.begin(13); tone2.begin(12); }
void loop(){ if (i == 16) i = 0; Tempo = ((analogRead(A0)*25)/48) + 40; Octave = (analogRead(A1))/128; Chord = (analogRead(A2))/128; if (digitalReadFast(7) == HIGH) { if (digitalReadFast(22) == HIGH) { loopDeLoop[i] = 0 + (Octave*12); } if (digitalReadFast(23) == HIGH) { loopDeLoop[i] = 1 + (Octave*12); } if (digitalReadFast(24) == HIGH) { loopDeLoop[i] = 2 + (Octave*12); } if (digitalReadFast(25) == HIGH) { loopDeLoop[i] = 3 + (Octave*12); } if (digitalReadFast(26) == HIGH) { loopDeLoop[i] = 4 + (Octave*12); } if (digitalReadFast(27) == HIGH) { loopDeLoop[i] = 5 + (Octave*12); } if (digitalReadFast(28) == HIGH) { loopDeLoop[i] = 6 + (Octave*12); } if (digitalReadFast(29) == HIGH) { loopDeLoop[i] = 7 + (Octave*12); } if (digitalReadFast(30) == HIGH) { loopDeLoop[i] = 8 + (Octave*12); } if (digitalReadFast(31) == HIGH) { loopDeLoop[i] = 9 + (Octave*12); } if (digitalReadFast(32) == HIGH) { loopDeLoop[i] = 10 + (Octave*12); } if (digitalReadFast(33) == HIGH) { loopDeLoop[i] = 11 + (Octave*12); } if (digitalReadFast(34) == HIGH) { loopDeLoop[i] = 12 + (Octave*12); } if (digitalReadFast(35) == HIGH) { loopDeLoop[i] = 13 + (Octave*12); } if (digitalReadFast(36) == HIGH) { loopDeLoop[i] = 14 + (Octave*12); } if (digitalReadFast(37) == HIGH) { loopDeLoop[i] = 15 + (Octave*12); } } if (digitalReadFast(6) == HIGH) { if (digitalReadFast(22) == HIGH) { loopDeTwo[i] = 0 + (Octave*12); } if (digitalReadFast(23) == HIGH) { loopDeTwo[i] = 1 + (Octave*12); } if (digitalReadFast(24) == HIGH) { loopDeTwo[i] = 2 + (Octave*12); } if (digitalReadFast(25) == HIGH) { loopDeTwo[i] = 3 + (Octave*12); } if (digitalReadFast(26) == HIGH) { loopDeTwo[i] = 4 + (Octave*12); } if (digitalReadFast(27) == HIGH) { loopDeTwo[i] = 5 + (Octave*12); } if (digitalReadFast(28) == HIGH) { loopDeTwo[i] = 6 + (Octave*12); } if (digitalReadFast(29) == HIGH) { loopDeTwo[i] = 7 + (Octave*12); } if (digitalReadFast(30) == HIGH) { loopDeTwo[i] = 8 + (Octave*12); } if (digitalReadFast(31) == HIGH) { loopDeTwo[i] = 9 + (Octave*12); } if (digitalReadFast(32) == HIGH) { loopDeTwo[i] = 10 + (Octave*12); } if (digitalReadFast(33) == HIGH) { loopDeTwo[i] = 11 + (Octave*12); } if (digitalReadFast(34) == HIGH) { loopDeTwo[i] = 12 + (Octave*12); } if (digitalReadFast(35) == HIGH) { loopDeTwo[i] = 13 + (Octave*12); } if (digitalReadFast(36) == HIGH) { loopDeTwo[i] = 14 + (Octave*12); } if (digitalReadFast(37) == HIGH) { loopDeTwo[i] = 15 + (Octave*12); } } if (loopDeLoop[i] >= 0) tone1.play(noteFreq[loopDeLoop[i]], Tempo); if (loopDeTwo[i] >= 0) tone2.play(noteFreq[loopDeTwo[i]], Tempo); delay(Tempo-5); //Serial.println(Octave); i++; Serial.println(i); Serial.print(loopDeLoop[i]); }
Eventually, I want to add the chords to my sequencer then merge both sketches so that I have an audio sequence in the background while I play realtime; but I don't know how to do it. Does anyone know how to put these two sketches together? Other than that, what should I add on my project? Any suggestion is appreciated! Thanks, TheKid
|
|
|
|
|
3
|
Using Arduino / Project Guidance / Arduino Keyboard
|
on: August 01, 2012, 03:57:21 pm
|
I built this keyboard for Arduino with the tone library. The controls are one octave plus A, A#, and B at the bottom and a 10k pot to change octaves. It can play single tones, a few chords, and a noise mode. I can also change the speed of chords and change between I, IV, V, i, iv, and vi chords. So here's my code: #include <digitalWriteFast.h> #include <Tone.h>
int Tempo; int noteFreq[] = { 28, 29, 31, //A0-B0 33, 35, 37, 39, 41, 44, 46, 49, 52, 55, 58, 62, //C1-B1 65, 69, 73, 78, 82, 87, 93, 98, 104, 110, 117, 123, //C2-B2 131, 139, 147, 156, 165, 175, 185, 196, 208, 220, 233, 247, //C3-B3 262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 493, //C4-B4 523, 554, 587, 622, 659, 698, 740, 784, 831, 880, 932, 988, //C5-B5 1047, 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, 1864, 1976, //C6-B6 2093, 2217, 2349, 2489, 2637, 2794, 2960, 3136, 3322, 3520, 3729, 3951, //C7-B7 4186, 4435, 4699, 4978, 5274, 5588, 5920, 6272, 6645, 7040, 7459, 7902, //C8-B8 8372, 8870, 9397, 9956, 10548, 11175, 11840, 12544, 13229, 14080, 14917, 15804, //C9-B9 16744}; //C10 int Octave; int Chord;
Tone tone1;
void setup(){ pinMode(22, INPUT); pinMode(23, INPUT); pinMode(24, INPUT); pinMode(25, INPUT); pinMode(26, INPUT); pinMode(27, INPUT); pinMode(28, INPUT); pinMode(29, INPUT); pinMode(30, INPUT); pinMode(31, INPUT); pinMode(32, INPUT); pinMode(33, INPUT); pinMode(34, INPUT); pinMode(35, INPUT); pinMode(36, INPUT); pinMode(37, INPUT); Serial.begin(115200); tone1.begin(13); }
void loop(){ Tempo = ((analogRead(A0)*25)/48) + 40; Octave = (analogRead(A1))/128; Chord = (analogRead(A2))/128; if (digitalReadFast(22) == HIGH) { playTone(0); } if (digitalReadFast(23) == HIGH) { playTone(1); } if (digitalReadFast(24) == HIGH) { playTone(2); } if (digitalReadFast(25) == HIGH) { playTone(3); } if (digitalReadFast(26) == HIGH) { playTone(4); } if (digitalReadFast(27) == HIGH) { playTone(5); } if (digitalReadFast(28) == HIGH) { playTone(6); } if (digitalReadFast(29) == HIGH) { playTone(7); } if (digitalReadFast(30) == HIGH) { playTone(8); } if (digitalReadFast(31) == HIGH) { playTone(9); } if (digitalReadFast(32) == HIGH) { playTone(10); } if (digitalReadFast(33) == HIGH) { playTone(11); } if (digitalReadFast(34) == HIGH) { playTone(12); } if (digitalReadFast(35) == HIGH) { playTone(13); } if (digitalReadFast(36) == HIGH) { playTone(14); } if (digitalReadFast(37) == HIGH) { playTone(15); } Serial.println(Octave); }
void playTone (int note) { switch (Chord) { case 0: tone1.play(noteFreq[note + (Octave*12)], 40); delay(30); break; case 1: tone1.play(noteFreq[note + (Octave*12) + 12], Tempo/4); delay(Tempo/4); tone1.play(noteFreq[note + (Octave*12) + 7], Tempo/4); delay(Tempo/4); tone1.play(noteFreq[note + (Octave*12) + 4], Tempo/4); delay(Tempo/4); tone1.play(noteFreq[note + (Octave*12)], Tempo/4); delay(Tempo/4); break; case 2: tone1.play(noteFreq[note + (Octave*12) + 12], Tempo/4); delay(Tempo/4); tone1.play(noteFreq[note + (Octave*12) + 9], Tempo/4); delay(Tempo/4); tone1.play(noteFreq[note + (Octave*12) + 5], Tempo/4); delay(Tempo/4); tone1.play(noteFreq[note + (Octave*12)], Tempo/4); delay(Tempo/4); break; case 3: tone1.play(noteFreq[note + (Octave*12) + 11], Tempo/4); delay(Tempo/4); tone1.play(noteFreq[note + (Octave*12) + 7], Tempo/4); delay(Tempo/4); tone1.play(noteFreq[note + (Octave*12) + 2], Tempo/2); delay(Tempo/2); break; case 4: tone1.play(noteFreq[note + (Octave*12) + 12], Tempo/4); delay(Tempo/4); tone1.play(noteFreq[note + (Octave*12) + 7], Tempo/4); delay(Tempo/4); tone1.play(noteFreq[note + (Octave*12) + 3], Tempo/4); delay(Tempo/4); tone1.play(noteFreq[note + (Octave*12)], Tempo/4); delay(Tempo/4); break; case 5: tone1.play(noteFreq[note + (Octave*12) + 12], Tempo/4); delay(Tempo/4); tone1.play(noteFreq[note + (Octave*12) + 8], Tempo/4); delay(Tempo/4); tone1.play(noteFreq[note + (Octave*12) + 5], Tempo/4); delay(Tempo/4); tone1.play(noteFreq[note + (Octave*12)], Tempo/4); delay(Tempo/4); break; case 6: tone1.play(noteFreq[note + (Octave*12) + 12], Tempo/4); delay(Tempo/4); tone1.play(noteFreq[note + (Octave*12) + 9], Tempo/4); delay(Tempo/4); tone1.play(noteFreq[note + (Octave*12) + 4], Tempo/4); delay(Tempo/4); tone1.play(noteFreq[note + (Octave*12)], Tempo/4); delay(Tempo/4); break; case 7: tone1.play(noteFreq[note + (Octave*12) + 12], 5); delay(5); tone1.play(noteFreq[note + (Octave*12) + 7], 5); delay(5); tone1.play(noteFreq[note + (Octave*12) + 4], 5); delay(5); tone1.play(noteFreq[note + (Octave*12)], 5); delay(5); break; } }
Any suggestions?
|
|
|
|
|
4
|
Using Arduino / Displays / Re: 2.8" TFT Touch Shield
|
on: August 03, 2011, 05:26:49 pm
|
|
I know what you mean. Actually that just means that one of your shapes' edges are out of bounds. Try displaying your shapes inside the screen borders.
|
|
|
|
|