/
ff-motor.ino
54 lines (39 loc) · 1.19 KB
/
ff-motor.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
/*
Fish Feeder DOMOVOY v.4.0 firmware
Specs: DIP board, uln2003, ds1307, HC-05, battery, analog keys
rev. 4.0.2
This file contains motor procedures
More information about the project can be found here: http://www.mf21.ru
created 2017
by KWL
*/
void motorInit() {
byte RetractionState;
motorNumTurns = EEPROM.read(ROMMotorOffset);
RetractionState = EEPROM.read(ROMRetractionOffset);
if (RetractionState == 255) {
RetractionState = 1;
EEPROM.write(ROMRetractionOffset, RetractionState);
}
}
void motorRotate(long Turns) {
unsigned long Angle;
byte RetractionState;
RetractionState = EEPROM.read(ROMRetractionOffset);
Angle = Turns * motorTurn + motorRetractionBefore * motorTurn * RetractionState;
motor.setSpeed(motorSpeed);
motor.step(motorRetractionBefore * motorTurn);
if (Angle < 32767) {
motor.step(-Angle);
} else {
for (int i=0; i<int(Angle / 32767); i++) {
motor.step(-32767);
}
motor.step(-1 * (Angle - int(Angle / 32767)*32767));
}
motor.step(motorRetractionAfter * motorTurn);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
}