Arduino Polska Forum
Witam i proszę o pomoc - Wersja do druku

+- Arduino Polska Forum (https://forum.arduinopolska.pl)
+-- Dział: Start (https://forum.arduinopolska.pl/dzial-start)
+--- Dział: Przywitanie (https://forum.arduinopolska.pl/dzial-przywitanie)
+--- Wątek: Witam i proszę o pomoc (/watek-witam-i-prosz%C4%99-o-pomoc)



Witam i proszę o pomoc - PAWSET - 27-02-2022

Witam.

Mam taki kod i nie wiem co dalej zrobić. Chodzi mi o to żeby po naciśnięciu przycisku silnik obrócił się o zadaną ilość kroków i następnie się zatrzymał. Proszę o pomoc!!!!!!

Kod:
// Include the AccelStepper library:
#include <AccelStepper.h>
// Define stepper motor connections and motor interface type. Motor interface type must be set to 1 when using a driver:
#define dirPin 2
#define stepPin 3
#define motorInterfaceType 1
int btn1 = 5;

// Create a new instance of the AccelStepper class:
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
void setup() {
  // Set the maximum speed and acceleration:
  stepper.setMaxSpeed(8000);
  stepper.setAcceleration(500);
pinMode(btn1,INPUT);

}
void loop() {
if(digitalRead(btn1) == HIGH);
  stepper.moveTo(32000);
  stepper.runToPosition();
}



RE: Witam i proszę o pomoc - Jarewa0606 - 27-02-2022

My też nie wiemy co chcesz zrobić...


RE: Witam i proszę o pomoc - kaczakat - 27-02-2022

Brak schematu, wg Twojego kodu przycisk powinien zwierać pin btn1 do VCC, a pin btn1 powinien być podłączony rezystorem 10k na stałe do GND.
Kod:
/ Include the AccelStepper library:
#include <AccelStepper.h>
// Define stepper motor connections and motor interface type. Motor interface type must be set to 1 when using a driver:
#define dirPin 2
#define stepPin 3
#define motorInterfaceType 1
int btn1 = 5;
bool start;

// Create a new instance of the AccelStepper class:
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
void setup() {
  // Set the maximum speed and acceleration:
  stepper.setMaxSpeed(8000);
  stepper.setAcceleration(500);
pinMode(btn1,INPUT);

}
void loop() {
if(digitalRead(btn1) == HIGH) start=1;
if(start)

stepper.moveTo(32000);
stepper.runToPosition();
}
}
Natomiast nie wiem co tu sobie poustawiałeś za prędkości i przyspieszenia, nie każdy silnik da z tym radę. Ale rozumiem, że jakkolwiek to już działa, silnik kręcił i reszta była OK.