if-Bedingung+Pushbutton Servo,SM kontrollieren

so danke erstmal für deine Hilfe :slight_smile:

habe das ganze im Prinzip nun am laufen, jedoch dreht sich der Stepper einfach weiter ....^^ er steht einfach nicht, ich denke aber der Code sollte passen soweit, denn mit dem Poti Steuere ich meinen Servo ohne Probleme und bei Tastendruck läuft der DC-Motor.

Einzig was noch fehlt ist der Stepper.

Anbei der momentane Code:

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"

#include <Servo.h>

//feste Variablen

const int buttonPin = 2;     // buttonPin für DC-Motor
const int button1Pin = 4;      // buttonPin für Schritt vorwärts
const int button2Pin = 7;     // buttonPin für Schritt rückwärts
const int ledPin =  13;      // the number of the LED pin

//veränderbare Variablen

int buttonState = 0;         // variable for reading the pushbutton status
int button1State = 0;         // variable for reading the pushbutton status
int button2State = 0;         // variable for reading the pushbutton status

int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin

//Allgemeine Zuweisung des Shields

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); 

//DC-Motor

// Select which 'port' M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *myMotor = AFMS.getMotor(3);
// You can also make another motor on port M2
//Adafruit_DCMotor *myOtherMotor = AFMS.getMotor(2);

// Connect a stepper motor with 64 steps per revolution 
// to motor port #1
Adafruit_StepperMotor *myStepper = AFMS.getStepper(64, 1);

//SERVO
// We'll also test out the built in Arduino Servo library
Servo servo1;


void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Adafruit Motorshield v2 - DC Motor test!");

  AFMS.begin();  // create with the default frequency 1.6KHz
  //AFMS.begin(1000);  // OR with a different frequency, say 1KHz

  // Attach a servo to pin #10
  servo1.attach(10);
   
  
// Set the speed to start, from 0 (off) to 255 (max speed)
  myMotor->setSpeed(150);
  myMotor->run(FORWARD);

//Umdrehungen pro Minute für Stepper

 //myStepper->setSpeed(5); 
  
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  button1State = digitalRead(button1Pin);
  button2State = digitalRead(button2Pin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
    myMotor->run(FORWARD);
     myMotor->setSpeed(150); 
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
     myMotor->setSpeed(0); 
  }

  if (button1State == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
      myStepper->step(10, FORWARD, DOUBLE); 
  
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
    myStepper->step(0,FORWARD,DOUBLE);
     
  }

  if (button2State == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
    myStepper->step(10, BACKWARD, DOUBLE); 
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
     myStepper->step(0,FORWARD,DOUBLE); 
  }

val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  servo1.write(val);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there

}

ich muss dazu noch erwähnen das wenn ich lediglich einen Button für den SChrittmotor verwende (vorwärts Schritt) so steht der Stepper und ich kann gemütlich per tastendruck immer einen Schritt weiter gehen.

Was muss ich noch berücksichtigen damit das mit dem Schrittmotorfür rückwärts funktioniert?

Edit:
Funktioniert genau mit diesem Code :slight_smile:
hatte Pin 6 u. 7 verbunden gehabt über das Zinn, habs neu gelötet und jetzt klappt es!!