Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. /* sterowanie krokowca
  2.  *  styczeń 2020
  3.  *  
  4.  *  MotyL
  5.  */
  6. //  ------definicje
  7. #define dirPin 6                //pin okreslajacy kierunek obrotow
  8. #define stepPin 5               //pin kluczujacy obrotami
  9. #define enPin 7                 //pin wlaczajacy stepper
  10. #define prawo 8                 //przycisk w prawo
  11. #define lewo 9                  //przycisk w lewo
  12. #define gora 4                  //krancowka gorna
  13. #define dol 3                   //krancowka dolna
  14. #define pinSpeed A1             //pin wejscia potencometru
  15. #define minSpeed 1000           //predkosc minimalna
  16. #define maxSpeed 5000000        //predkosc maxymalna
  17. unsigned long predkosc;
  18.  
  19. void setup() {
  20.  //.........ustawienie pinów In/Out
  21.   pinMode(dirPin, OUTPUT);
  22.   pinMode(stepPin, OUTPUT);
  23.   pinMode(enPin, OUTPUT);
  24.   pinMode(prawo, INPUT_PULLUP);
  25.     digitalWrite(prawo,HIGH);
  26.   pinMode(lewo, INPUT_PULLUP);
  27.     digitalWrite(lewo,HIGH);
  28.   pinMode(gora, INPUT_PULLUP);
  29.     digitalWrite(gora,HIGH);
  30.   pinMode(dol, INPUT_PULLUP);
  31.     digitalWrite(dol, HIGH);
  32.   pinMode(pinSpeed, INPUT);
  33. }
  34.  
  35. void loop() {
  36.  
  37. // ustalamy predkosc - mapujemy wejscie analogowe A1
  38. predkosc = analogRead(pinSpeed);
  39. predkosc = map(predkosc, 0, 1023, minSpeed, maxSpeed);
  40.  
  41. //krecimy w prawo - jazda do dołu
  42.  
  43. if(digitalRead(prawo)==LOW) {
  44.     digitalWrite(enPin,LOW);
  45.     digitalWrite(dirPin,LOW);
  46.      
  47.      while(digitalRead(prawo)==LOW && digitalRead(dol) == HIGH){
  48.           digitalWrite(stepPin,LOW);
  49.           delayMicroseconds(500);
  50.           digitalWrite(stepPin,HIGH);
  51.           delayMicroseconds(predkosc);
  52.             }
  53.   }
  54.   else digitalWrite(enPin,HIGH);
  55.  
  56.  
  57.  // krecimy w lewo - jazda do gory
  58.  
  59. if(digitalRead(lewo)==LOW) {
  60.     digitalWrite(enPin,LOW);
  61.     digitalWrite(dirPin,HIGH);
  62.      
  63.      while(digitalRead(lewo)==LOW && digitalRead(gora) == HIGH){
  64.           digitalWrite(stepPin,LOW);
  65.           delayMicroseconds(500);
  66.           digitalWrite(stepPin,HIGH);
  67.           delayMicroseconds(predkosc);
  68.             }
  69.   }
  70.   else digitalWrite(enPin,HIGH);
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement