forked from SeckinSinanIsik/FilmScaningProject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Semi-automaticUsingArduino.ino
101 lines (97 loc) · 3.1 KB
/
Semi-automaticUsingArduino.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* Automatic film scanning for Film Carriers
sing Arduino Nano
MIT License
Copyright (c) 2020 Seckin Sinan Isik
*/
// stepper control outputs, Pin address
#define motStepPin 8
#define motDirPin 7
#define motMS1Pin 11
#define motMS2Pin 10
#define motMS3Pin 9
// button inputs, Pin address
#define buttonRev 4
#define buttonRunRev 13
#define buttonRun 6
#define buttonFrw 5
#define buttonPicture 3
// speed control pot
#define speedPot A7
int FrameLength=111;
const int ledPin = 12;
int motSpeed; //use this variable if you keep it fixed
void setup() {
Serial.begin(9600);
pinMode(buttonRun, INPUT);
pinMode(buttonRunRev, INPUT);
pinMode(buttonFrw, INPUT);
pinMode(buttonRev, INPUT);
pinMode(buttonPicture, INPUT);
// configure initial motor settings
digitalWrite(motStepPin, LOW);
digitalWrite(motDirPin, HIGH);
digitalWrite(motMS1Pin, LOW);
digitalWrite(motMS2Pin, LOW);
digitalWrite(motMS3Pin, LOW);
pinMode(motStepPin, OUTPUT);
pinMode(motDirPin, OUTPUT);
pinMode(motMS1Pin, OUTPUT);
pinMode(motMS2Pin, OUTPUT);
pinMode(motMS3Pin, OUTPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
}
void loop() {
// MircoStep Forward
if (digitalRead(buttonFrw)== LOW) {
digitalWrite(motDirPin, 1); // direction input
digitalWrite(motMS1Pin,1); //[MS1][MS2][MS3] all 1 for activatin 1/16 micro ste
digitalWrite(motMS2Pin,1);
digitalWrite(motMS3Pin,1);
for (int i = 0; i < 24; i++) { //using microseteps for precision
motSpeed = map(analogRead(speedPot), 0, 1023, 5000, 200); //read motor speed
digitalWrite(motStepPin, HIGH);
delayMicroseconds(motSpeed);
digitalWrite(motStepPin, LOW);
delayMicroseconds(motSpeed);
}
delay(80);
}
// MircoStep Reverse
if (digitalRead(buttonRev)== LOW ) {
digitalWrite(motDirPin, 0); // direction input
digitalWrite(motMS1Pin,1); //[MS1][MS2][MS3] all 1 for activatin 1/16 micro ste
digitalWrite(motMS2Pin,1);
digitalWrite(motMS3Pin,1);
for (int i = 0; i < 24; i++) {//using microseteps for precision
motSpeed = map(analogRead(speedPot), 0, 1023, 5000, 200); //read motor speed
digitalWrite(motStepPin, HIGH);
delayMicroseconds(motSpeed);
digitalWrite(motStepPin, LOW);
delayMicroseconds(motSpeed);
}
delay(80);
}
// Next Frame
if (digitalRead(buttonRun)==LOW ) {
digitalWrite(motDirPin, 1); // direction input
digitalWrite(motMS1Pin,0); //[MS1][MS2][MS3] all 0 for activating full step
digitalWrite(motMS2Pin,0);
digitalWrite(motMS3Pin,0);
for (int i = 0; i < FrameLength; i++) { //Using full steps to advance
motSpeed = map(analogRead(speedPot), 0, 1023, 5000, 200); //read motor speed
digitalWrite(motStepPin, HIGH);
delayMicroseconds(motSpeed);
digitalWrite(motStepPin, LOW);
delayMicroseconds(motSpeed);
}
delay(400);
}
// Take a picture
if (digitalRead(buttonPicture)== LOW) {
digitalWrite(ledPin, LOW);
delay(100);
digitalWrite(ledPin, HIGH);
delay(500);
}
}