-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArmStepper.ino
More file actions
77 lines (63 loc) · 1.71 KB
/
ArmStepper.ino
File metadata and controls
77 lines (63 loc) · 1.71 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
70
71
72
73
74
75
76
77
#include "SpeedyStepper.h"
#include "RCServo.h"
SpeedyStepper armStepper; // init objects from libs
RCServo EMagnet;
int microStepping = 8; // settings values
float armAccel = 2;
float armSpeed = 10;
int steps = 200;
int transmissionRatio = 2;
float maxDistance = 1.0;
const byte ARM_STEPPER_PIN = 2; // assigning sensors and pins to vars
const byte HOME_SENSOR_PIN = A1;
const byte TOP_SENSOR_PIN = A2;
const byte BOTTOM_SENSOR_PIN = A3;
const byte EMAGNET_PIN = A4;
const byte PISTON_PIN = 10;
void setup() {
pinMode(HOME_SENSOR_PIN, INPUT_PULLUP); // init sensors to be inputs
pinMode(TOP_SENSOR_PIN, INPUT_PULLUP);
pinMode(BOTTOM_SENSOR_PIN, INPUT_PULLUP);
pinMode(PISTON_PIN, OUTPUT);
armStepper.connectToPort(ARM_STEPPER_PIN); // init stepper and electromagnet
EMagnet.connectToPin(EMAGNET_PIN);
armStepper.setAccelerationInRevolutionsPerSecondPerSecond(armAccel); //init the speed and accel
armStepper.setStepsPerRevolution(transmissionRatio * microStepping * steps);
armStepper.setSpeedInRevolutionsPerSecond(armSpeed);
}
void loop() {
goHome();
goToTopTower();
turnOnEMagnet();
armGoDown();
delay(1000);
armGoUp();
delay(2000);
GoToBottomPad();
armGoDown();
delay(2000);
turnOffEmagnet();
armGoUp();
delay(2000);
}
void goHome() {
armStepper.moveToHomeInRevolutions(-1, armSpeed, maxDistance, HOME_SENSOR_PIN);
}
void goToTopTower() {
armStepper.moveToPositionInRevolutions(.255);
}
void turnOnEMagnet() {
EMagnet.setServoPosition(1.0);
}
void turnOffEmagnet() {
EMagnet.setServoPosition(0.0);
}
void armGoUp() {
digitalWrite(PISTON_PIN, LOW);
}
void armGoDown() {
digitalWrite(PISTON_PIN, HIGH);
}
void GoToBottomPad() {
armStepper.moveToPositionInRevolutions(.42);
}