-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptical_shutter.ino
More file actions
69 lines (51 loc) · 1.28 KB
/
Copy pathoptical_shutter.ino
File metadata and controls
69 lines (51 loc) · 1.28 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
66
67
68
69
// For simple optical shutter in Greytak Laboratory
// Servo motor movement direction driven by push buttons, LEDs indicate which button was pressed
// Arduino Nano board used in this build
// Mathew L. Kelley
#include<Servo.h>
int pos = 0;
Servo servo;
const int GREENBUTTON = 5;
const int GREENLED = 3;
int GREENBUTTONstate = 0;
const int REDBUTTON = 6;
const int REDLED = 4;
int REDBUTTONstate = 0;
void setup() {
// Servo setup:
pinMode(11, INPUT); // digital pin 11
pinMode(12, INPUT); // digital pin 12
pinMode(GREENBUTTON, INPUT);
pinMode(GREENLED, OUTPUT);
pinMode(REDBUTTON, INPUT);
pinMode(REDLED, OUTPUT);
servo.attach(2); // digital pin 2
}
void loop() {
GREENBUTTONstate = digitalRead(GREENBUTTON);
if (GREENBUTTONstate == HIGH)
{
digitalWrite(GREENLED, HIGH);
}
else{
digitalWrite(GREENLED, LOW);
}
REDBUTTONstate = digitalRead(REDBUTTON);
if (REDBUTTONstate == HIGH)
{
digitalWrite(REDLED, HIGH);
}
else{
digitalWrite(REDLED, LOW);
}
if (digitalRead(11) == HIGH && pos < 180) {
pos = 15;
servo.write(pos);
delay(10);
}
if (digitalRead(12) == HIGH && pos > 0 ) {
pos = 130;
servo.write(pos);
delay(10);
}
}