-
Notifications
You must be signed in to change notification settings - Fork 0
/
DropShot.ino
86 lines (72 loc) · 1.99 KB
/
DropShot.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#define LED 13 //LED Pin for Status
#define FLASH 2 // Optocoupler PIN for the flash
#define SHUTTER 4 // Optocoupler Pin for the shutter
#define TRIGGER 0 // Lightbar receiver to start the rec
#define VALVE 6 // Valve Output Pin -> Transistor
#define SWITCH 8 // Trigger button to open the valve
#define DROPSIZE 90 // Valve open time Test: 90ms@9,1V
#define FLASHDELAY 180 // Delay between trigger and flash
//Usually t= sqrt((2h)/9,81)
// No interrupt neaded. Timing is @ 16Mhz fairly accurate
int value = 0;
boolean done = false;
void setup() {
//Pin modes
pinMode(LED, OUTPUT);
digitalWrite(LED, HIGH); //Show status
pinMode(FLASH, OUTPUT);
pinMode(SHUTTER, OUTPUT);
pinMode(VALVE, OUTPUT);
pinMode(TRIGGER, INPUT);
pinMode(SWITCH, INPUT);
Serial.begin(9600); //Begin serial communcation -> Debug
// collect sensor data
for(int i = 0; i <= 10; i++){
value += analogRead(TRIGGER);
delay(100);
}
value = value/10; // average sensor data
digitalWrite(LED, LOW); //End startup
}
void loop() {
//Serial.println(analogRead(TRIGGER)); //Write the value of the photoresistor to the serial monitor.
//insert here analogRead(POTI) to controll manually the delay for valve and trigger.
//Start the shooting
if(digitalRead(SWITCH) && done == false){
//noInterrupts();
shoot();
delay(100); // wait for mechanical camera parts
valve();
done=true;
}
// If trigger -> make a photo
if(analogRead(TRIGGER) > value){
delay(FLASHDELAY);
flash();
delay(1000);
done = false; // reenable
}
}
//Photo trigger function
void shoot(){
digitalWrite(SHUTTER, HIGH);
delay(60);
digitalWrite(SHUTTER, LOW);
done = true;
Serial.println("shoot!");
}
//Flash light function
void flash(){
digitalWrite(FLASH, HIGH);
delay(60);
digitalWrite(FLASH, LOW);
Serial.println("flash!");
}
//Valve open function
void valve(){
digitalWrite(VALVE, HIGH);
delay(DROPSIZE);
digitalWrite(VALVE, LOW);
done = true;
Serial.println("value opende");
}