-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstepper.h
52 lines (43 loc) · 1.2 KB
/
stepper.h
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
/* Activate Stepper Motor for soap dispensing actuation
* Single stepper motor used to press and release the dispenser
* Connected to P0.16 to P0.19
*/
#define STEPS 50
/* Actuate clockwise rotation of stepper to push down tap
* @param: None
* @return: <void> None
*/
void dispense() {
IO0DIR |= 0xF0000; // Set P0.16 to P0.19 as output
int step_count = STEPS;
while(1) {
int i, to_shift = 1;
for(i = 0; i < 4 && --step_count; i++) {
IO0CLR = 0xF0000; // Clear all concerned pin values
IO0SET = to_shift << 16; // Sets appropriate direction pin
to_shift *= 2;
}
if(!(--step_count))
break;
}
IO0CLR = 0xF0000; // Resets all concerned pins
}
/* Actuate anti-clockwise rotation of stepper to release tap
* @param: None
* @return: <void> None
*/
void release() {
IO0DIR |= 0xF0000; // Set P0.16 to P0.19 as output
int step_count = STEPS;
while(1) {
int i, to_shift = 8;
for(i = 0; i < 4 && --step_count; i++) {
IO0CLR = 0xF0000; // Clear all concerned pin values
IO0SET = to_shift << 16; // Sets appropriate direction pin
to_shift /= 2;
}
if(!(--step_count))
break;
}
IO0CLR = 0xF0000; // Resets all concerned pins
}