I am fixing an old installation for the show. It has 4 photocells grounded with 10k resistors. When the light to the cell falls below threshold a sequence of MIDI notes will be triggered.
It works OK when there is plenty of light, but gets hard to control with limited light. I think I need to increase sensitivity range of the cells with tweaking 10K resistors. But before I go for hard work of disassembling the thing I would like to know if this improve the situation much and if so witch way I should change the resistor values.
Here is the code compiled with Arduino App 0023
I use a value(byte b) to prevent slight light change to trigger the cell, but I am not sure if this makes sense or if there is a better way to do this
#include <MIDI.h>
byte note = 0;
byte b = 33; //-b that slight change will not affect
byte c = 5; // Midi Channel
byte a = 3; //+Midi Channel
int valPin = 0; //analog pin 0-4 sensor(photocell)
int val2Pin = 1;
int val3Pin = 2;
int val4Pin = 3;
int val;
int val2;
int val3;
int val4;
int val5Pin = 4; //analog pin 4-7 pot for threshold adjustment
int val6Pin = 5;
int val7Pin = 6;
int val8Pin = 7;
int a1 = 0; // a1-a5 treshold adjustable with pot
int a2 = 0;
int a3 = 0;
int a4 = 0;
void setup() {
Serial.begin(31250);
}
void loop() {
val = analogRead(valPin);
a1 = analogRead(val5Pin);
if (val <= a1-b) {
MIDI.sendNoteOn(54,127,c);
delay(300);
MIDI.sendNoteOn(58,127,c);
delay(300);
MIDI.sendNoteOn(66,127,c);
delay(100);
MIDI.sendNoteOff(54,0,c);
MIDI.sendNoteOff(58,0,c);
MIDI.sendNoteOff(66,0,c);
}
val2 = analogRead(val2Pin);
a2 = analogRead(val6Pin);
if (val2 <= a2-b) {
MIDI.sendNoteOn(68,127,c);
delay(100);
MIDI.sendNoteOn(70,127,c);
delay(100);
MIDI.sendNoteOn(73,127,c);
delay(100);
MIDI.sendNoteOn(75,127,c);
delay(100);
MIDI.sendNoteOff(68,0,c);
MIDI.sendNoteOff(73,0,c);
MIDI.sendNoteOff(70,0,c);
MIDI.sendNoteOff(75,0,c);
}
val3 = analogRead(val3Pin);
a3 = analogRead(val7Pin);
if (val3 <= a3-b) {
MIDI.sendNoteOn(60,127,c);
delay(200);
MIDI.sendNoteOn(70,127,c);
delay(100);
MIDI.sendNoteOn(68,127,c);
delay(100);
MIDI.sendNoteOn(51,127,c);
delay(300);
MIDI.sendNoteOn(60,127,c);
delay(100);
MIDI.sendNoteOff(60,0,c);
MIDI.sendNoteOff(70,0,c);
MIDI.sendNoteOff(68,0,c);
MIDI.sendNoteOff(51,0,c);
MIDI.sendNoteOff(60,0,c);
}
val4 = analogRead(val4Pin);
a4 = analogRead(val8Pin);
if (val <= a4-b) {
MIDI.sendNoteOn(60,127,c+a);
delay(300);
MIDI.sendNoteOn(61,127,c+a);
delay(300);
MIDI.sendNoteOn(62,127,c+a);
delay(600);
MIDI.sendNoteOff(60,0,c+a);
MIDI.sendNoteOff(61,0,c+a);
MIDI.sendNoteOff(62,0,c+a);
}
}