5
5
#include < AccelStepper.h>
6
6
#include < LiquidCrystal.h>
7
7
#include < SoftwareSerial.h>
8
+
8
9
#define HALFSTEP 8
9
10
#define FULLSTEP 4
10
11
11
12
LiquidCrystal lcd (8 , 9 , 4 , 5 , 6 , 7 );
12
13
// SoftwareSerial BT(10,11);
13
14
15
+ // RA Motor pins
14
16
#define motorPin1 2 // IN1 auf ULN2003 driver 1 // 2 / 22
15
17
#define motorPin2 3 // IN2 auf ULN2003 driver 1 // 3 / 24
16
18
#define motorPin3 11 // IN3 auf ULN2003 driver 1 // 11 / 26
17
19
#define motorPin4 12 // IN4 auf ULN2003 driver 1 // 12 / 28
18
20
21
+ // DEC Motor pins
19
22
#define motorPin11 15 // IN1 auf ULN2003 driver 2
20
23
#define motorPin12 16 // IN2 auf ULN2003 driver 2
21
24
#define motorPin13 17 // IN3 auf ULN2003 driver 2
22
25
#define motorPin14 18 // IN4 auf ULN2003 driver 2
23
26
27
+ // LCD shield buttons
24
28
#define btnRIGHT 0
25
29
#define btnUP 1
26
30
#define btnDOWN 2
27
31
#define btnLEFT 3
28
32
#define btnSELECT 4
29
33
#define btnNONE 5
30
34
35
+ // Menu IDs
31
36
#define RA_Menu 0
32
37
#define DEC_Menu 1
33
38
#define HA_Menu 2
34
39
#define Polaris_Menu 3
35
40
#define Heat_Menu 4
36
41
#define Calibration_Menu 5
37
42
#define Control_Menu 6
43
+ #define Home_Menu 7
38
44
39
- int lcd_key = 0 ;
40
- int adc_key_in = 0 ;
41
- int read_LCD_buttons () {
42
- adc_key_in = analogRead (0 );
43
- if (adc_key_in > 1000 ) return btnNONE;
44
- if (adc_key_in < 50 ) return btnRIGHT;
45
- if (adc_key_in < 250 ) return btnUP;
46
- if (adc_key_in < 450 ) return btnDOWN;
47
- if (adc_key_in < 600 ) return btnLEFT;
48
- if (adc_key_in < 920 ) return btnSELECT;
49
- // return btnNONE;
50
- }
51
-
52
- // Adjust the given number by the given adjustment, wrap around the limits.
53
- // Limits are inclusive, so they represent the lowest and highest valid number.
54
- int adjustWrap (int current, int adjustBy, int minVal, int maxVal)
55
- {
56
- current += adjustBy;
57
- if (current > maxVal) current -= (maxVal + 1 );
58
- if (current < minVal) current += (maxVal + 1 );
59
- return current;
60
- }
61
-
62
- // Adjust the given number by the given adjustment, clamping to the limits.
63
- // Limits are inclusive, so they represent the lowest and highest valid number.
64
- int adjustClamp (int current, int adjustBy, int minVal, int maxVal)
65
- {
66
- current += adjustBy;
67
- if (current > maxVal) current = maxVal;
68
- if (current < minVal) current = minVal;
69
- return current;
70
- }
71
-
72
- int adjustSecond (int current, int adjustBy) {
73
- return adjustWrap (current, adjustBy, 0 , 59 );
74
- }
75
-
76
- int adjustMinute (int current, int adjustBy) {
77
- return adjustWrap (current, adjustBy, 0 , 59 );
78
- }
79
-
80
- int adjustHour (int current, int adjustBy) {
81
- return adjustWrap (current, adjustBy, 0 , 23 );
82
- }
83
-
84
- String inString = " " ;
85
- int controlDisplay =0 ;
86
-
45
+ // Stepper control for RA and DEV.
46
+ // TRK is used for live tracking and runs in parallel with RA.
47
+ // GUIDE is used for Stellarium control
87
48
AccelStepper stepperRA (FULLSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
88
49
AccelStepper stepperDEC (HALFSTEP, motorPin11, motorPin13, motorPin12, motorPin14);
89
50
AccelStepper stepperTRK (HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4); // yes, this is the same motor as stepperRA, dont ask why
90
51
AccelStepper stepperGUIDE (HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
91
52
53
+ int lcd_key = 0 ; // The current key state
54
+ int adc_key_in = 0 ; // The analog value of the keys
55
+
56
+ String inString = " " ;
57
+
58
+ int calDelay = 150 ; // The current delay when changing calibration value. The longer a button is depressed, the samller this gets.
59
+
60
+ bool waitForButtonRelease = false ; // When a button is pressed should we wait for its release before another loop?
61
+
62
+ // Variables for use in the CONTROL menu
63
+ int StateMaskDEC = 0x0011 ; // Is the DEC stepper running?
64
+ int StateMaskUp = 0x0001 ; // Is the DEC stepper moving upwards?
65
+ int StateMaskDown = 0x0010 ; // Is the DEC stepper moving downwards?
66
+ int StateMaskRA = 0x1100 ; // Is the RA stepper running?
67
+ int StateMaskLeft = 0x0100 ; // Is the RA stepper moving left (CW)?
68
+ int StateMaskRight = 0x1000 ; // Is the RA stepper moving right (CCW)?
69
+
70
+ int controlState = 0x0000 ; // The current state of the steppers (combination of above values)
71
+ int controlDisplay = 0 ; // How many loop cycles left before updating the display
72
+ bool inControlMode = false ; // Is manual control enabled
73
+
74
+ int lastKey = btnNONE; // The key state when we last came through the loop
75
+
76
+ float totalDECMove = 0 ; // The number of DEC steps we asked for
77
+ float totalRAMove = 0 ;
78
+ bool isUnreachable = false ;
79
+
92
80
// String inCmd;
93
81
// String inputString = "";
94
82
// String commandString = "";
@@ -116,15 +104,9 @@ int mPolarisPosition;
116
104
int tracking = 1 ;
117
105
float trackingspeed;
118
106
119
- // RA stuff
120
- int hourRA=0 ;
121
- int minRA = 0 ;
122
- int secRA = 0 ;
107
+ // RA stuff
123
108
float moveRA;
124
109
int RAselect;
125
- int hourRAprint;
126
- int minRAprint;
127
- int secRAprint;
128
110
129
111
// DEC stuff
130
112
int degreeDEC;
@@ -134,19 +116,13 @@ float moveDEC;
134
116
int DECselect;
135
117
int printdegDEC;
136
118
137
- // Hour correction
138
- int hourHA = 0 ;
139
- int minHA = 0 ;
119
+ // Hour stuff
140
120
int HAselect;
141
- int hHAcorrection;
142
- int mHAcorrection = -5 ; // wenn minus dann hHAcorrection -1
143
- int sHAcorrection ;
144
- int hourHAzeit;
145
- int minHAzeit;
146
121
147
- int heatselect;
148
- int RAheat = 0 ;
149
- int DECheat = 1 ;
122
+ // HEAT menu settings
123
+ int heatselect; // Which stepper are we changing?
124
+ int RAheat = 0 ; // Are we heating the RA stepper?
125
+ int DECheat = 0 ; // Are we heating the DEC stepper?
150
126
151
127
// Stellarium
152
128
char current_RA[9 ];
@@ -156,10 +132,11 @@ int HAm_save;
156
132
float slew_RA;
157
133
float slew_DEC;
158
134
159
- int rightArrow = 4 ;
135
+ // LCD special chars
160
136
int leftArrow = 3 ;
137
+ int rightArrow = 4 ;
161
138
162
- byte DEG [8 ] = {
139
+ byte DegreesBitmap [8 ] = {
163
140
B01100,
164
141
B10010,
165
142
B10010,
@@ -170,7 +147,7 @@ byte DEG[8] = {
170
147
B00000
171
148
};
172
149
173
- byte min [] = {
150
+ byte MinutesBitmap [] = {
174
151
B10000,
175
152
B10000,
176
153
B10000,
@@ -181,7 +158,7 @@ byte min[] = {
181
158
B00000
182
159
};
183
160
184
- byte sec [] = {
161
+ byte SecondsBitmap [] = {
185
162
B10100,
186
163
B10100,
187
164
B10100,
0 commit comments