#include <SoftwareSerial.h>
// Definiáljuk a másik sorosportot (RX, TX)
SoftwareSerial mySerial(10, 11);
String gcodeLine = "";
float x = 0, y = 0, z = 0;
bool onlySendFlag=0;
void setup() {
Serial.begin(9600); // Alapértelmezett sorosport sebessége
mySerial.begin(9600); // Másik sorosport sebessége
Serial.println("Joe");
}
void loop() {
while (Serial.available() > 0) {
char c = Serial.read();
if (c == '\n') {
processGCode(gcodeLine);
gcodeLine = "";
} else {
gcodeLine += c;
}
}
}
void processGCode(String line) {
if (line.startsWith("G")) {
onlySendFlag=1;
int gcodeIndex = line.indexOf('G');
String gcode = line.substring(gcodeIndex + 1, gcodeIndex + 3);
int command = gcode.toInt();
if (command == 0 || command == 1) { // G0 vagy G1 parancsok
if (line.indexOf('X') >= 0) {
int xIndex = line.indexOf('X');
int nextSpace = line.indexOf(' ', xIndex);
x = line.substring(xIndex + 1, nextSpace).toFloat();
}
if (line.indexOf('Y') >= 0) {
int yIndex = line.indexOf('Y');
int nextSpace = line.indexOf(' ', yIndex);
y = line.substring(yIndex + 1, nextSpace).toFloat();
}
if (line.indexOf('Z') >= 0) {
int zIndex = line.indexOf('Z');
int nextSpace = line.indexOf(' ', zIndex);
z = line.substring(zIndex + 1, nextSpace).toFloat();
}
sendCoordinates();
}
}
else
if(onlySendFlag==0){
Serial.println("csak tovabbit serial2 felé");
Serial.println(line);
}
if(onlySendFlag==1 && line.startsWith("OK"))
{
Serial.println("OnlySendflag=1 and CheckThe encoder");
onlySendFlag=0;
}
}
void sendCoordinates() {
String coordinates = "X: " + String(x) + " Y: " + String(y) + " Z: " + String(z);
Serial.println(coordinates);
//mySerial.println(coordinates); // Küldés a másik sorosportra
}
nano:12
nano:11
nano:10
nano:9
nano:8
nano:7
nano:6
nano:5
nano:4
nano:3
nano:2
nano:GND.2
nano:RESET.2
nano:0
nano:1
nano:13
nano:3.3V
nano:AREF
nano:A0
nano:A1
nano:A2
nano:A3
nano:A4
nano:A5
nano:A6
nano:A7
nano:5V
nano:RESET
nano:GND.1
nano:VIN
nano:12.2
nano:5V.2
nano:13.2
nano:11.2
nano:RESET.3
nano:GND.3