samedi 30 novembre 2019

For loop stops at first iteration [Arduino]

My code stops at the first iteration for the phot_val "for" statement.

void loop() {
  double sound = MIC();                            //Declare variable for obtaining microphone data
  double phot_val;
  int nreadings = 100;
  int song1[N]={CN4, DN4, EN4, FN4, GN4, AN4, BN4, CN5};
  int song2[M]= {RT0, RT0, CN4, DN4, CN4, FN4, EN4, RT0,CN4, DN4, CN4, GN4, FN4, RT0, CN4, CN5, AN4, FN4, EN4,DN4, RT0, AS4, AN4, FN4, GN4, FN4, RT0, RT0};
  phot_val = read_analogn(2,nreadings);
Serial.print("Sound: ");Serial.println(sound);    //Testing purposes, Print out sound/mic value
Serial.print("Light: ");Serial.println(phot_val,5);//Testing purposes, Print out light sensor data

  if(phot_val >= .5){play_song(song1,N);} //Stops after first 100???

/// Else If statements to change RBG colors depending on sound 
 if(MIC() >= 30){ setColor(255, 0, 0); }                        //Red Color
 else if(MIC() >= 35){setColor(0, 255, 0);}                     //Green Color
  else if(MIC() >= 40){setColor(0, 0 , 255);}                   //Blue Color
    else if(MIC() >=25){setColor(255, 255, 255);}               //White Color
      else if(MIC() >=25){setColor(170, 0, 255);}               //White Color
 else {setColor(0, 0, 0);}

}

I can post more code if needed, but I have no Idea why it stops

Aucun commentaire:

Enregistrer un commentaire