05-02-2022, 20:07
Dzięki, masz rację. Pomieszałem kabelki. Teraz się kręcą.
Mam pytanie dot funkcji czas(). Jak dobrze zrozumiałem kod, związana jest ona tylko z wyświetlaniem informacji w porcie szeregowym. Mam rację? Po wyeliminowanie z kodu elementów związanych z tą funkcją silniki nadal pracują. Próbowałem zmodyfikować ten kod, tak by wykonywał się "n" razy co 2 sekundy. I znowu porażka. Nie ma ruchu. Dochodzę do wniosku, że jedyne co mi wychodzi to mruganie diodą na pinie 13.
#include <AccelStepper.h>
const int stepPin1 = 7; // Silnik nr 1 ruch poziomy
const int dirPin1 = 6;
const int enablePin1 = 10;
const int stepPin2 = 9; //Silnik nr 2 ruch obrotowy głowicy
const int dirPin2 = 8;
const int enablePin2 = 11;
bool flag = true;
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);
pinMode(enablePin1,OUTPUT);
pinMode(enablePin2,OUTPUT);
digitalWrite(enablePin1, LOW) ;
digitalWrite(enablePin2, LOW) ;
stepper1.setMaxSpeed(1000);
stepper1.setAcceleration(50);
stepper1.moveTo(2000);
stepper2.setMaxSpeed(3000);
stepper2.setAcceleration(100);
stepper2.moveTo(2000);
}
void loop()
{
if(flag){
for(int i = 0; i <= 3; i++){
ruch();
delay(2000);
}
flag = false;}
}
void ruch(){
if (stepper1.distanceToGo() <=2000) stepper1.moveTo (stepper1.currentPosition()-2000) ;
if (stepper2.distanceToGo() <=2000) stepper2.moveTo (stepper2.currentPosition()+2000) ;
stepper1.run();
stepper2.run();
}
Mam pytanie dot funkcji czas(). Jak dobrze zrozumiałem kod, związana jest ona tylko z wyświetlaniem informacji w porcie szeregowym. Mam rację? Po wyeliminowanie z kodu elementów związanych z tą funkcją silniki nadal pracują. Próbowałem zmodyfikować ten kod, tak by wykonywał się "n" razy co 2 sekundy. I znowu porażka. Nie ma ruchu. Dochodzę do wniosku, że jedyne co mi wychodzi to mruganie diodą na pinie 13.
#include <AccelStepper.h>
const int stepPin1 = 7; // Silnik nr 1 ruch poziomy
const int dirPin1 = 6;
const int enablePin1 = 10;
const int stepPin2 = 9; //Silnik nr 2 ruch obrotowy głowicy
const int dirPin2 = 8;
const int enablePin2 = 11;
bool flag = true;
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);
pinMode(enablePin1,OUTPUT);
pinMode(enablePin2,OUTPUT);
digitalWrite(enablePin1, LOW) ;
digitalWrite(enablePin2, LOW) ;
stepper1.setMaxSpeed(1000);
stepper1.setAcceleration(50);
stepper1.moveTo(2000);
stepper2.setMaxSpeed(3000);
stepper2.setAcceleration(100);
stepper2.moveTo(2000);
}
void loop()
{
if(flag){
for(int i = 0; i <= 3; i++){
ruch();
delay(2000);
}
flag = false;}
}
void ruch(){
if (stepper1.distanceToGo() <=2000) stepper1.moveTo (stepper1.currentPosition()-2000) ;
if (stepper2.distanceToGo() <=2000) stepper2.moveTo (stepper2.currentPosition()+2000) ;
stepper1.run();
stepper2.run();
}