Hallo, ich weiss es ist viel verlangt aber eventuelle hat doch jmd Lust und Zeit sich folgenden Code einmal anzusehen -währe echt dankbar.
Syntax ist lt. der IDE richtig aber kann das von der Logik so funktionieren ??
es soll mittels RPM1 bis 4 ein Vorschub eingestellt werden ( nur jeweils 1 Taster )
S_* sind endschalter
M_* sind Steuerleitungen zum Motortreiber
#include <AccelStepper.h>
AccelStepper Motor(AccelStepper::DRIVER, 31, 33);
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 20 chars and 4 line display
// Eingänge
const int S_Links_Pin = 53;
const int S_Rechts_Pin = 51;
const int Links_Pin = 49;
const int Rechts_Pin = 47;
const int Man_Pin = 45;
const int RPM1 = 43;
const int RPM2 = 41;
const int RPM3 = 39;
const int RPM4 = 37;
//Ausgänge
const int M_ENA = 35;
const int M_DIR = 33;
const int M_PUL = 31;
// Variabeln
float current_speed = 0.0;
int Status = 0;
void setup()
{
digitalWrite(M_ENA, HIGH); // Entstufe abgeschaltet
// Set up the button inputs, with pullups
pinMode(S_Links_Pin, INPUT_PULLUP);
pinMode(S_Rechts_Pin, INPUT_PULLUP);
pinMode(Links_Pin, INPUT_PULLUP);
pinMode(Rechts_Pin, INPUT_PULLUP);
pinMode(Man_Pin, INPUT_PULLUP);
pinMode(RPM1, INPUT_PULLUP);
pinMode(RPM2, INPUT_PULLUP);
pinMode(RPM3, INPUT_PULLUP);
pinMode(RPM3, INPUT_PULLUP);
lcd.init(); // initialize the lcd
lcd.setCursor(3, 0);
lcd.print("Vorschub: 0 M/Minute");
lcd.setCursor(3, 2);
lcd.print("Betrieb: ");
}
void loop()
{
// Holds current motor speed in steps/second
static char sign = 0; // Holds -1, 1 or 0 to turn the motor on/off and control direction
if (digitalRead(Man_Pin) == 0 ) {
current_speed = 0;
digitalWrite(M_ENA, HIGH);
lcd.setCursor(12, 2);
lcd.print("Manuell");
delay(500);
}
if (digitalRead(RPM1) == 0 && digitalRead(RPM2) == 1 && digitalRead(RPM3) == 1 && digitalRead(RPM4) == 1) { // Vorschub 1,8 M/min
current_speed = 8000;
lcd.setCursor(3, 0);
lcd.print("Vorschub: 1,8 M/Minute");
}
if (digitalRead(RPM1) == 1 && digitalRead(RPM2) == 0 && digitalRead(RPM3) == 1 && digitalRead(RPM4) == 1) { // Vorschub 3,6 M/min
current_speed = 16000;
lcd.setCursor(3, 0);
lcd.print("Vorschub: 3,6 M/Minute");
}
if (digitalRead(RPM1) == 1 && digitalRead(RPM2) == 1 && digitalRead(RPM3) == 0 && digitalRead(RPM4) == 1) { // Vorschub 5,4 M/min
current_speed = 24000;
lcd.setCursor(3, 0);
lcd.print("Vorschub: 5,4 M/Minute");
}
if (digitalRead(RPM1) == 1 && digitalRead(RPM2) == 1 && digitalRead(RPM3) == 1 && digitalRead(RPM4) == 0) { // Vorschub 7,0 M/min
current_speed = 32000;
lcd.setCursor(3, 0);
lcd.print("Vorschub: 7,0 M/Minute");
}
if (digitalRead(S_Links_Pin) == 1 or digitalRead(S_Rechts_Pin) == 1) {
Motor.stop();
delay(1000);
Status = 0;
}
if ( digitalRead(Links_Pin) == 0 && digitalRead(Rechts_Pin) == 1 && digitalRead(S_Rechts_Pin) == 1 && Status == 0) {
Status = 1;
current_speed = current_speed * 1;
digitalWrite(M_ENA, LOW);
lcd.setCursor(3, 3);
lcd.print("läuft links");
}
if ( digitalRead(Rechts_Pin) == 0 && digitalRead(Links_Pin) == 1 && digitalRead(S_Links_Pin) == 1 && Status == 0) {
Status = 2;
current_speed = current_speed * -1;
digitalWrite(M_ENA, LOW);
lcd.setCursor(3, 3);
lcd.print("läuft rechts");
}
Motor.setSpeed(current_speed);
Motor.run();
}