-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathouter_wilds_artifact.ino
More file actions
65 lines (57 loc) · 1.1 KB
/
outer_wilds_artifact.ino
File metadata and controls
65 lines (57 loc) · 1.1 KB
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
int state = 0;
int light_pin = 13;
int mic_pin = A0;
int ldr_pin = A2;
bool should_print = false;
int light_threshold = 30;
int dark_threshold = 10;
int mic_threshold = 450;
void setup() {
pinMode(light_pin, OUTPUT); // Light
pinMode(mic_pin, INPUT); // Mic
pinMode(ldr_pin, INPUT); // LDR
if (should_print){
Serial.begin(9600);
}
}
void loop() {
if (state == 0){
off_1();
} else if (state == 1){
off_2();
} else if (state == 2){
on();
}
delay(20);
}
void off_1(){
digitalWrite(light_pin, false);
if (should_print){
Serial.print("0: ");
Serial.println(analogRead(ldr_pin));
}
if (analogRead(ldr_pin) > light_threshold){
state = 1;
}
}
void off_2(){
if (should_print){
Serial.print("1: ");
Serial.println(analogRead(ldr_pin));
}
if (analogRead(ldr_pin) < dark_threshold){
state = 2;
}
}
void on(){
int mic = analogRead(mic_pin);
if (should_print){
Serial.print("2: ");
Serial.println(mic);
}
digitalWrite(light_pin, true);
if (mic == 0 || mic > mic_threshold){
digitalWrite(light_pin, false);
state = 0;
}
}