Adding a temporary note to a melody array

Hey!

My team and I are trying to create an action that adds a temporary note to a melody array and lights an LED when a photo resister is fully covered. We are able to cause the melody to play while the photo resistor is lighting the LED, but we are unable to add a temporary note, mind helping?

#define NOTE_B0 31
#define NOTE_D5 587
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_G5 784
#define NOTE_A5 880
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_DS6 1245

int melody[] = {NOTE_B0, NOTE_D5, NOTE_E5, NOTE_F5, NOTE_G5, NOTE_A5, NOTE_B5, NOTE_C6};
int note = NOTE_DS6; //this is the temporary note
int light = 0;
int duration = 1000;
int counter = 0;
int buzzerPin = 8;
int photoResistor = A4;
int ledPin = 12;
int exNote = NOTE_DS6;



void setup()
{   
  Serial.begin (9600);
  pinMode(ledPin,OUTPUT);
  pinMode(buzzerPin, OUTPUT);
  pinMode(photoResistor, OUTPUT);
  }
  
void loop() {
  light = analogRead(A4);
  Serial.println(light);
  
  if(light < 10){
    digitalWrite(12,LOW);
    
  /*for (int i = 256; i > 0; i--){     analogWrite(A4,i);   }*/
  } 
  
  else {
      digitalWrite(12,HIGH);
      tone (8, note, duration); 
      //for (int i = 0; i < 256; i++){   
      //  analogWrite(A4,i);
      }
      
  for (int i = 0; i < 8 ; i++) {
   tone (8, melody[counter], duration);
    }
    counter = counter+1;
   if (counter > 7){
    counter = 0;
  }
   
 delay (500);
}

Please explain your problem. Write step by step explanations in your code what you hope your code does. That will save us time. We can't figure out from your code what you think it should do, especially if the code is wrong.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.