Paso 4: Arduino-tiempo (versión 1)
Utilice el siguiente código (versión: 1)
int trigger=0; unsigned long Time=0; unsigned long VTime=0; int focus=0; int overD=0; int thresHold=0; int count=0; int maxx=0; int minn=1500;void setup () { pinMode(5,INPUT); pinMode(3, OUTPUT); pinMode(4,OUTPUT); pinMode(12,OUTPUT); pinMode(13,OUTPUT); Serial.begin(9600); digitalWrite(3,HIGH); //initialisation: take 1000 times a sample to set your outer limits //in the middle of the limits, arduino sets its threshold. If the light inensity falls //below that value, the camera will be triggert. while (count< 1000){ int test = analogRead(A1); delay(5); if(testmaxx){ maxx=test;} count=count+1; Serial.println(count); } thresHold=(minn+maxx)/2; Serial.print("max= "); Serial.print(maxx); Serial.print("min= "); Serial.print(minn); Serial.print("threshold= "); Serial.println(thresHold); delay(1000); digitalWrite(4,HIGH); delay(500); digitalWrite(3,LOW); digitalWrite(4,LOW); } void loop () { VTime= analogRead(A0); //read the time delay(5); Serial.print("VTime= "); Serial.println(VTime); Time=map(VTime,0,1023,0,1200); // map the the time so the range of the potentiometer is usefull, note: I didn't use millisecondes, because it makes the code more complicated then needed and slower. focus= digitalRead(5); //see if you pushed the focus button yet Serial.print("laservalue= "); Serial.println (trigger); while(focus== HIGH) { // if you've focussed, you can now wait till the laserbeam is interrupted Serial.println("focussed"); digitalWrite(3,HIGH); // Led will indicated that the camera is focussed overD=1; // arduino will remember you(ve focussed trigger = analogRead(A1); if(trigger < thresHold && overD ==1){ //If you 've focussed and the intensity of the beam is below the treshold //the camera will take a picture delay(Time); //before taking a picture wait a periode of time //delay(1); Serial.println("pic taken"); digitalWrite(4,HIGH); // take the picture for real delay (500); focus=LOW; //Ready for the next one but you will first have to focus again (optional) } } digitalWrite(3,LOW); digitalWrite(4,LOW); }