I strongly suspect the main problems with your code are in these lines:
if(detect2 <= (master2 - 10) || detect2 >= (master2 + 10)) {
accumulator++;
}
If I understand correctly, with this code you are attempting to tell whether you have been over a line of tape, which will be indicated by a change in reading from RGB.readGreen(); - say high, low, high. If so, accumulator++. (I have no opinion on whether this is a valid way of sensing it, or how well your sensor will work.)
This is definitely broken in one way, and probably broken in another.
First the definitely-broken way:
You want to sense down-up-down-up-down-up (or up-down-up-down-up-down). Your code senses simply three higher or lower readings. Your loop() takes no time at all, so when your buggy moves onto the tape, it will immediately read (say) high, then loop round, read high again, loop round and read high again, and again. accumulator is now 3 and we stop the motor.
Second, the maybe-broken way:
What value does master2 have? Consider that it is an unsigned integer. You are subtracting 10 from it. What do you get if its value is 5? It can'be be -5 because it is unsigned. How you solve this depends on the possible range of values from RGB.readGreen();. The implementation looks like it could give a value anywhere in the range, so we have to be careful.
Here's my reworking of your code. It assumes the concept of checking for values which vary by 10 from the original value is sensible - I've no idea if it is. (I don't understand what this "middle" values means, but you say you've "already tested the components individually" which I don't believe because your code could never have worked but, assuming you saw something similar working...) It also makes a very big assumption that the value will change cleanly - from higher to lower exactly once per edge of strip, with no wobbling. Log out some values to find whether it really does.
#include <SFE_ISL29125.h>
SFE_ISL29125 RGB;
int master2;
boolean isOn = false;
int changes = 0;
#define BUTTON 7
#define MOTOR_A 8
#define MOTOR_B 9
#define LOWER 0
#define HIGHER 1
int last_state = 0;
void setup() {
RGB.init();
pinMode(BUTTON, INPUT);
pinMode(MOTOR_A, OUTPUT);
pinMode(MOTOR_B, OUTPUT);
master2 = (int)(RGB.readGreen()/2);
}
void loop() {
if(isOn) {
// Wait for 6 changes: up-down or down-up, three times.
if(changes < 6) {
int detect2 = (int)(RGB.readGreen()/2);
digitalWrite(MOTOR_A, HIGH);
digitalWrite(MOTOR_B, LOW);
// Count _changes_ in state only
if(last_state == HIGHER && detect2 <= (master2 - 5) {
last_state = LOWER;
changes++;
} else if (last_state == LOWER && detect2 >= (master2 + 5)) {
last_state = HIGHER;
changes++;
}
} else {
accumulator = 0;
isOn = false;
digitalWrite(MOTOR_A, LOW);
digitalWrite(MOTOR_B, LOW);
}
} else if(digitalRead(7) == HIGH) {
isOn = true;
} else {
digitalWrite(MOTOR_A, LOW);
digitalWrite(MOTOR_B, LOW);
}
}
#defines) please? It's hard(er than I can be bothered with) to guess what the various pins do.