Project not working.

basically, i have this project that produces sound when an LDR is covered and a piezo is hit. we have everything up but its just looping the same set of notes. any help would be good.

// audio and interactivity project

int abuttonPin = 1;
int bbuttonPin = 2;
int cbuttonPin = 3;
int dbuttonPin = 4;
int ebuttonPin = 5;
int fbuttonPin = 6;
int piezoPin = 8;
int footswitch = 9;

#include "pitches.h"

const int threshold = 5;

int notes[] = {
  NOTE_A4, NOTE_AS4, NOTE_B4, NOTE_C5, NOTE_CS5, NOTE_D5, NOTE_DS5, NOTE_E5, NOTE_F5, NOTE_FS5, NOTE_G5, NOTE_GS5,
}

;void setup () {
  pinMode(abuttonPin, INPUT);
  pinMode(bbuttonPin, INPUT);
  pinMode(cbuttonPin, INPUT);
  pinMode(dbuttonPin, INPUT);
  pinMode(ebuttonPin, INPUT);
  pinMode(fbuttonPin, INPUT);
  pinMode(piezoPin, INPUT);
  pinMode(footswitch, INPUT);
  Serial.begin (31250);
  
}

void loop() {
  int digitalRead(piezoPin);
  if (footswitch = LOW) int notes (NOTE_A4 > NOTE_D5);
  
   for (int abuttonPin = 0; abuttonPin < 3; abuttonPin++) {
    // get a sensor reading:
    int abuttonPinReading = analogRead(abuttonPin);
    // if the sensor is pressed hard enough:
    if (abuttonPinReading > threshold) {
      // play the note corresponding to this sensor:
      tone(8, notes[abuttonPin], 20);}
      
    for (int bbuttonPin = 0; bbuttonPin < 3; bbuttonPin++) {
    int bbuttonPinReading = analogRead(bbuttonPin);
    if (bbuttonPinReading > threshold) {
    tone(8, notes[bbuttonPin], 20);}
      
      for (int cbuttonPin = 0; cbuttonPin < 3; cbuttonPin++) {
    // get a sensor reading:
    int cbuttonPinReading = analogRead(cbuttonPin);
    // if the sensor is pressed hard enough:
    if (cbuttonPinReading > threshold) {
      // play the note corresponding to this sensor:
      tone(8, notes[cbuttonPin], 20);}
      
      for (int dbuttonPin = 0; dbuttonPin < 3; dbuttonPin++) {
    // get a sensor reading:
    int dbuttonPinReading = analogRead(dbuttonPin);
    // if the sensor is pressed hard enough:
    if (dbuttonPinReading > threshold) {
      // play the note corresponding to this sensor:
      tone(8, notes[dbuttonPin], 20);}
      
      for (int ebuttonPin = 0; ebuttonPin < 3; ebuttonPin++) {
    // get a sensor reading:
    int ebuttonPinReading = analogRead(ebuttonPin);
    // if the sensor is pressed hard enough:
    if (ebuttonPinReading > threshold) {
      // play the note corresponding to this sensor:
      tone(8, notes[ebuttonPin], 20);}
      
      for (int fbuttonPin = 0; fbuttonPin < 3; fbuttonPin++) {
    // get a sensor reading:
    int fbuttonPinReading = analogRead(fbuttonPin);
    // if the sensor is pressed hard enough:
    if (fbuttonPinReading > threshold) {
      // play the note corresponding to this sensor:
      tone(8, notes[fbuttonPin], 20);}
   }
  if (footswitch = HIGH) int notes (NOTE_DS5 > NOTE_GS5);
  
 for (int abuttonPin = 0; abuttonPin < 3; abuttonPin++) {
    // get a sensor reading:
    int abuttonPinReading = analogRead(abuttonPin);
    // if the sensor is pressed hard enough:
    if (abuttonPinReading > threshold) {
      // play the note corresponding to this sensor:
      tone(8, notes[abuttonPin], 20);}
      
      for (int bbuttonPin = 0; bbuttonPin < 3; bbuttonPin++) {
    // get a sensor reading:
    int bbuttonPinReading = analogRead(bbuttonPin);
    // if the sensor is pressed hard enough:
    if (bbuttonPinReading > threshold) {
      // play the note corresponding to this sensor:
      tone(8, notes[bbuttonPin], 20);}
      
      for (int cbuttonPin = 0; cbuttonPin < 3; cbuttonPin++) {
    // get a sensor reading:
    int cbuttonPinReading = analogRead(cbuttonPin);
    // if the sensor is pressed hard enough:
    if (cbuttonPinReading > threshold) {
      // play the note corresponding to this sensor:
      tone(8, notes[cbuttonPin], 20);}
      
      for (int dbuttonPin = 0; dbuttonPin < 3; dbuttonPin++) {
    // get a sensor reading:
    int dbuttonPinReading = analogRead(dbuttonPin);
    // if the sensor is pressed hard enough:
    if (dbuttonPinReading > threshold) {
      // play the note corresponding to this sensor:
      tone(8, notes[dbuttonPin], 20);}
      
      for (int ebuttonPin = 0; ebuttonPin < 3; ebuttonPin++) {
    // get a sensor reading:
    int ebuttonPinReading = analogRead(ebuttonPin);
    // if the sensor is pressed hard enough:
    if (ebuttonPinReading > threshold) {
      // play the note corresponding to this sensor:
      tone(8, notes[ebuttonPin], 20);}
      
      for (int fbuttonPin = 0; fbuttonPin < 3; fbuttonPin++) {
    // get a sensor reading:
    int fbuttonPinReading = analogRead(fbuttonPin);
    // if the sensor is pressed hard enough:
    if (fbuttonPinReading > threshold) {
      // play the note corresponding to this sensor:
      tone(8, notes[fbuttonPin], 20);}
      }
      }
      }
      }
      }
 }
      }
      }
      }
    }
   }
}





void noteOn (int cmd, int pitch, int velocity) {
  Serial.print (cmd, BYTE);
  Serial.print (pitch, BYTE);
  Serial.print (velocity, BYTE);
  }

I think part of the problem is that you are using the "abuttonPin" variables both for pin numbers and loop variables.

If you declare the pin numbers as 'constant' you can't accidentally change their value. Also, since you are using the buttonPins for analogRead() you might want to make that clear by using the analog pin names. Note that most Arduinos have A0-A5 and no A6.

const int abuttonPin = A0;
const int bbuttonPin = A1;
const int cbuttonPin = A2;
const int dbuttonPin = A3;
const int ebuttonPin = A4;
const int fbuttonPin = A5;
const int piezoPin = 8;
const int footswitch = 9;

You will get a ton of compile errors where you try to assign new values to the pin numbers. Use other variables in those places.

When code statarts to look like this:

      }
      }
      }
      }
      }
 }
      }
      }
      }
    }
   }
}

it is time to investigate using the IDE's auto-format (ctrl-T) tool.

 if (footswitch = LOW) int notes (NOTE_A4 > NOTE_D5);

There's an interesting construct.
It never gets executed, but I wonder what you intended it to do?

It never gets executed, but I wonder what you intended it to do?

Win the IOCCC?

Seriously, MegaUltraTurkey, you should investigate the use of arrays as lookup tables that might help.

also consider the use of functions, this pattern occurs more than once

      for (int dbuttonPin = 0; dbuttonPin < 3; dbuttonPin++) {
    // get a sensor reading:
    int dbuttonPinReading = analogRead(dbuttonPin);
    // if the sensor is pressed hard enough:
    if (dbuttonPinReading > threshold) {
      // play the note corresponding to this sensor:
      tone(8, notes[dbuttonPin], 20);}

could become the following function (I assumed this is what you intended todo)

void handleButton(int pin)
{
  for (int i= 0; i< 3; i++) 
  {
    if (analogRead(i) > threshold) tone(8, notes[pin], 20);
  }
}

making the code

...
handleButton(aButton);
handleButton(bButton);
handleButton(cButton);
handleButton(dButton);
handleButton(eButton);
handleButton(fButton);
handleButton(gButton);
...

Also using:-

int abuttonPin = 1;

Means you are using pin 1 as a push button input. As pins 0 & 1 are used for serial communication it is never a good idea to use them for anything else unless you know what you are doing.

Grumpy_Mike:
Also using:-

int abuttonPin = 1;

Means you are using pin 1 as a push button input. As pins 0 & 1 are used for serial communication it is never a good idea to use them for anything else unless you know what you are doing.

Except that he's using the pin numbers with analogRead() so it means A1.

OK sorry didn't spot that sorry.

Seriously, MegaUltraTurkey, you should investigate the use of arrays as lookup tables that might help.

To that end I put up this page:-
http://www.thebox.myzen.co.uk/Tutorial/Arrays.html