-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrobi_v01.ino
191 lines (154 loc) · 4.35 KB
/
trobi_v01.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// Schrittmotor --------------------------------
#include <AccelStepper.h>
#define dirPin 8
#define stepPin 9
#define motorInterfaceType 1
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
// Gleichstrommotor 1 - Ballmixer 1
int GSM1 = 7; // PWM Pin
int in1 = 20;
int in2 = 21;
// Gleichstrommotor 2 - Ballmixer 2
int GSM2 = 6; //PWM Pin
int in3 = 22;
int in4 = 23;
// Bluetooth --------------------------------
//#include <SoftwareSerial.h>
//Serial BT(5, 6);
String a;
String b;
String c;
int d;
// Servo --------------------------------
#include <Servo.h>
Servo myservoA;
Servo myservoB;
Servo myservoC;
const int myservoA_Center = 1450; // Mittelposition Servo A
const int myservoB_Center = 1400; // Mittelposition Servo B
const int myservoC_Center = 1500; // Mittelposition Servo C
int pos = 0;
// Servo ESC Brushless ------------------
Servo myservo_ESC_A;
Servo myservo_ESC_B;
// ------------------------------------------
void setup() {
Serial.begin(9600);
Serial1.begin(9600); // serial port 1
// Motoren für Ballmixer - Drehzahl 0
analogWrite(GSM1, 0);
analogWrite(GSM2, 0);
pinMode(GSM1, OUTPUT);
pinMode(GSM2, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
// Servo Rotation Kopf Drehung----------------------
myservoA.attach(2);
myservoA.writeMicroseconds(myservoA_Center);
delay(1000);
// Servo Rotation Kopf Neigung----------------------
myservoB.attach(3);
myservoB.writeMicroseconds(myservoB_Center);
delay(1000);
// Servo Rotation Turm ----------------------
myservoC.attach(4);
myservoC.writeMicroseconds(myservoC_Center);
delay(1000);
// Servo ESC Brushless ------------------
myservo_ESC_A.attach(14); // BackSpin
myservo_ESC_B.attach(15); // TopSpin
// Bluetooth --------------------------------
//BT.begin(9600);
//BT.println("Hello from Arduino");
// Schrittmotor ----------------------------
stepper.setMaxSpeed(8000);
stepper.setSpeed(0);
// Microstepping ----------------------------
// Low Low Low Full step
// High Low Low Half step
// Low High Low 1/4 step
// High High Low 1/8 step
// Low Low High 1/16 step
// High Low High 1/32 step
// Low High High 1/32 step
// High High High 1/32 step
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);
pinMode(11, OUTPUT);
digitalWrite(11, HIGH);
pinMode(12, OUTPUT);
digitalWrite(12, HIGH);
}
void loop() {
stepper.runSpeed();
digitalWrite(in1, HIGH); // Motor 1 beginnt zu rotieren
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH); // Motor 2 beginnt zu rotieren
digitalWrite(in4, LOW );
if (Serial1.available())
{
a=Serial1.readString();
b = a.substring(0,1);
c = a.substring(1);
d = c.toInt();
if ((b=="M" || b=="m"))
{
Serial.println(a);
Serial.println(b);
Serial.println(c);
stepper.setSpeed(d);
analogWrite(GSM1, 50);
analogWrite(GSM2, 50);
}
if ((b=="O" || b=="o"))
{
Serial.println(a);
Serial.println(b);
Serial.println(c);
myservoA.writeMicroseconds(d);
}
if ((b=="P" || b=="p"))
{
Serial.println(a);
Serial.println(b);
Serial.println(c);
myservoB.writeMicroseconds(d);
}
if ((b=="Q" || b=="q"))
{
Serial.println(a);
Serial.println(b);
Serial.println(c);
myservoC.writeMicroseconds(d);
}
if ((b=="T" || b=="t"))
{
Serial.println(a);
Serial.println(b);
Serial.println(c);
myservo_ESC_A.writeMicroseconds(d);
}
if ((b=="B" || b=="b"))
{
Serial.println(a);
Serial.println(b);
Serial.println(c);
myservo_ESC_B.writeMicroseconds(d);
}
if ((b=="X" || b=="x")) // Stop
{
stepper.setSpeed(0);
myservo_ESC_A.writeMicroseconds(0);
myservo_ESC_B.writeMicroseconds(0);
analogWrite(GSM1, 0);
analogWrite(GSM2, 0);
}
else
{
//BT.println("NULL");
//stepper.setSpeed(0);
}
}
}