Advertisement
Guest User

Untitled

a guest
May 29th, 2022
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. #include<AccelStepper.h>
  2. #include <iarduino_RTC.h>
  3. #define HALFSTEP 8
  4. // Определение пинов для управления двигателем
  5. #define motorPin11 13 // IN1 на 1-м драйвере
  6. #define motorPin12 12 // IN2 на 1-м драйвере
  7. #define motorPin13 11 // IN3 на 1-м драйвере
  8. #define motorPin14 10 // IN4 на 1-м драйвере
  9. #define motorPin21 6 // IN1 на 2-м драйвере
  10. #define motorPin22 7 // IN2 на 2-м драйвере
  11. #define motorPin23 8 // IN3 на 2-м драйвере
  12. #define motorPin24 9 // IN4 на 2-м драйвере
  13.  
  14. // Инициализируемся с последовательностью выводов IN1-IN3-IN2-IN4
  15. iarduino_RTC time(RTC_DS1302,3,4,5);
  16. AccelStepper stepper1(HALFSTEP, motorPin11, motorPin13, motorPin12, motorPin14);
  17. AccelStepper stepper2(HALFSTEP, motorPin21, motorPin23, motorPin22, motorPin24);
  18.  
  19. void setup(){
  20. Serial.begin(9600);
  21. pinMode(2, INPUT_PULLUP); // вывод для кнопки
  22. stepper1.setMaxSpeed(1500.0); // Задаём максимальную скорость двигателя
  23. stepper1.setAcceleration(500.0); // Задаём ускорение двигателя
  24. stepper2.setMaxSpeed(1500.0);
  25. stepper2.setAcceleration(500.0);
  26.  
  27. //time.settime(0, 24, 19, 27, 5, 22, 5);
  28. //time.begin();
  29. }
  30.  
  31. void loop(){
  32. bool h , m;
  33. bool btnState = !digitalRead(2);
  34. time.gettime();
  35. //Serial.println(time.gettime("d-m-Y, H:i:s, D"));
  36. if (btnState){
  37. if (time.Hours == 0 && stepper2.currentPosition() != 0){
  38. stepper2.moveTo (8192);
  39. stepper2.runToPosition();
  40. stepper2.disableOutputs();
  41. stepper2.setCurrentPosition (0);
  42. }
  43. else{
  44. stepper2.moveTo (time.Hours * 82);
  45. stepper2.runToPosition();
  46. stepper2.disableOutputs();
  47. }
  48. if (time.minutes == 0 && stepper1.currentPosition() != 0){
  49. stepper1.moveTo (-8192);
  50. stepper1.runToPosition();
  51. stepper1.disableOutputs();
  52. stepper1.setCurrentPosition (0);
  53. }
  54. else{
  55. stepper1.moveTo (time.minutes * -82);
  56. stepper1.runToPosition();
  57. stepper1.disableOutputs();
  58. }
  59. }
  60. if (!btnState){
  61. stepper2.moveTo (8192);
  62. stepper2.runToPosition();
  63. stepper2.disableOutputs();
  64. stepper2.setCurrentPosition (0);
  65. stepper1.moveTo (-8192);
  66. stepper1.runToPosition();
  67. stepper1.disableOutputs();
  68. stepper1.setCurrentPosition (0);
  69. delay(20000);
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement