Może ustawiasz złą prędkość/przyspieszenie. Jak miałem takie silniczki za 1$ to tylko się grzały w bezruchu jak się ustawiło coś za dużo.
To powinno działać, ale nie mam aktualnie żadnego krokowca pod ręką, ustaw swoje piny, akurat na tych miałem ledy:
To powinno działać, ale nie mam aktualnie żadnego krokowca pod ręką, ustaw swoje piny, akurat na tych miałem ledy:
Kod:
#include <AccelStepper.h>
const int stepPin1 = 4; // Silnik nr 1 ruch poziomy
const int dirPin1 = 6;
const int stepPin2 = 5; //Silnik nr 2 ruch obrotowy głowicy
const int dirPin2 = 8;
AccelStepper stepper1 = AccelStepper(1, stepPin1, dirPin1);
AccelStepper stepper2 = AccelStepper(1, stepPin2, dirPin2);
uint32_t czasTeraz,czasPoprzedni,tik=10;
uint8_t nTik,sekundy,minuty,godziny,dni;
bool fnTik,fsekundy,fminuty,fgodziny,fdni;
char napis[64];
void setup() {
Serial.begin(115200);
stepper1.setMaxSpeed(100);
stepper1.setAcceleration(50);
stepper1.moveTo(100);
stepper2.setMaxSpeed(300);
stepper2.setAcceleration(100);
stepper2.moveTo(100);
}
void loop()
{
czas();
if (stepper1.distanceToGo() ==0) stepper1.moveTo (stepper1.currentPosition()-50) ;
if (stepper2.distanceToGo() <=1) stepper2.moveTo (stepper2.currentPosition()+50) ;
stepper1.run();
stepper2.run();
if(fsekundy) {
Serial.print(sekundy);
sprintf(napis," Silnik1: %6d;",stepper1.currentPosition());
Serial.print(napis);
sprintf(napis," Silnik2: %6d;",stepper2.currentPosition());
Serial.println(napis);
}
}
void czas()
{
czasTeraz=millis();
fnTik=fsekundy=fminuty=fgodziny=fdni=0;
if((uint32_t)(czasTeraz-czasPoprzedni)>=tik)
{
czasPoprzedni=czasTeraz;
fnTik=1;
nTik++;
if(nTik>=(1000/tik))
{
nTik=0;
sekundy++;
fsekundy=1;
if (sekundy>=60)
{
sekundy=0;
minuty++;
fminuty=1;
if (minuty>=60)
{
minuty=0;
godziny++;
fgodziny=1;
if (godziny>=24)
{
godziny=0;
fdni=1;
dni++;
}
}
}
}
}
}
Miło być decenianym https://buycoffee.to/kaczakat