Guidance (code) with Interactive Audio project

With a University group, ive started to develop a project. The project aims to integrate LDR sensors into a stuffed toy to create an interactive audio device which raises audio awareness in kids towards melody (this part is not important to the guidance needed)

I have attached the circuit, which works with a basic test code; illuminating LED’s once an LDR is covered.

The problem my group is having is putting together a feesable code which will instead of lighting LED’s will trigger audio files in Max.

We have used a few different references, texts and books to put together the attached code so far, but its ridden with errors due to this being our first project using an arduino (and the fact our lecturer cant seam to code to save himself, so how else are we expected to learn?)

Any guidance would be greatly appreciated. If any other information is needed ill supply and be very greatful for the help.

code for jingle monkey.txt (2.85 KB)

All executable code, like:

leftValue = analogRead(leftSensor);    // LEFT ARM
rightValue = analogRead(rightSensor);  //RIGHT ARM
leftLegValue = analogRead(leftLegSensor);    //LEFT LEG
rightLegValue = analogRead(rightLegSensor);  //RIGHT LEG
  
  //print the results
  Serial.print(leftValue, DEC);
  Serial.print(rightValue,DEC);
  Serial.print(leftLegValue,DEC);
  Serial.println(rightLegvalue,DEC);

Must be in a function, not just randomly located in the file.

This stuff looks like it should be in loop().

Forget triggering audio for now. Just get the program to read the sensors and Serial.print() to the Serial Monitor.

When you can read the sensors correctly, then you can figure out how to send the data to Max.

In another sketch, ive used this code to read the sensors and output via the LED’s is this what you mean?

int LDRpin1 = 0; //LDR1 in analog pin 0
int LDRpin2 = 1; //LDR2 in analog pin 1
int LDRpin3 = 2; //LDR3 in analog pin 2
int LDRpin4 = 3; //LDR4 in analog pin 3
int LEDpin1 = 13; //LED1 in didital 13
int LEDpin2 = 12; //LED2 in digital 12
int LEDpin3 = 11; //LED3 in digital 11
int LEDpin4 = 10; //LED4 in digital 10
int val1; //value for LDR1
int val2; //value for LDR2
int val3; //value for LDR3
int val4; //value for LDR4

void setup() {
  pinMode(LDRpin1, INPUT); //declare LDR's as INPUT's
  pinMode(LDRpin2, INPUT); 
  pinMode(LDRpin3, INPUT);
  pinMode(LDRpin4, INPUT);
  pinMode(LEDpin1, OUTPUT);
  pinMode(LEDpin2, OUTPUT);
  pinMode(LEDpin3, OUTPUT);
  pinMode(LEDpin4, OUTPUT);
}

void loop()
{
  val1 = analogRead(LDRpin1); //Reads the value in LDR# and stores the variable...
  val2 = analogRead(LDRpin2); 
  val3 = analogRead(LDRpin3);
  val4 = analogRead(LDRpin4);
  if(val1 < 150) //...If value is lower than value of 150 (ranged from 0 - 1023)...
  {
    digitalWrite(LEDpin1, LOW); //...Turn LED off
  }
  else // But if not...
  {
    digitalWrite(LEDpin1, HIGH);// ...Turn the led off
  }
  if(val2 < 150)
  {
    digitalWrite(LEDpin2, LOW);
  }
  else
  {
    digitalWrite(LEDpin2, HIGH);
  }
   if(val3 < 150)
  {
    digitalWrite(LEDpin3, LOW);
  }
  else
  {
    digitalWrite(LEDpin3, HIGH);
  }
   if(val4 < 150)
  {
    digitalWrite(LEDpin4, LOW);
  }
  else
  {
    digitalWrite(LEDpin4, HIGH);
  }
}

In another sketch, ive used this code to read the sensors and output via the LED's is this what you mean?

If you can get Max to read the LEDs (which I doubt), that would work.

  val1 = analogRead(LDRpin1); //Reads the value in LDR# and stores the variable...
  val2 = analogRead(LDRpin2); 
  val3 = analogRead(LDRpin3);
  val4 = analogRead(LDRpin4);
  Serial.print("val1 = ");
  Serial.println(val1);
  Serial.print("val2 = ");
  Serial.println(val2);
  Serial.print("val3 = ");
  Serial.println(val3);
  Serial.print("val4 = ");
  Serial.println(val4);