User:JBers/enes100/My Work3/Turn2FansOnAndOff

//Code for the QRE1113 Digital board //Outputs via the serial terminal - Lower numbers mean more reflected //3000 or more means nothing was reflected.

int QRE1113_Pin = 2; //connected to digital 2

void setup{ Serial.begin(9600); //establish motor direction toggle pins pinMode(12, OUTPUT); //drive motor -- HIGH = forwards and LOW = backwards pinMode(11, OUTPUT); //Sets initial direction of drive motor digitalWrite(12, HIGH); digitalWrite(11, HIGH); }

void loop{

int QRE_Value = readQD; Serial.println(QRE_Value);

}

int readQD{ //Returns value from the QRE1113 //Lower numbers mean more refleacive //More than 3000 means nothing was reflected. pinMode( QRE1113_Pin, OUTPUT ); digitalWrite( QRE1113_Pin, HIGH ); delayMicroseconds(10); pinMode( QRE1113_Pin, INPUT );

long time = micros;

//time how long the input is HIGH, but quit after 3ms as nothing happens after that while (digitalRead(QRE1113_Pin) == HIGH && micros - time < 3000); int diff = micros - time;

if (diff < 300){ //set drive motor backwards direction digitalWrite(12, HIGH); digitalWrite(11, HIGH); } else{

//set drive motor forward direction digitalWrite(12, LOW); digitalWrite(11, LOW);

}

return diff; }