Multi theremin-flute-sequencer prototype (project 1: blink)

Playing with LEDs and light sensors, I tought that could be nice to build a kind of flute, where instead of using fingers to close the holes to make diferent sounds, it could be posible to use fingers to let or not passing light over the sensor.

As you can see in the draw, we could use LEDs close to the holes, and we could put light sensor inside of the holes. That way we could use our fingers to play with the amount of light that we would let pass through.

Moreover, we could put some time sequence to LEDs, in order to add some rhythm to the instrument.

So as a result we could built a “mini-multi-theremin-flute-sequencer”.

Firs step:

First, we build the LEDs system to make them shine. We use a knob to change the velocity-rhythm-timesequencer of the LEDs.

Materials:
LEDs
1 knob
220 Ω resistor

First step code:

int potPin = 0; // select the input pin for the potentiometer
int ledsPin[] = {7, 6, 5, 4, 3}; // array to store pin numbers for several LEDs outputs
int ledsPinLength = 5; // variable to store the ledsPin array"s length
int valPot = 0; // variable to store the value coming from the pot

void setup() {
pinMode(potPin, INPUT); // declare the potPin as an INPUT
for(int i=0; i pinMode(ledsPin[i], OUTPUT); // declare the ledPin[] as an OUTPUT
}
}

void loop() {
for(int i=0; i valPot = analogRead(potPin); // read the value from the pot
digitalWrite(ledsPin[i], HIGH); // turn the ledPin on
delay(valPot); // stop the program for some time
digitalWrite(ledsPin[i], LOW); // turn the ledPin off
}
}

Second step:

Then we put some home-made buttons. We put this buttons because we wanted to switch on and off each one of the LEDs, in order to build serveral and diferents rhythms, like happens on a real music sequencer.

Materials:
Home-made buttons
10 KΩ resistors

First and second steps code:

 
int potPin = 0; // select the input pin for the potentiometer
int butonsPin[] = {12, 11, 10, 9, 8}; // array to store pin numbers for several butons inputs
int butonsVal[] = {0, 0, 0, 0, 0}; // array to store values coming from each one of the butons.
int ledsPin[] = {7, 6, 5, 4, 3}; // array to store pin numbers for several LEDs outputs
int ledsPinLength = 5; // variable to store the ledsPin array"s length
int valPot = 0; // variable to store the value coming from the pot

void setup() {
pinMode(potPin, INPUT); // declare the potPin as an INPUT

for(int i=0; i pinMode(ledsPin[i], OUTPUT); // declare the ledPin[] as an OUTPUT
pinMode(butonsPin[i], INPUT); // declare the lightsPin[] as an INPUT
}
}

void loop() {

for(int i=0; i butonsVal[i] = digitalRead(butonsPin[i]); // read the value of each one of the buttons.
valPot = analogRead(potPin); // read the value from the sensor

if(butonsVal[i] != HIGH){
digitalWrite(ledsPin[i], HIGH); // turn the ledPin on
delay(valPot); // stop the program for some time
digitalWrite(ledsPin[i], LOW); // turn the ledPin off
}else{
delay(valPot); // stop the program for some time
}

}

}

Last Step:

Finally, we added the light sensors.
The code bellow must be improved, because each time the program switch on a LED, it wait an amount of time (delay(valPot);) until it turns off theLED and turn on the next one. I would like to do something else during this period of time, but i can”t because the program is stoped.

Materials:
Light sensors
220 Ω – 1 KΩ resistors

PD: This prototype doesn”t have sound. We can just see the values that come from the light sensors through the serial terminal. I would like to send this values via midi or osc to another software like puredata, but I don”t know how yet.

All steps code:

 
int potPin = 0; // select the input pin for the potentiometer
int lightsPin[] = {1, 2, 3, 4, 5}; // array to store pin numbers for several Light sensors inputs.
int lightsVal[] = {0, 0, 0, 0, 0}; // array to store values coming from each one of the light sensors.
int butonsPin[] = {12, 11, 10, 9, 8}; // array to store pin numbers for several butons inputs.
int butonsVal[] = {0, 0, 0, 0, 0}; // array to store values coming from each one of the butons.
int ledsPin[] = {7, 6, 5, 4, 3}; // array to store pin numbers for several LEDs outputs
int ledsPinLength = 5; // variable to store the ledsPin array"s length
int valPot = 0; // variable to store the value coming from the pot

void setup() {
pinMode(potPin, INPUT); // declare the potPin as an INPUT

for(int i=0; i pinMode(ledsPin[i], OUTPUT); // declare the ledPin[] as an OUTPUT
pinMode(butonsPin[i], INPUT); // declare the lightsPin[] as an INPUT
}

Serial.begin(9600); // Setup serial.
}

void loop() {

for(int i=0; i butonsVal[i] = digitalRead(butonsPin[i]); // read the value of each one of the buttons.
valPot = analogRead(potPin); // read the value from the sensor
lightsVal[i] = analogRead(lightsPin[i]); // read the value of each one of the light sensors.

if(butonsVal[i] != HIGH){
digitalWrite(ledsPin[i], HIGH); // turn the ledPin on
Serial.print("light sensor number: ");
Serial.print(lightsPin[i]);
Serial.print(", value: ");
Serial.println(lightsVal[i]); // debug value of the light sensor
delay(valPot); // stop the program for some time
digitalWrite(ledsPin[i], LOW); // turn the ledPin off
}else{
delay(valPot); // stop the program for some time
}

}

}

Pictures of the last version:

TODO:
There is a problem with the code, because of the delay function. I would like to do something else while the sequencer is running, but the delay function stops the program and doesn”t allow me to do anything.
This code would be helpfull to fix the problem:
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay

Download code and pictures: