Advertisement
stevn

omr

Jan 18th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. +/*
  2. Stepper Motor Control - one revolution
  3.  
  4. This program drives a unipolar or bipolar stepper motor.
  5. The motor is attached to digital pins 8 - 11 of the Arduino.
  6.  
  7. The motor should revolve one revolution in one direction, then
  8. one revolution in the other direction.
  9.  
  10.  
  11. Created 11 Mar. 2007
  12. Modified 30 Nov. 2009
  13. by Tom Igoe
  14.  
  15. */
  16.  
  17. #include <TM1637Display.h>
  18.  
  19. const int CLK = 7; //Set the CLK pin connection to the display
  20. const int DIO = 6; //Set the DIO pin connection to the display
  21.  
  22. int sek = 0;
  23.  
  24. int ja = 0;
  25.  
  26.  
  27. int tid = 5;
  28.  
  29. int tider = 10;
  30.  
  31. #include <Stepper.h>
  32.  
  33. const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
  34. // for your motor
  35.  
  36. TM1637Display display(CLK, DIO); //set up the 4-Digit Display.
  37.  
  38. // initialize the stepper library on pins 8 through 11:
  39. Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
  40.  
  41. void setup() {
  42. // set the speed at 60 rpm:
  43. myStepper.setSpeed(60);
  44. // initialize the serial port:
  45. Serial.begin(9600);
  46.  
  47. display.setBrightness(0x0a); //set the diplay to maximum brightness
  48.  
  49. pinMode(3,INPUT_PULLUP); // mere tid
  50. pinMode(2,INPUT_PULLUP); // mindre tid
  51. pinMode(5,INPUT_PULLUP); // meget mere tid
  52. pinMode(4,INPUT_PULLUP); // meget mindre tid
  53. pinMode(12,INPUT_PULLUP); // start
  54. pinMode(13,INPUT_PULLUP); // stop
  55.  
  56. }
  57.  
  58. void loop() {
  59. Serial.println(sek);
  60.  
  61. display.showNumberDec(sek);
  62. if(digitalRead(3) == LOW){
  63. sek = sek+tid;
  64. delay(500);
  65. }
  66. else if(digitalRead(2)== LOW){
  67.  
  68. sek = sek-tid;
  69. delay(500);
  70. }
  71. else if(digitalRead(5)== LOW){
  72.  
  73. sek = sek+tider;
  74. delay(500);
  75. }
  76.  
  77. if(digitalRead(4)== LOW){
  78.  
  79. sek = sek-tider;
  80. delay(500);
  81. }
  82. else if(digitalRead(12)== LOW){
  83.  
  84. ja = 1;
  85. delay(500);
  86. }
  87. else if(digitalRead(13) == LOW){
  88. ja = 0;
  89.  
  90. sek = 0;
  91. delay(500);
  92. }
  93.  
  94. if(sek == 0){
  95.  
  96. ja = 0;
  97. }
  98.  
  99. while(sek > 0 && ja == 1){
  100. Serial.println(sek);
  101. display.showNumberDec(sek);
  102. myStepper.step(stepsPerRevolution);
  103.  
  104.  
  105. if(digitalRead(13) == LOW){
  106. ja = 0;
  107. }
  108.  
  109. sek = sek-1;
  110.  
  111. if(sek == 0){
  112.  
  113. ja = 0;
  114. }
  115. }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement