How to code for multiple servo with light sensor

I am very new at this btw... I am trying to build a robot that plays the piano tiles (for a school project). So far I can only code one servo with one light sensor, but how do I code for 4 motors that control by 4 light sensors?

If you post the code you say you have already written, someone may have an idea about how you could expand it.

I am trying to build a robot that plays the piano tiles

What ARE "piano tiles"?

but how do I code for 4 motors that control by 4 light sensors?

Pretty much exactly like you'd do it for one motor and one sensor. Use an array for the Servo instances and an array for the sensor pin numbers and an array for the sensor values. Then, it's a simple matter of using a for loop to iterate over the arrays, reading the appropriate pin, and making the appropriate servo move.

#include <Servo.h>

Servo myservo;
int val;

void setup()
{
myservo.attach(12);
}
void loop()
{
val = analogRead(0);
val = map(val, 0, 1023, 0, 179);
myservo.write(val);
delay(15);
}

This is my current code

We still don't know what a piano "tile" is, are you trying to make the servo strike a piano "key"?

This is my current code

So, where are the arrays?

Servo servos[4];
int servoPos[4];
int servoPins[] = { LeftField, CenterField, HomePlate, FirstBase /* Oh, wait, you'll never get there */ };
int sensorPins[] = { Tom, Dick, Harry, Sally };

void setup()
{
   for(byte i=0; i<4; i++)
   {
      servos[i].attach(servoPins[i]);
   }
}

void loop()
{
   for(byte i=0; i<4; i++)
   {
       int val = analogRead(sensorPins[i]);
       servoPos[i] = map(val, 0, 1023, 0, 179);
       servos[i].write(servoPos[i]);
   }
}

See the pretty code tags? Learn to use them.

756E6C: We still don't know what a piano "tile" is, are you trying to make the servo strike a piano "key"?

Piano Tiles is a game where the player's objective is to tap on the black tiles as they appear from the top of the screen while avoiding the white. When each black tile is tapped, it will emit a piano sound. (copied from wikipedia)

PaulS

Your code don't seem to be working

Your code don't seem to be working

Tough.

You OBVIOUSLY needed to make some changes to use valid pin numbers. Since you changed the code, you need to post YOUR code.

You need to describe what YOUR code ACTUALLY does. You need to describe what you expect.

"It doesn't work" is too lame to merit ANY help.

// 4 servo motor
#include <Servo.h>

Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;

int value1=0;
int value2;
int value3;
int value4;

void setup()
{
servo1.attach(10);
servo2.attach(11);
servo3.attach(12);
servo4.attach(13);
}

void loop()
{
if (value1==0)
value1=20;
value1 = analogRead(0);
value1 = map(value1, 0, 1023, 0, 60);
servo1.write(value1);
delay(15);

if (value2==0)
value2=20;
value2 = analogRead(1);
value2 = map(value2, 0, 1023, 0, 60);
servo2.write(value2);
delay(15);

if (value3==0)
value3=20;
value3 = analogRead(2);
value3 = map(value3, 0, 1023, 0, 60);
servo3.write(value3);
delay(15);

if (value4==0)
value4=20;
value4 = analogRead(3);
value4 = map(value4, 0, 1023, 0, 60);
servo4.write(value4);
delay(15);
}

Thanks

You want:

if (value1==0) {
   . . .
}

Otherwise only the first statement following the if is conditioned by the if. If you use the built-in code formatter, such errors become obvious.