Need help putting codes together

I have two codes that I would like to put together. I have a colorPAL light sensor that is functioning, sending color data over serial. I also have an analog light sensor that I can use to send midi notes out. I’m really noobish with this stuff, still though. I would like to send the RGB data from the colorPAL to the arduino instead of the light sensor, and then use its values to controle note, velocity and either pan or phase or something along those lines. I can switch things around a little to make it fit my needs, but I’m clueless as to how to combine the two. I’m sure it should be easy, but not for me. I would also like to remove the switchpin and just have a constant output, once it’s all done, with new values triggering the notes.

Thanks anyone for looking or commenting.

// analog in midi out

 const int switchPin = 10;  // The switch is on Arduino pin 10
 const int middleC = 60;    // Middle C (MIDI note value 60) is the lowest
                            //  note we'll play
 const int LEDpin = 13;     //  Indicator LED
 const int lightPin = 0;

 // Variables: 
 byte note = 0;              // The MIDI note value to be played
 int AnalogValue = 0;        // value from the analog input
 int lastNotePlayed = 0;     // note turned on when you press the switch
 int lastSwitchState = 0;    // state of the switch during previous time
                             //  through the main loop
 int currentSwitchState = 0;

 void setup() {
   //  set the states of the I/O pins:
   pinMode(switchPin, INPUT); // read the switch on/off
   pinMode(LEDpin, OUTPUT); // send a signal to turn on led to show note 
                            // being played
   //  Set MIDI baud rate:
   Serial.begin(31250); // the rate of MIDI communication
   blink(3); // LED shows signal communication has started

 void loop() {
   //  My potentiometer gave a range from 0 to 1023: original comment;
   //  must know sensor values though
   AnalogValue = analogRead(0); // reads the analog sensor
   //  convert to a range from 0 to 127:
   note = AnalogValue/3.5; // I used a light sensor that read about 900 
                      //- devide by 127 to get value - midi reads values of 127
   currentSwitchState = digitalRead(switchPin);
   // Check to see that the switch is pressed:
   if (currentSwitchState == 1) {
     //  check to see that the switch wasn't pressed last time
     //  through the main loop:
     if (lastSwitchState == 0) {
       // set the note value based on the analog value, plus a couple octaves:
       // note = note + 60;
       // start a note playing:
       noteOn(0x90, note, 0x40);
       // save the note we played, so we can turn it off:
       lastNotePlayed = note;
       digitalWrite(LEDpin, HIGH);
       Serial.println(analogRead(lightPin/4)); //Write the value of the 
       // photoresistor to the serial monitor.
   else {   // if the switch is not pressed:
     //  but the switch was pressed last time through the main loop:
     if (lastSwitchState == 1) {
       //  stop the last note played:
       noteOn(0x90, lastNotePlayed, 0x00);
       digitalWrite(LEDpin, LOW);

   //  save the state of the switch for next time
   //  through the main loop:
   lastSwitchState = currentSwitchState;

 //  plays a MIDI note.  Doesn't check to see that
 //  cmd is greater than 127, or that data values are  less than 127:
 void noteOn(byte cmd, byte data1, byte  data2) {
   Serial.print(cmd, BYTE);
   Serial.print(data1, BYTE);
   Serial.print(data2, BYTE);

 // Blinks an LED 3 times
 void blink(int howManyTimes) {
   int i;
   for (i=0; i< howManyTimes; i++) {
     digitalWrite(LEDpin, HIGH);
     digitalWrite(LEDpin, LOW);

and then the colorPAL

#include <SoftwareSerial.h>

SoftwareSerial Color90(2, 3);

 / Connect ColorPAL SIG signal to Arduino pin 2 and 3
 / Baud Rate = 9600 kbps
 / Connect Power to 3.3v
 / Read signal on 9600 in HEX

void setup()
  Serial.begin(9600); // Start communication with serial port read value
  Color90.begin(4800); // Send signal to led to read value

  pinMode(2,INPUT); // serial pin out from color pal
  pinMode(3,INPUT); // from same serial pin, signal pulls up, sends, pulls down, reads
  digitalWrite(2,HIGH); // Enable the pull-up resistor
  digitalWrite(3,HIGH); // Enable the pull-up resistor

  pinMode(2,OUTPUT); // send signal out
  digitalWrite(2,LOW); // turn pin off so pin 3 can go high
  pinMode(2,INPUT); // Input signal to print
  Serial.println("Pass 1");
  while( digitalRead(2) != HIGH || digitalRead(3) != HIGH ) {
    Serial.println("In the loop");
  Serial.println("Pass 2");


 // This oscillates back and forth on one wire to turn off led, send signal,
 // turn on led, read signal. very fast strobe read - arduino is not capable of 
 // one wire signal communication over digital ports, so this is a way around
 // that over 2 wires communicating with 1 pin on the sensor. 

void loop()
  char rByte[9];
  Color90.print("= (00 $ m) !");

  rByte[0] =;
  if( rByte[0] == '

) {
   for(int i=0; i<9; i++) {
     rByte[i] =;


The first thing to do is to click on "modify" up there on the right, then highlight each block of code, then click the '#' icon on the editor's toolbar.

Thanks. I wasn't sure how to do that. Did I mention noob?