Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Stepper.h>
- int switchPin = 12; // go home
- int potPin = 0; // x
- int potPin2 = 1; // y
- int potPin3 = 2; // czułość
- int czulosc = 70;
- int stan0x = 0;
- int stan0y = 0;
- int x = 0;
- int y = 0;
- const int stepsPerRevolution = 200; // te dwie krowy robia 200 kroków na 360
- int speed = 0;
- // initialize the stepper library on pins 8 through 11:
- Stepper myStepper(stepsPerRevolution, 8,9,10,11);
- Stepper myStepper2(stepsPerRevolution, 2,3,4,5);
- int stopnie = 2;
- void setup() {
- pinMode(switchPin, INPUT_PULLUP);
- stan0x = analogRead(potPin);
- stan0y = analogRead(potPin2);
- //czulosc = analogRead(potPin3);
- //speed = map(speed, stan0x, 1040, 0, czulosc);
- myStepper.setSpeed(10);
- myStepper2.setSpeed(10);
- // initialize the serial port:
- Serial.begin(9600); }
- void loop() {
- czulosc = analogRead(potPin3);
- // Serial.print(czulosc);
- // Serial.print("analog ");
- czulosc = map(czulosc, 0, 1040, 0, 200);
- // Serial.print(czulosc);
- // Serial.println("map");
- int speed = analogRead(potPin) ;
- speed = map(speed, stan0x, 1040, 0, czulosc);
- int speed2 = analogRead(potPin2) ;
- speed2 = map(speed2, stan0y, 1040, 0, czulosc);
- if(speed >5 ) {
- myStepper.setSpeed(speed);
- myStepper.step(stopnie);
- x = x + stopnie;
- }
- if(speed<-5 ) {
- myStepper.setSpeed(speed*-1);
- myStepper.step(-stopnie);
- x = x-stopnie;
- }
- if(speed2 >5 ) {
- myStepper2.setSpeed(speed2);
- myStepper2.step(stopnie);
- y = y+stopnie;
- }
- if(speed2<-5 ) {
- myStepper2.setSpeed(speed2*-1);
- myStepper2.step(-stopnie);
- y = y-stopnie;
- }
- if(speed > -5 && speed < 5){
- stop_motor_a();}
- if(speed2 > -5 && speed2 < 5){
- stop_motor_b();}
- boolean blin = digitalRead(12);
- if(!blin){
- Serial.print(x);
- Serial.print("x ");
- Serial.print(y);
- Serial.println("y wracam");
- myStepper2.setSpeed(100);
- myStepper2.step(y*-1);
- myStepper.setSpeed(100);
- myStepper.step(x*-1);
- x = 0;
- y = 0;
- }
- }
- void stop_motor_a (){
- digitalWrite(2, HIGH);
- digitalWrite(3, HIGH);
- digitalWrite(4, HIGH);
- digitalWrite(5, HIGH);
- }
- void stop_motor_b (){
- digitalWrite(8, HIGH);
- digitalWrite(9, HIGH);
- digitalWrite(10, HIGH);
- digitalWrite(11, HIGH);
- }
- void debug(){
- // step one revolution in one direction:
- // Serial.print(speed);
- // Serial.print ("speed ");
- //Serial.print(analogRead(potPin));
- //Serial.print ("x");
- //Serial.print(analogRead(potPin2));
- //Serial.print ("y ");
- //Serial.print(analogRead(potPin3));
- //Serial.print ("czulosc ");
- //Serial.println("");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement