Advertisement
dioxik

Untitled

Oct 23rd, 2015
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.75 KB | None | 0 0
  1. #include <Stepper.h>
  2.  
  3. int switchPin = 12; // go home
  4. int potPin = 0; // x
  5. int potPin2 = 1; // y
  6. int potPin3 = 2; // czułość
  7. int czulosc = 70;
  8. int stan0x = 0;
  9. int stan0y = 0;
  10. int x = 0;
  11. int y = 0;
  12. const int stepsPerRevolution = 200; // te dwie krowy robia 200 kroków na 360
  13. int speed = 0;
  14. // initialize the stepper library on pins 8 through 11:
  15.  
  16. Stepper myStepper(stepsPerRevolution, 8,9,10,11);
  17. Stepper myStepper2(stepsPerRevolution, 2,3,4,5);
  18. int stopnie = 2;
  19. void setup() {
  20.  
  21.   pinMode(switchPin, INPUT_PULLUP);
  22.   stan0x = analogRead(potPin);
  23.   stan0y = analogRead(potPin2);
  24.   //czulosc = analogRead(potPin3);
  25.  
  26.   //speed = map(speed, stan0x, 1040, 0, czulosc);
  27. myStepper.setSpeed(10);
  28. myStepper2.setSpeed(10);
  29.  
  30. // initialize the serial port:
  31.  
  32. Serial.begin(9600); }
  33.  
  34. void loop() {
  35.  
  36.    czulosc = analogRead(potPin3);
  37.   // Serial.print(czulosc);
  38.  //  Serial.print("analog          ");
  39.    czulosc = map(czulosc, 0, 1040, 0, 200);
  40.  //  Serial.print(czulosc);
  41.   // Serial.println("map");
  42.  
  43.   int speed = analogRead(potPin) ;
  44.   speed = map(speed, stan0x, 1040, 0, czulosc);
  45.   int speed2 = analogRead(potPin2) ;
  46.   speed2 = map(speed2, stan0y, 1040, 0, czulosc);
  47.  
  48.  
  49.  
  50.  
  51.   if(speed >5 ) {
  52.     myStepper.setSpeed(speed);
  53.     myStepper.step(stopnie);
  54.    x = x + stopnie;
  55.     }  
  56.  
  57.   if(speed<-5 ) {
  58.     myStepper.setSpeed(speed*-1);
  59.     myStepper.step(-stopnie);
  60.     x = x-stopnie;
  61.     }
  62.  
  63.   if(speed2 >5 ) {
  64.     myStepper2.setSpeed(speed2);
  65.     myStepper2.step(stopnie);
  66.     y = y+stopnie;
  67.     }  
  68.  
  69.   if(speed2<-5 ) {
  70.     myStepper2.setSpeed(speed2*-1);
  71.     myStepper2.step(-stopnie);
  72.     y = y-stopnie;
  73.     }
  74.     if(speed > -5 && speed < 5){
  75.     stop_motor_a();}
  76.     if(speed2 > -5 && speed2 < 5){
  77.     stop_motor_b();}
  78.    
  79.     boolean blin = digitalRead(12);
  80.     if(!blin){
  81.       Serial.print(x);
  82.       Serial.print("x         ");
  83.       Serial.print(y);
  84.       Serial.println("y       wracam");
  85.         myStepper2.setSpeed(100);
  86.         myStepper2.step(y*-1);
  87.         myStepper.setSpeed(100);
  88.         myStepper.step(x*-1);
  89.         x = 0;
  90.         y = 0;
  91.     }
  92. }
  93.  
  94. void stop_motor_a (){
  95.       digitalWrite(2, HIGH);
  96.       digitalWrite(3, HIGH);
  97.       digitalWrite(4, HIGH);
  98.       digitalWrite(5, HIGH);
  99. }
  100. void stop_motor_b (){
  101.       digitalWrite(8, HIGH);
  102.       digitalWrite(9, HIGH);
  103.       digitalWrite(10, HIGH);
  104.       digitalWrite(11, HIGH);
  105. }
  106.  
  107. void debug(){
  108. // step one revolution in one direction:
  109. //    Serial.print(speed);
  110. //    Serial.print ("speed               ");
  111. //Serial.print(analogRead(potPin));
  112. //Serial.print ("x");
  113. //Serial.print(analogRead(potPin2));
  114. //Serial.print ("y             ");
  115. //Serial.print(analogRead(potPin3));
  116. //Serial.print ("czulosc       ");
  117. //Serial.println("");
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement