Пытался сделать ездящую коробку с Arduino Mega и 4 биполярными шаговиками, управляемую с помощью контроллера flysky i6. Вот код:
#include <IBusBM.h>
IBusBM ibusRc;
HardwareSerial& ibusRcSerial = Serial1;
HardwareSerial& debugSerial = Serial;
#include <GyverStepper.h>
GStepper<STEPPER4WIRE> stepperLF(2048, 22, 24, 26, 28);
GStepper<STEPPER4WIRE> stepperRF(2048, 7, 6, 5, 4);
GStepper<STEPPER4WIRE> stepperRB(2048, 23, 25, 27, 29);
GStepper<STEPPER4WIRE> stepperLB(2048, 30, 31, 32, 33);
int spws;
int spad;
void setup() {
debugSerial.begin(74880);
ibusRc.begin(ibusRcSerial);
stepperLF.setRunMode(KEEP_SPEED);
stepperRF.setRunMode(KEEP_SPEED);
stepperLB.setRunMode(KEEP_SPEED);
stepperRB.setRunMode(KEEP_SPEED);
stepperLF.stop();
stepperRF.stop();
stepperLB.stop();
stepperRB.stop();
}
// Read the number of a given channel and convert to the range provided.
// If the channel is off, return the default value
int readChannel(byte channelInput, int minLimit, int maxLimit, int defaultValue){
uint16_t ch = ibusRc.readChannel(channelInput);
if (ch < 100) return defaultValue;
return map(ch, 1000, 2000, minLimit, maxLimit);
}
// Red the channel and return a boolean value
bool redSwitch(byte channelInput, bool defaultValue){
int intDefaultValue = (defaultValue)? 100: 0;
int ch = readChannel(channelInput, 0, 100, intDefaultValue);
return (ch > 50);
}
void loop() {
for (byte i = 0; i<4; i++){
int value = readChannel(i, -400, 400, 0);
debugSerial.print("Ch");
debugSerial.print(i + 1);
debugSerial.print(": ");
debugSerial.print(value);
debugSerial.print(" ");
}
debugSerial.print("Ch5: ");
debugSerial.print(redSwitch(4, false));
debugSerial.println();
spws = readChannel(2, -400, 400, 0);
spad = readChannel(3, -400, 400, 0);
Serial.print("5");
Serial.print(": ");
Serial.print(spws);
Serial.print(" ");
Serial.print("6");
Serial.print(": ");
Serial.print(spad);
Serial.print(" ");
stepperLF.setSpeed(spws);
stepperRF.setSpeed(spws);
stepperLB.setSpeed(spws);
stepperRB.setSpeed(spws);
stepperLF.tick();
stepperRF.tick();
stepperLB.tick();
stepperRB.tick();
}
В мониторе порта изменения отображаются, то есть значения от пульта принимает, но вот движки не крутятся. Может, кто, подсказать в чем проблема?