I write a program on library Stepper not AccelStepper.
Now is working.
Program code:
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
// Enable repeater functionality for this node
#define MY_REPEATER_FEATURE
#include <SPI.h>
#include <MySensors.h>
#include <Stepper.h>
#define CURTAIN_CLOSED 1000 // wartosc gdy kurtyna zamknieta
#define CURTAIN_OPEN -1000 // wartosc gdy kurtyna otwarta
#define CHILD_ID 1
// definicje MySensors
MyMessage message(CHILD_ID, S_COVER);
int in1Pin = 3;
int in2Pin = 4;
int in3Pin = 5;
int in4Pin = 6;
int lastState;
// liczba kroków na jeden obrót
#define stepsPerRevolution 200
//ustawienie szybkości silnika
int motorSpeed = 40;
Stepper myStepper(stepsPerRevolution, in1Pin, in2Pin, in3Pin, in4Pin);
void setup() {
// ustawienie pinów jako wyjście
pinMode(in1Pin, OUTPUT);
pinMode(in2Pin, OUTPUT);
pinMode(in3Pin, OUTPUT);
pinMode(in4Pin, OUTPUT);
// ustawienie szybkosci silnika
myStepper.setSpeed(motorSpeed);
}
void presentation()
{
// Wyslanie informacji o wersji programu
sendSketchInfo("Program kurtyna", "1.0");
// Register all sensors to gw (they will be created as child devices)
present(CHILD_ID, S_COVER); // Window Cover sub-type, commands: V_UP, V_DOWN, V_STOP
}
void receive(const MyMessage &message) {
// if message = V_UP start moving until closed
if (message.type==V_UP) {
myStepper.step(CURTAIN_OPEN);
// Store state in eeprom
saveState(message.sensor, message.getBool());
request(CHILD_ID, V_UP, 0); // request new values from controller
}
if (message.type==V_DOWN) {
myStepper.step(CURTAIN_CLOSED);
// Store state in eeprom
saveState(message.sensor, message.getBool());
request(CHILD_ID, V_DOWN, 0); // request new values from controller
}
}
I use MySensors Library 2.0
Youtube film
Silnik krokowy z L298N - sterowanie z Domoticz – 00:40
— Roman Kubat