Program stops working over time.


i have rather simple program photo cells used trigger midi notes when light drops under threshold - person blocking light.
in order compensate differences of ambient light added pots set threshold @ specific location(different rooms). have dedicated strong light source setup.
something not quit right - program stops reacting after time(ambient light change?). works - after time or change of ambient light either triggers notes time without human interaction or not thing - regardless of tweaking threshold pots..
could check out?

code: [select]
#include <midi.h>
byte note = 0;
byte b = 3;  //-b slight change not affect
byte c = 1;

int val1pin = 0;  //analog pin 0-3 photocell
int val2pin = 1;
int val3pin = 2;
int val4pin = 3;
int val1;        //photocell reads
int val2;
int val3;
int val4;

int val5pin = 8;  //analog pin 8-11 pot treshold
int val6pin = 9;
int val7pin = 10;
int val8pin = 11;

int a1 = 0;        // a1-a5 treshold adjustable pot
int a2 = 0;
int a3 = 0;
int a4 = 0;





 
 
void setup() {

  serial.begin(31250);   // set midi baud rate
  midi.sendprogramchange (121,c);  // set midi instrument
 
 
}

void loop() {
 
  val1 = analogread(val1pin);
    a1 = analogread(val5pin);
  if (val1 <= a1-b) {          //if val under threshold play notes
  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(70,0,c);
midi.sendnoteoff(73,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 (val4 <= a4-b) {
  midi.sendnoteon(44,127,c);
  delay(300);
  midi.sendnoteon(51,127,c);
  delay(300);
  midi.sendnoteon(49,127,c);
  delay(100);
 midi.sendnoteoff(44,0,c);
midi.sendnoteoff(51,0,c);
midi.sendnoteoff(49,0,c);
      }
       
  }

well ambient light change in room depending on time of day , comparing fixed potentiometer threshold - conditions change need adjust pots continuously. (or have no window , control lighting yourself?)

also - using "photo cells" real solar cell (photovoltaic cell)? photovoltaic cells known vary output depending on heat of cell -> when solar cell heated, becomes less efficient. solar panel not change , work when warm, measure can have impact. worth checking.
 
side note:

you not initializing midi instance (midi_create_default_instance) etc. i'm not expert library , know if know can work - sure set right way?

also instead of using

  if (val1 <= a1-b) {          //if val under threshold play notes


you might want to map val1 , a1 similar space offset effects @ low and  high end of range. reading analog pins (assuming mega) might not precise if don't have clean voltage reference.


Arduino Forum > Using Arduino > Programming Questions > Program stops working over time.


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'