Color sensor controlling LEDs

Hi guys,

I'm in a project trying to get a ADJD s311 color sensor to calibrate and then control lights with the readings from the sensor using an Arduino Uno. So if the value of r is in a certain range (corresponding to a certain color) it turns on a certain number of lights etc. For this I tried to merge two files I had, slowly working all of the errors out, but it doesn't seem to be working, though it uploads to the Arduino Uno just fine. Seperately the two sketches I merged worked fine too. One is mainly for calibrating and the other was for reading and controlling the lights. The sketch reading and controlling the lights however didn't give very consistent readings, so that's why I wanted the calibration in there as well. I'd appreciate any help! Colorsensorfinal.ino is the merged file, sketch-may04b.ino is the calibrating file and color_sensornew4.ino is the file for reading and controlling the lights.

Colorsensorfinal.ino (22.6 KB)

Color_sensornew4.ino (10 KB)

sketch_may04b.ino (14.7 KB)

No one with experience in using color sensors?