Paso 2: codificación
Disfrute :)
int ledArray [] = {2,3,4};
Boolean balanceSet = false;
int rojo = 0;
verde int = 0;
int azul = 0;
Float colourArray [] = {0,0,0};
Float whiteArray [] = {0,0,0};
Float blackArray [] = {0,0,0};
int avgRead;
void setup() {}
Serial.Begin(9600); pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT); }
void loop() {}
checkBalance();
checkColour();
printColour();
}
void checkBalance() {}
if(balanceSet == false) {}
setBalance();
}
}
void setBalance() {}
Delay(7000);
para (int i = 0; i < = 2; i ++) {}
digitalWrite(ledArray[i],HIGH);
Delay(100);
getReading(5);
whiteArray [i] = avgRead;
digitalWrite(ledArray[i],LOW);
Delay(100);
}
Delay(7000);
para (int i = 0; i < = 2; i ++) {}
digitalWrite(ledArray[i],HIGH);
Delay(100);
getReading(5);
blackArray [i] = avgRead;
digitalWrite(ledArray[i],LOW);
Delay(100);
}
balanceSet = true;
Delay(5000);
}
void checkColour() {}
para (int i = 0; i < = 2; i ++) {}
digitalWrite(ledArray[i],HIGH);
Delay(100);
getReading(5);
colourArray [i] = avgRead;
Float greyDiff = whiteArray [i] - blackArray [i];
colourArray [i] = (colourArray [i] - blackArray [i]) / (greyDiff) * 255;
digitalWrite(ledArray[i],LOW);
Delay(100);
}
}
void getReading (int veces) {}
int leer;
int cuenta = 0;
para (int i = 0; i < veces; i ++) {}
lectura = analogRead(0);
cuenta = lectura + recuento;
Delay(10);
}
avgRead = (recuento) y horas;
}
void printColour() {Serial.print ("R =");
Serial.println(int(colourArray[0]));
Serial.Print ("G =");
Serial.println(int(colourArray[1]));
Serial.Print ("B =");
Serial.println(int(colourArray[2]));
}
Q de Narzan.