Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<AccelStepper.h>
- #include <iarduino_RTC.h>
- #define HALFSTEP 8
- // Определение пинов для управления двигателем
- #define motorPin11 13 // IN1 на 1-м драйвере
- #define motorPin12 12 // IN2 на 1-м драйвере
- #define motorPin13 11 // IN3 на 1-м драйвере
- #define motorPin14 10 // IN4 на 1-м драйвере
- #define motorPin21 6 // IN1 на 2-м драйвере
- #define motorPin22 7 // IN2 на 2-м драйвере
- #define motorPin23 8 // IN3 на 2-м драйвере
- #define motorPin24 9 // IN4 на 2-м драйвере
- // Инициализируемся с последовательностью выводов IN1-IN3-IN2-IN4
- iarduino_RTC time(RTC_DS1302,3,4,5);
- AccelStepper stepper1(HALFSTEP, motorPin11, motorPin13, motorPin12, motorPin14);
- AccelStepper stepper2(HALFSTEP, motorPin21, motorPin23, motorPin22, motorPin24);
- void setup(){
- Serial.begin(9600);
- pinMode(2, INPUT_PULLUP); // вывод для кнопки
- stepper1.setMaxSpeed(1500.0); // Задаём максимальную скорость двигателя
- stepper1.setAcceleration(500.0); // Задаём ускорение двигателя
- stepper2.setMaxSpeed(1500.0);
- stepper2.setAcceleration(500.0);
- //time.settime(0, 24, 19, 27, 5, 22, 5);
- //time.begin();
- }
- void loop(){
- bool h , m;
- bool btnState = !digitalRead(2);
- time.gettime();
- //Serial.println(time.gettime("d-m-Y, H:i:s, D"));
- if (btnState){
- if (time.Hours == 0 && stepper2.currentPosition() != 0){
- stepper2.moveTo (8192);
- stepper2.runToPosition();
- stepper2.disableOutputs();
- stepper2.setCurrentPosition (0);
- }
- else{
- stepper2.moveTo (time.Hours * 82);
- stepper2.runToPosition();
- stepper2.disableOutputs();
- }
- if (time.minutes == 0 && stepper1.currentPosition() != 0){
- stepper1.moveTo (-8192);
- stepper1.runToPosition();
- stepper1.disableOutputs();
- stepper1.setCurrentPosition (0);
- }
- else{
- stepper1.moveTo (time.minutes * -82);
- stepper1.runToPosition();
- stepper1.disableOutputs();
- }
- }
- if (!btnState){
- stepper2.moveTo (8192);
- stepper2.runToPosition();
- stepper2.disableOutputs();
- stepper2.setCurrentPosition (0);
- stepper1.moveTo (-8192);
- stepper1.runToPosition();
- stepper1.disableOutputs();
- stepper1.setCurrentPosition (0);
- delay(20000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement