Некая проблемка с Arduino Uno

короче у меня уже есть схема и есть код, мне надо их всего лишь соотнести друг с другом, а именно чтобы при нажатии каждой кнопки работал один из моторов или сервоприводов

Вот схема: https://www.tinkercad.com/things/bi6fvCoiIzo-incredible-kieran-amur/editel?sharecode=QUt-vuq5nHt5vcqMFlY3c7xFGTuZbD4RMieCT8TLCic

введите сюда описание изображения

Вот код:

// Define the pins for the DC motors and micro servos
int motor1Pin1 = 2;
int motor1Pin2 = 3;
int motor2Pin1 = 4;
int motor2Pin2 = 5;
int servo1Pin = 6;
int servo2Pin = 7;

// Define the pins for the buttons
int button1Pin = 8;
int button2Pin = 9;
int button3Pin = 10;
int button4Pin = 11;

// Define the variables for the button states
int button1State = 0;
int button2State = 0;
int button3State = 0;
int button4State = 0;

void setup() {
  // Initialize the pins for the DC motors and micro servos as output
  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT);
  pinMode(motor2Pin1, OUTPUT);
  pinMode(motor2Pin2, OUTPUT);
  pinMode(servo1Pin, OUTPUT);
  pinMode(servo2Pin, OUTPUT);

  // Initialize the pins for the buttons as input with internal pull-up resistor
  pinMode(button1Pin, INPUT_PULLUP);
  pinMode(button2Pin, INPUT_PULLUP);
  pinMode(button3Pin, INPUT_PULLUP);
  pinMode(button4Pin, INPUT_PULLUP);
}

void loop() {
  // Read the state of the buttons
  button1State = digitalRead(button1Pin);
  button2State = digitalRead(button2Pin);
  button3State = digitalRead(button3Pin);
  button4State = digitalRead(button4Pin);

  // Control the DC motors and micro servos based on the button states
  if (button1State == LOW) {
    // Move DC motor 1 forward
    digitalWrite(motor1Pin1, HIGH);
    digitalWrite(motor1Pin2, LOW);
  } else if (button2State == LOW) {
    // Move DC motor 1 backward
    digitalWrite(motor1Pin1, LOW);
    digitalWrite(motor1Pin2, HIGH);
  } else {
    // Stop DC motor 1
    digitalWrite(motor1Pin1, LOW);
    digitalWrite(motor1Pin2, LOW);
  }

  if (button3State == LOW) {
    // Move DC motor 2 forward
    digitalWrite(motor2Pin1, HIGH);
    digitalWrite(motor2Pin2, LOW);
  } else if (button4State == LOW) {
    // Move DC motor 2 backward
    digitalWrite(motor2Pin1, LOW);
    digitalWrite(motor2Pin2, HIGH);
  } else {
    // Stop DC motor 2
    digitalWrite(motor2Pin1, LOW);
    digitalWrite(motor2Pin2, LOW);
  }

  if (button1State == LOW) {
    // Move micro servo 1 to position 1
    digitalWrite(servo1Pin, HIGH);
    delay(1000);
    digitalWrite(servo1Pin, LOW);
  }

  if (button2State == LOW) {
    // Move micro servo 1 to position 2
    digitalWrite(servo1Pin, HIGH);
    delay(2000);
    digitalWrite(servo1Pin, LOW);
  }

  if (button3State == LOW) {
    // Move micro servo 2 to position 1
    digitalWrite(servo2Pin, HIGH);
    delay(1000);
    digitalWrite(servo2Pin, LOW);
  }

  if (button4State == LOW) {
    // Move micro servo 2 to position 2
    digitalWrite(servo2Pin, HIGH);
    delay(2000);
    digitalWrite(servo2Pin, LOW);
  }
}

Ответы (0 шт):