Hier mein geänderter code zur section control per arduino:
Dieser Code verwendet nicht den SDOSE Befehl für die externe Markierung weil damit nicht in Auto gefahren werden kann.
Es sind die Zeilen mit SDOSE auskommentiert und einfach durch Marc ersetzt worden. (Also eigentlich nur ein Provisorium eines Programmierlaien...)
Code
// Arduino Cerea Teilbreitenschaltung
// (C) 2016 by Andreas Ortner - office@gh-ortner.com
// Weitergabe an Dritte nur unter Erlaubniss von Andreas Ortner
// geändert von Michael K.
// Version 2017 provisorium 1!
String cmd;
char nextChar;
String teilbreite;
int anztb ;
int i;
int sensorVal;
int lsensorVal;
void setup() {
Serial.begin(9600);
pinMode(2, OUTPUT); //Teilbreite 1 Pin 2
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT); // Teilbreite 7 Pin 8
pinMode(9, OUTPUT); // Pin 9 Hydraulik Befehl
pinMode(10, INPUT_PULLUP); // Marcar ein oder aus
digitalWrite(2, HIGH); // alle Ports of 0 = HIGH Setzten
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
}
void loop()
{
cmd = ""; // String leeren
ser(); // Commando einleisen
if (cmd.startsWith("@CEREA;")) { // Wenn Cerea entdeckt wird mit ausführung starten
cerea();
}
if (cmd.startsWith("@HIDRAU")) { // Wenn Hidrau entdeckt wird mit ausführung starten
hidrau(); // evt. hier entferenen um Hyraulik nicht zu nutzten
}
//neues Komando. WECHSELT den ZUSTAND des MArkierungsknopfes in Cerea.
//@MARC Simuliert das drücken der der Marc Taste.
//@AUTO simuliert das drücken der Auto taste
sensorVal = digitalRead(10); // pin 10 Abfragen
if (sensorVal == HIGH && sensorVal != lsensorVal) {
//Serial.print ("@SDOSE;1;0;0;0;0;0;0;0;0;0;0;END"); //wenn Kontakt frei Marc ein //auskommentiert weil erstzt
Serial.print ("@MARC"); // neues Komando. WECHSELT den ZUSTAND des MArkierungsknopfes in Cerea.
Serial.print ('\r');
Serial.print ('\n');
lsensorVal= sensorVal;
} else if (sensorVal == LOW && sensorVal != lsensorVal)
{
//Serial.print ("@SDOSE;0;0;0;0;0;0;0;0;0;0;0;END"); //wenn Kontakt auf GND Marc aus //auskommentiert weil erstzt
Serial.print ("@MARC"); // neues Komando. WECHSELT den ZUSTAND des MArkierungsknopfes in Cerea.
Serial.print ('\r');
Serial.print ('\n');
lsensorVal= sensorVal;
}
}
void cerea() //String auswerten
{
cmd.remove(0, 7); // @Cerea; entferenen
int first = cmd.indexOf(';'); // erstem ; suchen
int second = cmd.indexOf(';', first + 1 ); // zweiten ; suchen
cmd.remove(0, second + 1); //geschwindigkeit und minus 1 entferene
int ende = cmd.indexOf('END'); //sucht nach "end"
anztb = (ende - 2) / 2; //anzahl teilbreiten ermitteln
teilbreite = cmd.substring(0, ende - 3); //teilbreiten in einen neuen string
int b = 1;
for (i = 0; i < anztb * 2 ; i = i + 2) { //teilbreiten schalten
b = b + 1;
if (teilbreite.substring(i, i + 1) == "1") digitalWrite(b, LOW); //Teilbreite einschalten
if (teilbreite.substring(i, i + 1) == "0" ) digitalWrite(b, HIGH); //Teilbreite ausschalten
}
for (i = anztb + 1 ; i < 8; i++) { // restlichen teilbreiten aus
digitalWrite(i + 1, HIGH);
}
}
void hidrau()
{
int ende = cmd.indexOf('EN'); //sucht nach "end"
cmd.remove(0, ende - 3); // rest entfernen
if (cmd.substring(0, 1) == "1") {
digitalWrite(9, LOW); //hyro ein --> hier low mit high ersetzten falls hydro nicht gewünscht wird
}
if (cmd.substring(0, 1) == "0") {
digitalWrite(9, HIGH); //hyro aus
}
}
void ser() // Serielle Schnittstelle bis Return lesen
{
do {
if (Serial.available() > 0)
{
nextChar = Serial.read();
if (nextChar >= 32) {
cmd += nextChar;
}
}
} while (nextChar != 10); //solange lesen bis zeilenende
}
Alles anzeigen