#include "AccelStepper.h"
#include "ShiftRegs.h"
const int stepper1_stepPin = 129;
const int stepper1_directionPin = 130;
const int stepper1_enablePin = 128;
const int stepper2_stepPin = 137;
const int stepper2_directionPin = 138;
const int stepper2_enablePin = 136;
AccelStepper stepper1(AccelStepper::DRIVER, stepper1_stepPin, stepper1_directionPin); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
AccelStepper stepper2(AccelStepper::DRIVER, stepper2_stepPin, stepper2_directionPin); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
uint32_t led_builtin_time_previous = 0;
uint16_t led_builtin_interval = 500; // ms
uint32_t led_bar_graph_time_previous = 0;
uint16_t led_bar_graph_interval = 500; // ms
// bool led_bar_graph[8] = {};
void blink_led_builtin(){
if (millis() > led_builtin_time_previous + led_builtin_interval){
led_builtin_time_previous = millis();
_digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
}
void led_bar_graph_animation(){
if (millis() > led_bar_graph_time_previous + led_bar_graph_interval){
led_bar_graph_time_previous = millis();
for (uint8_t i=0; i<8; i++){
_digitalWrite(i+144, LOW);
}
uint8_t volume = random(8);
for (uint8_t i=0; i<volume; i++){
_digitalWrite(144+i, HIGH);
}
}
}
void setup() {
_pinMode(LED_BUILTIN, OUTPUT);
_init_shift_registers(_LATCH_PIN, _CLOCK_PIN, _DATA_PIN);
stepper1.setEnablePin(stepper1_enablePin);
stepper1.setPinsInverted(false, false, true);
stepper1.enableOutputs();
stepper1.setMaxSpeed(400);
stepper1.setAcceleration(250);
stepper2.setEnablePin(stepper2_enablePin);
stepper2.setPinsInverted(false, false, true);
stepper2.enableOutputs();
stepper2.setMaxSpeed(400);
stepper2.setAcceleration(250);
Serial.begin(115200);
_digitalWrite(144, HIGH);
}
void loop() {
if(stepper1.distanceToGo() == 0) {
// delay(1000);
stepper1.moveTo(random(200, 1000));
}
if(stepper2.distanceToGo() == 0) {
// delay(1000);
stepper2.moveTo(random(200, 1000));
}
stepper1.run();
stepper2.run();
blink_led_builtin();
led_bar_graph_animation();
// Перенести в отдельную библиотеку
}