29-12-2022, 08:06
(Ten post był ostatnio modyfikowany: 29-12-2022, 08:21 przez Jarewa0606.)
Kod:
* Unipolar stepper motor speed and direction control with Arduino
* and joystick
* This is a free software with NO WARRANTY.
* https://simple-circuit.com/
*/
// include Arduino stepper motor library
#include <Stepper.h>
// define number of steps per revolution
#define STEPS 32
// define stepper motor control pins
#define IN1 11
#define IN2 10
#define IN3 9
#define IN4 8
// initialize stepper library
Stepper stepper(STEPS, IN4, IN2, IN3, IN1);
// joystick pot output is connected to Arduino A0
#define joystick A0
void setup()
{
}
void loop()
{
// read analog value from the potentiometer
int val = analogRead(joystick);
val = constrain(val,5,1024);
// if the joystic is in the middle ===> stop the motor
if(val < 10 )
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
else[
{
//
while (val >= 10)
{
// map the speed between 5 and 500 rpm
int speed_ = map(val, 10, 1024, 5, 1000);
// set motor speed
stepper.setSpeed(speed_);
// move the motor (1 step);
stepper.step(1);
val = analogRead(joystick);
val = constrain(val,5,1024);
}
}
}
Do prędkości zmieniaj liczbę ostatnie 1000 gdyby nie działało to zmień jak było na 500. Poszukaj po prostu max prędkość jaka będzie działać. Ja już podkręciłem 2X
int speed_ = map(val, 10, 1024, 5, 1000);
Arduino zostało wymyślone po to, by robić dobrze jedną prostą rzecz – migać diodą.