solenoidScript

SOLENOID CODE

int L_lightMin = 1023; int L_lightMax = 0; int delup = 200; int deldn = 200; int minSpeed = 40; int maxSpeed = 400;

int R_in = 0; int L_in = 0; int in = 0; int threshold = 0; int counter = 0;

void setup { Serial.begin(9600); pinMode(3, OUTPUT); pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); pinMode(8, OUTPUT); pinMode(9, OUTPUT); pinMode(10, OUTPUT); pinMode(11, OUTPUT); }

void loop { //reset min and max values every once in a while// //if (counter == 512){// //counter = 0;// //L_lightMin = 1023;// //L_lightMax = 0;// //}// //R_in = analogRead(0);// Right photocell L_in = analogRead(1); //Left photocell// //in = 0.5 * (R_in + L_in);// averaged value if (in < L_lightMin) L_lightMin = in; if (in > L_lightMax) L_lightMax = in; threshold = L_lightMin + ((L_lightMax - L_lightMin)/2); delup = minSpeed + maxSpeed - map(in, L_lightMin, L_lightMax, minSpeed, maxSpeed); deldn = delup; Serial.println("inputs"); Serial.println(R_in); Serial.println(L_in); Serial.println(in); Serial.println("otherstuff"); Serial.println(counter); Serial.println(delup); Serial.println(threshold); if (in >= 1.0 * threshold){ digitalWrite(3, HIGH); //up// //delay(delup);// wait digitalWrite(3, LOW); //down// //delay(deldn);// wait digitalWrite(4, HIGH); //up// //delay(delup);// wait digitalWrite(4, LOW); //down// //delay(deldn);// wait digitalWrite(5, HIGH); //up// //delay(delup);// wait digitalWrite(5, LOW); //down// //delay(deldn);// wait digitalWrite(6, HIGH); //up// //delay(delup);// wait digitalWrite(6, LOW); //down// //delay(deldn);// wait digitalWrite(8, HIGH); //up// //delay(delup);// wait digitalWrite(8, LOW); //down// //delay(deldn);// wait digitalWrite(9, HIGH); //up// //delay(delup);// wait digitalWrite(9, LOW); //down// //delay(deldn);// wait digitalWrite(10, HIGH); //up// //delay(delup);// wait digitalWrite(10, LOW); //down// //delay(deldn);// wait digitalWrite(11, HIGH); //up// //delay(delup);// wait digitalWrite(11, LOW); //down// //delay(deldn);// wait } else { delay(8*delup); } counter++; }