-
Notifications
You must be signed in to change notification settings - Fork 25
/
ArduinoCode.ino
executable file
·118 lines (112 loc) · 2.77 KB
/
ArduinoCode.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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// This file is part of Arduino ST4.
//
// Arduino ST4 is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Arduino ST4 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
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Arduino ST4. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright Kevin Ferrare 2014
/*
* Led indicates whether the software requested connection, it is shut off when the software disconnects
*/
const int pinLED = 13;
/**
* An axis has a pin per direction.
* Both pins cannot be up at the same time.
*/
class Axis {
private:
int plusPin;
int minusPin;
public:
Axis(int plusPin, int minusPin) :
plusPin(plusPin), minusPin(minusPin) {
}
void setupPins(){
pinMode(this->plusPin, OUTPUT);
pinMode(this->minusPin, OUTPUT);
}
void plus(){
digitalWrite(this->minusPin, LOW);
digitalWrite(this->plusPin, HIGH);
}
void minus(){
digitalWrite(this->plusPin, LOW);
digitalWrite(this->minusPin, HIGH);
}
void reset(){
digitalWrite(this->minusPin, LOW);
digitalWrite(this->plusPin, LOW);
}
};
class Axis rightAscension(
2,//RA+ pin
5);//RA- pin
class Axis declination(
3,//DEC+ pin
4);//DEC- pin
void setup()
{
rightAscension.setupPins();
declination.setupPins();
pinMode(pinLED, OUTPUT);
//57.6k, 8 data bits, no parity, one stop bit.
Serial.begin(57600, SERIAL_8N1);
//Wait for serial port to connect. Needed for Leonardo only
while (!Serial);
Serial.println("INITIALIZED#");
}
void resetPins(){
rightAscension.reset();
declination.reset();
}
void loop()
{
if (Serial.available() > 0) {
//Received something
String opcode = Serial.readStringUntil('#');
boolean validOpcode=true;
//Parse opcode
if(opcode=="CONNECT"){
digitalWrite(pinLED, HIGH);
resetPins();
}
else if (opcode=="DISCONNECT"){
digitalWrite(pinLED, LOW);
resetPins();
}
else if(opcode=="RA0"){
rightAscension.reset();
}
else if(opcode=="RA+"){
rightAscension.plus();
}
else if(opcode=="RA-"){
rightAscension.minus();
}
else if(opcode=="DEC0"){
declination.reset();
}
else if(opcode=="DEC+"){
declination.plus();
}
else if(opcode=="DEC-"){
declination.minus();
}
else{
validOpcode=false;
}
if(validOpcode){
//Acknowledge valid command
Serial.println("OK#");
}
}
}