Because every sensor got its own property's we have to calibrate them to determine what value the sensor gives when he sees black or white
The program to do this can be found at our colleague's blog : http://3autothespoilers.blogspot.be/
after the sensors are calibrated the value's should be put in our program:
this is an example on 6sensors
void setup(){
Serial.begin(2400);
}
void loop() {
int sensors[6]={0,0,0,0,0,0};
int witwaarden[6]={0,0,0,0,0,0};
int zwartwaarden[6]={0,0,0,0,0,0};
int i;
int pin;
int afwijking=0;
int total=0;
int teller=0;
//read the value's from the analog pins
for (i=0;i<6;i++){
pin =A0+i;
sensors[i]=analogRead(pin);
}
//put the sensor value's in a range from 0-100
for (i=0;sizeof(sensors);i++){
sensors[i]=((sensors[i]-zwartwaarden[i])/(witwaarden[i]-zwartwaarden[i]))*100;
}
//calculate the position of the line
for (i=0;sizeof(sensors);i++){
total=total+sensors[i];
}
teller =(sensors[0]*-25)+(sensors[1]*-15)+(sensors[2]*-5)+(sensors[3]*5)+(sensors[4]*15)+(sensors[5]*25);
afwijking=teller/total;
}
Geen opmerkingen:
Een reactie posten