-
Notifications
You must be signed in to change notification settings - Fork 1
/
sketch.ino
65 lines (51 loc) · 1.14 KB
/
sketch.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
// Sketch to take picture on button press
// Open Source Code under MIT License. Created by Ryan Davis.
#include <Bridge.h>
#include <Process.h>
// Picture process
Process picture;
// Filename
String filename;
// Pin
int button_pin = 3;
int blue = 2;
int green = 3;
int red = 4;
// Path
String path = "/mnt/sda1/";
void setup() {
// Bridge
Bridge.begin();
// Set pin mode
pinMode(button_pin,INPUT);
pinMode(blue,OUTPUT);
pinMode(green,OUTPUT);
pinMode(red,OUTPUT);
}
void loop(void)
{
if (analogRead(button_pin) >= 800) {
// Generate filename with timestamp
filename = "";
picture.runShellCommand("date +%s");
while(picture.running());
while (picture.available()>0) {
char c = picture.read();
filename += c;
}
filename.trim();
filename += ".png";
digitalWrite(red,HIGH);
delay(1000);
digitalWrite(red,LOW);
digitalWrite(blue,HIGH);
delay(1000);
digitalWrite(blue,LOW);
digitalWrite(green,HIGH);
delay(1000);
digitalWrite(green,LOW);
// Take picture
picture.runShellCommand("fswebcam " + path + filename + " -r 1280x720");
while(picture.running());
}
}