Hello Arduino forum,
I've had the Uno development board since December and I've been doing some prototyping with it.
Now, I feel like I should make something useful out of it.. I've narrowed down my choices to a few projects and have some questions regarding programming (and the hardware too)
First of all I have in mind this nifty "bassline" program that uses potentiometers (or faders) to cycle through pins to read values and print them as tone (it's 4 step as the I/O and the breadboard space is very limited)
void setup() {
Serial.begin(9600);
}
void loop() {
int tempo = 500 ;
int noteLength = 200 ;
int step1 = analogRead(A0) / 4 ;
int step2 = analogRead(A1) / 4 ;
int step3 = analogRead(A2) / 4 ;
int step4 = 100 ;
Serial.println(step1) ;
Serial.println(step2) ;
Serial.println(step3) ;
tone(8, step1, noteLength);
delay(tempo);
tone(8, step2, noteLength);
delay(tempo);
tone(8, step3, noteLength);
delay(tempo);
tone(8, step4, noteLength);
delay(tempo);
}
It could be further extended with tempo, play/pause, note length, filters etc whatnot. (edit : note that I only had 3 pots to work with..I also simplified the code by removing digitalWrite bits for LEDs) The problem here is the I/O because the Uno has 6 analog ins and for 8 steps you'd need 8 or more. I've read about GPIO shields which could come handy here.
Other than that it's very funky, analogue-y in the sense that you'll almost never get the notes in tune. (edit : tbh it's just downright atonal but I liked it for some reason)
Here's another sketch :
void setup() {
Serial.begin(9600) ;
}
void loop() {
int tempo = 1000 ;
int noteLength = 100 ;
int notes[5] = {262,294,330,349,0} ;
int seq[4] ;
int keyVal = analogRead(A0) ;
int stepVal = analogRead(A1) ;
Serial.println(keyVal) ;
Serial.println(stepVal) ;
if (stepVal == 1023 && keyVal == 1023){
seq[0] = notes[0] ;
}
else if (stepVal >= 990 && stepVal <=1010 && keyVal >= 990 && keyVal <= 1010){
seq[0] = notes[1] ;
}
else if (stepVal >= 505 && stepVal <= 515 && keyVal >= 505 && keyVal <= 515){
seq[0] = notes[2] ;
}
else if (stepVal >= 5 && stepVal <=10 && keyVal >= 5 && keyVal <= 10){
seq[0] = notes[3] ;
}
else if (stepVal == 1023){
seq[0] = notes[5] ;
}
if (stepVal == 1023 && keyVal == 1023){
seq[1] = notes[0] ;
}
else if (stepVal >= 990 && stepVal <=1010 && keyVal >= 990 && keyVal <= 1010){
seq[1] = notes[1] ;
}
else if (stepVal >= 505 && stepVal <= 515 && keyVal >= 505 && keyVal <= 515){
seq[1] = notes[2] ;
}
else if (stepVal >= 5 && stepVal <=10 && keyVal >= 5 && keyVal <= 10){
seq[1] = notes[3] ;
}
else if (stepVal == 1023){
seq[1] = notes[5] ;
}
if (stepVal == 1023 && keyVal == 1023){
seq[2] = notes[0] ;
}
else if (stepVal >= 990 && stepVal <=1010 && keyVal >= 990 && keyVal <= 1010){
seq[2] = notes[1] ;
}
else if (stepVal >= 505 && stepVal <= 515 && keyVal >= 505 && keyVal <= 515){
seq[2] = notes[2] ;
}
else if (stepVal >= 5 && stepVal <=10 && keyVal >= 5 && keyVal <= 10){
seq[2] = notes[3] ;
}
else if (stepVal == 1023){
seq[2] = notes[5] ;
}
if (stepVal == 1023 && keyVal == 1023){
seq[3] = notes[0] ;
}
else if (stepVal >= 990 && stepVal <=1010 && keyVal >= 990 && keyVal <= 1010){
seq[3] = notes[1] ;
}
else if (stepVal >= 505 && stepVal <= 515 && keyVal >= 505 && keyVal <= 515){
seq[3] = notes[2] ;
}
else if (stepVal >= 5 && stepVal <=10 && keyVal >= 5 && keyVal <= 10){
seq[3] = notes[3] ;
}
else if (stepVal == 1023){
seq[3] = notes[5] ;
}
else{
tone(8, seq[0], noteLength) ;
delay(tempo) ;
tone(8, seq[1], noteLength) ;
delay(tempo) ;
tone(8, seq[2], noteLength) ;
delay(tempo) ;
tone(8, seq[3], noteLength) ;
delay(tempo) ;
}
}
This one is a bit different animal. Basically it uses two 220ohm/10kOhm/1MOhm resistor ladders with buttons; one to create the incoming voltage (=note) and fetch the correct frequency from the "notes" array and the other to select a pattern step. The note is then stored to the "seq" array when they're both pressed simultaneously but for me it didn't work.. (edit : I also tested it with the steps using digital pins, the problem is the I/O because one would need 8+8 for LEDs and steps so there'd be no space for play/pause and output)
I've been thinking whether the "seq" array should be under the "setup" program should the loop overwrite it, one solution could be to use EEPROM.write and address the values there. I assume the data byte is written in the SRAM so I'd have to divide the incoming values by 4 (because 255 is the maximum value for 8-bit) which means I'd have to either rewrite the "if" parts (there could also be a problem with the voltage values as I'd be narrowing the resolution) or use another array/lookup-table so I'd be writing only note values (1, 2, n..)
Another idea was a drum machine which basically works in the same manner but instead I'd define separate arrays for different sounds (kick, snare etc) and use 4th's, 8th's and 16th's for the sequence.
Anyway, what's your take on this?
Thanks in advance,
-ef