11// If you really want to look through this code, i apologise for my terrible coding
22// #include <SoftwareSerial.h>
3+ #include < stdarg.h>
34#include < EEPROM.h>
45#include < AccelStepper.h>
56#include < LiquidCrystal.h>
67#include < SoftwareSerial.h>
8+
79#define HALFSTEP 8
810#define FULLSTEP 4
911
1012LiquidCrystal lcd (8 , 9 , 4 , 5 , 6 , 7 );
1113// SoftwareSerial BT(10,11);
1214
15+ // RA Motor pins
1316#define motorPin1 2 // IN1 auf ULN2003 driver 1 // 2 / 22
1417#define motorPin2 3 // IN2 auf ULN2003 driver 1 // 3 / 24
1518#define motorPin3 11 // IN3 auf ULN2003 driver 1 // 11 / 26
1619#define motorPin4 12 // IN4 auf ULN2003 driver 1 // 12 / 28
1720
21+ // DEC Motor pins
1822#define motorPin11 15 // IN1 auf ULN2003 driver 2
1923#define motorPin12 16 // IN2 auf ULN2003 driver 2
2024#define motorPin13 17 // IN3 auf ULN2003 driver 2
2125#define motorPin14 18 // IN4 auf ULN2003 driver 2
2226
27+ // LCD shield buttons
2328#define btnRIGHT 0
2429#define btnUP 1
2530#define btnDOWN 2
2631#define btnLEFT 3
2732#define btnSELECT 4
2833#define btnNONE 5
2934
30- int lcd_key = 0 ;
31- int adc_key_in = 0 ;
32- int read_LCD_buttons () {
33- adc_key_in = analogRead (0 );
34- if (adc_key_in > 1000 ) return btnNONE;
35- if (adc_key_in < 50 ) return btnRIGHT;
36- if (adc_key_in < 250 ) return btnUP;
37- if (adc_key_in < 450 ) return btnDOWN;
38- if (adc_key_in < 600 ) return btnLEFT;
39- if (adc_key_in < 920 ) return btnSELECT;
40- // return btnNONE;
41- }
42-
43- String inString = " " ;
44-
35+ // Menu IDs
36+ #define RA_Menu 0
37+ #define DEC_Menu 1
38+ #define HA_Menu 2
39+ #define Polaris_Menu 3
40+ #define Heat_Menu 4
41+ #define Calibration_Menu 5
42+ #define Control_Menu 6
43+ #define Home_Menu 7
44+ #define POI_Menu 8
45+
46+ // Stepper control for RA and DEV.
47+ // TRK is used for live tracking and runs in parallel with RA.
48+ // GUIDE is used for Stellarium control
4549AccelStepper stepperRA (FULLSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
4650AccelStepper stepperDEC (HALFSTEP, motorPin11, motorPin13, motorPin12, motorPin14);
4751AccelStepper stepperTRK (HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4); // yes, this is the same motor as stepperRA, dont ask why
4852AccelStepper stepperGUIDE (HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
4953
54+ int lcd_key = 0 ; // The current key state
55+ int adc_key_in = 0 ; // The analog value of the keys
56+
57+ String inString = " " ;
58+
59+ bool inStartup = true ; // Start with a guided startup
60+
61+ int calDelay = 150 ; // The current delay when changing calibration value. The longer a button is depressed, the samller this gets.
62+
63+ bool waitForButtonRelease = false ; // When a button is pressed should we wait for its release before another loop?
64+
65+ // Variables for use in the CONTROL menu
66+ int StateMaskDEC = 0x0011 ; // Is the DEC stepper running?
67+ int StateMaskUp = 0x0001 ; // Is the DEC stepper moving upwards?
68+ int StateMaskDown = 0x0010 ; // Is the DEC stepper moving downwards?
69+ int StateMaskRA = 0x1100 ; // Is the RA stepper running?
70+ int StateMaskLeft = 0x0100 ; // Is the RA stepper moving left (CW)?
71+ int StateMaskRight = 0x1000 ; // Is the RA stepper moving right (CCW)?
72+
73+ int controlState = 0x0000 ; // The current state of the steppers (combination of above values)
74+ int controlDisplay = 0 ; // How many loop cycles left before updating the display
75+ bool inControlMode = false ; // Is manual control enabled
76+
77+ int lastKey = btnNONE; // The key state when we last came through the loop
78+
79+ float totalDECMove = 0 ; // The number of DEC steps we asked for
80+ float totalRAMove = 0 ;
81+ bool isUnreachable = false ;
82+
5083// String inCmd;
5184// String inputString = "";
5285// String commandString = "";
@@ -58,10 +91,9 @@ String logString;
5891boolean isPulseGuiding = true ;
5992
6093unsigned long Zeit;
61- float onehour ;
94+ float stepsPerHour ;
6295
6396boolean pcControl = false ;
64- int menu = 2 ;
6597int currentSecs;
6698int currentMins;
6799float inputcal;
@@ -75,15 +107,9 @@ int mPolarisPosition;
75107int tracking = 1 ;
76108float trackingspeed;
77109
78- // RA stuff
79- float hourRA;
80- float minRA = 0 ;
81- float secRA = 0 ;
110+ // RA stuff
82111float moveRA;
83112int RAselect;
84- int hourRAprint;
85- int minRAprint;
86- int secRAprint;
87113
88114// DEC stuff
89115int degreeDEC;
@@ -93,29 +119,27 @@ float moveDEC;
93119int DECselect;
94120int printdegDEC;
95121
96- // Hour correction
97- int hourHA = 0 ;
98- int minHA = 0 ;
122+ // Hour stuff
99123int HAselect;
100- int hHAcorrection;
101- int mHAcorrection = -5 ; // wenn minus dann hHAcorrection -1
102- int sHAcorrection ;
103- int hourHAzeit;
104- int minHAzeit;
105124
106- int heatselect;
107- int RAheat = 0 ;
108- int DECheat = 1 ;
125+ // HEAT menu settings
126+ int heatselect; // Which stepper are we changing?
127+ int RAheat = 0 ; // Are we heating the RA stepper?
128+ int DECheat = 0 ; // Are we heating the DEC stepper?
109129
110- // Stellarium
130+ // Stellarium
111131char current_RA[9 ];
112132char current_DEC[10 ];
113133int HAh_save;
114134int HAm_save;
115135float slew_RA;
116136float slew_DEC;
117137
118- byte DEG[8 ] = {
138+ // LCD special chars
139+ int leftArrow = 3 ;
140+ int rightArrow = 4 ;
141+
142+ byte DegreesBitmap[8 ] = {
119143 B01100,
120144 B10010,
121145 B10010,
@@ -126,7 +150,7 @@ byte DEG[8] = {
126150 B00000
127151};
128152
129- byte min [] = {
153+ byte MinutesBitmap [] = {
130154 B10000,
131155 B10000,
132156 B10000,
@@ -137,7 +161,7 @@ byte min[] = {
137161 B00000
138162};
139163
140- byte sec [] = {
164+ byte SecondsBitmap [] = {
141165 B10100,
142166 B10100,
143167 B10100,
@@ -148,6 +172,5 @@ byte sec[] = {
148172 B00000
149173};
150174
151-
152175// debugging
153176String inBT;
0 commit comments