Negative frequency value's from a color sensor

int R = 0;
int G = 0;
int B = 0;

The int data type can hold values from -32768 to 32767. 32767 + 1 = -32768 due to "roll over".

R= pulseIn(out, LOW);

The pulseIn() function returns an unsigned long data type. Unsigned long holds 0 to 4,294,967,295. So if pulseIn() returns a value greater than 32767 it rolls over to negative values. Solution, make R, G and B data types appropriate to the values returned to them by pulseIn() (unsigned long).