Making the same code work for more sensors.
hi there, wrote code make single light dependant resistor activate led light , send midi messages laptop:
the code working grate single sensor, tried make multisensor code, not working...what did wrong?
here's fau;ty code:
thank much!
davide
code: [select]
int lightpin =0;
int ledpin =9;
int treshold = 400;
int lightlevel = 0;
void setup()
{
pinmode(ledpin, output);
serial.begin(9600);
}
void loop()
{
int lightlevel = analogread(lightpin);
serial.println(lightlevel);
if (lightlevel >= treshold){
switchled();
delay(500);
}
}
void switchled(){
if (digitalread(ledpin) == high){
do {
digitalwrite(ledpin,low);
midi_tx(144,60,127);
delay(100);
midi_tx(128,60,127);
delay(100);
}
while(analogread(lightpin) > treshold);
}
else if (digitalread(ledpin) == low){
do {
digitalwrite(ledpin,high);
midi_tx(144,61,127);
delay(100);
midi_tx(128,61,127);
delay(100);
}
while(analogread(lightpin) > treshold);
}
}
// code midi
void midi_tx(unsigned char message, unsigned char pitch, unsigned char velocity)
{
serial.print(message);
serial.print(pitch);
serial.print(velocity);
}
the code working grate single sensor, tried make multisensor code, not working...what did wrong?
here's fau;ty code:
code: [select]
int lightpin =0;
int ledpin =9;
int treshold = 400;
int lightlevel = 0;
void setup()
{
pinmode(ledpin, output);
serial.begin(9600);
}
void loop()
{
int lightlevel = analogread(lightpin);
serial.println(lightlevel);
if (lightlevel >= treshold){
switchled();
delay(500);
}
}
void switchled(){
if (digitalread(ledpin) == high){
do {
digitalwrite(ledpin,low);
midi_tx(144,60,127);
delay(100);
midi_tx(128,60,127);
delay(100);
}
while(analogread(lightpin) > treshold);
}
else if (digitalread(ledpin) == low){
do {
digitalwrite(ledpin,high);
midi_tx(144,61,127);
delay(100);
midi_tx(128,61,127);
delay(100);
}
while(analogread(lightpin) > treshold);
}
}
// code midi
void midi_tx(unsigned char message, unsigned char pitch, unsigned char velocity)
{
serial.print(message);
serial.print(pitch);
serial.print(velocity);
}
thank much!
davide
the code in both blocks looks same me. did miss something?
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Making the same code work for more sensors.
arduino
Comments
Post a Comment