School Project: Door Lock

we are doing a project in which a color sensor reads a sequence of colors to turn a servo. If the sequence is correct it turns and if it isn't then it wont turn. we need help trying to write code for the servo to turn when the sequence is correct. we have code to make the color sensor read the colors of blue, green, and red as 1, 2, and 3. we have also made it to where the sensor only reads the color once.

Hint: if you want help with code, you need to post your code. Use code tags.

#include <Servo.h>

Servo myservo;

int pos = 0;

const int redOut = 6;
const int greenOut = 5;
const int blueOut = 3;
const int ledPin = 13;
const int GSR1 = 12;
const int GSR0 = 11;
const int GSG1 = 10;
const int GSG0 = 9;
const int GSB1 = 8;
const int GSB0 = 7;
int redPin = A0;
int redScaled;
int redSum = 0;
int redAverage;
int greenPin=A1;
int greenScaled;
int greenSum = 0;
int greenAverage;
int bluePin = A2;
int blueScaled;
int blueSum = 0;
int blueAverage;

int mainColor;
int oldMainColor;
int color1;
int color2;
int color3;
int oldColor1;
int oldColor2;
int oldColor3;
int colorCheck = 1;

// Sensor read values
int red[20];
int green[20];
int blue[20];

void setup()
{
Serial.begin(9600);
pinMode(redOut, OUTPUT);
pinMode(blueOut,OUTPUT);
pinMode(greenOut,OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(GSR1, OUTPUT);
pinMode(GSR0, OUTPUT);
pinMode(GSG1, OUTPUT);
pinMode(GSG0, OUTPUT);
pinMode(GSB1, OUTPUT);
pinMode(GSB0, OUTPUT);
pinMode(redPin,INPUT);
pinMode(greenPin,INPUT);
pinMode(bluePin,INPUT);
// Turn on the LED
digitalWrite(ledPin, HIGH);

myservo.attach(9);

// Set the gain of each sensor
digitalWrite(GSR1, HIGH);
digitalWrite(GSR0, HIGH);
digitalWrite(GSG1, HIGH);
digitalWrite(GSG0, HIGH);
digitalWrite(GSB1, HIGH);
digitalWrite(GSB0, HIGH);

}

void loop()
{

for (int i = 0; i < 20; i++)
{
red*=analogRead(redPin);*
_ green*=analogRead(greenPin);_
_ blue=analogRead(bluePin);
redSum = redSum + red;
greenSum = greenSum + green;
blueSum = blueSum + blue;
}*

redAverage = redSum / 20;
greenAverage = greenSum / 20;
blueAverage = blueSum / 20;_

redScaled = redAverage *10;
greenScaled = greenAverage * 14;
blueScaled = blueAverage * 17;

redScaled = map(redScaled,140,1140,0,1023);
greenScaled = map(greenScaled,266,1700,0,1023);
blueScaled = map(blueScaled,187,1420,0,1023);

if(redScaled < 0) {redScaled = 0;}
if(redScaled > 1023) {redScaled = 1023;}
if(greenScaled < 0) {greenScaled = 0;}
if(greenScaled > 1023) {greenScaled = 1023;}
if(blueScaled < 0) {blueScaled = 0;}
if(blueScaled > 1023) {blueScaled = 1023;}

if(redScaled > greenScaled && redScaled > blueScaled)
{
* mainColor = 1;*
}
if(greenScaled > redScaled && greenScaled > blueScaled)
{
* mainColor = 2;*
}

if(blueScaled > redScaled && blueScaled > greenScaled)
{
* mainColor = 3;*
}

if(mainColor != oldMainColor)
{
* Serial.println(mainColor);*
}
oldMainColor = mainColor;

redSum = 0;
greenSum = 0;
blueSum = 0;

//Serial.print("red scaled: ");
//Serial.print(redScaled);
//Serial.print(" green scaled: ");
//Serial.print(greenScaled);
//Serial.print(" blue scaled: ");
//Serial.print(blueScaled);
//Serial.println("");

}

Have another careful read of reply #1.