-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnative.cpp
96 lines (63 loc) · 2.18 KB
/
native.cpp
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
/*
Copyright (C) 2013 - 2020 GEATEC engineering
This program is free software.
You can use, redistribute and/or modify it, but only under the terms stated in the QQuickLicence.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY, without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the QQuickLicence for details.
The QQuickLicense can be accessed at: http://www.qquick.org/license.html
__________________________________________________________________________
THIS PROGRAM IS FUNDAMENTALLY UNSUITABLE FOR CONTROLLING REAL SYSTEMS !!
__________________________________________________________________________
It is meant for training purposes only.
Removing this header ends your licence.
*/
#include <Wire.h>
#include <AccelStepper.h>
#include <Adafruit_MotorShield.h>
auto motorShield = Adafruit_MotorShield ();
auto mode = DOUBLE;
// ====== Create decl stepper
auto *declMotor = motorShield.getStepper (48, 2);
void forwardStepDecl () {
declMotor->onestep (FORWARD, mode);
}
void backwardStepDecl () {
declMotor->onestep (BACKWARD, mode);
}
auto declStepper = AccelStepper (forwardStepDecl, backwardStepDecl);
// ====== Create ra stepper
auto *raMotor = motorShield.getStepper (48, 1);
void forwardStepRa () {
raMotor->onestep (BACKWARD, mode);
}
void backwardStepRa () {
raMotor->onestep (FORWARD, mode);
}
auto raStepper = AccelStepper (forwardStepRa, backwardStepRa);
// ====== Standard Arduino callbacks
void setup () {
pinMode (0, INPUT_PULLUP);
pinMode (1, INPUT_PULLUP);
pinMode (2, INPUT_PULLUP);
pinMode (3, INPUT_PULLUP);
pinMode (4, OUTPUT);
motorShield.begin ();
declStepper.setAcceleration (10);
raStepper.setAcceleration (10);
}
void loop () {
downButton = !digitalRead (1);
upButton = !digitalRead (3);
leftButton = !digitalRead (0);
rightButton = !digitalRead (2);
cycle ();
digitalWrite (4, led);
declStepper.setMaxSpeed (declSpeed);
declStepper.move (declGoalDist);
declStepper.run ();
raStepper.setMaxSpeed (raSpeed);
raStepper.move (raGoalDist);
raStepper.run ();
}