Stap 2: codering
Genieten :)
int ledArray [] = {2,3,4};
Boole balanceSet = false;
int rood = 0;
int groen = 0;
int blauw = 0;
zweven [colourArray] = {0,0,0};
zweven [whiteArray] = {0,0,0};
zweven [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();
}
ongeldig checkBalance() {}
if(balanceSet == false) {}
setBalance();
}
}
ongeldig setBalance() {}
delay(7000);
for (int i = 0; ik < = 2; i ++) {}
digitalWrite(ledArray[i],HIGH);
delay(100);
getReading(5);
whiteArray [i] = avgRead;
digitalWrite(ledArray[i],LOW);
delay(100);
}
delay(7000);
for (int i = 0; ik < = 2; i ++) {}
digitalWrite(ledArray[i],HIGH);
delay(100);
getReading(5);
blackArray [i] = avgRead;
digitalWrite(ledArray[i],LOW);
delay(100);
}
balanceSet = true;
delay(5000);
}
ongeldig checkColour() {}
for (int i = 0; ik < = 2; i ++) {}
digitalWrite(ledArray[i],HIGH);
delay(100);
getReading(5);
colourArray [i] = avgRead;
zweven greyDiff = whiteArray [i] - blackArray [i];
colourArray [i] = (colourArray [i] - blackArray [i]) / (greyDiff) * 255;
digitalWrite(ledArray[i],LOW);
delay(100);
}
}
VOID getReading (int keer) {}
int lezen;
int tally = 0;
voor (int i = 0; ik < keer; i ++) {}
lezen = analogRead(0);
Tally = lezing + tally;
delay(10);
}
avgRead = (tally) / times;
}
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]));
}
Narzan Q.