Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Stepper.h>
- #include <Servo.h>
- int stepsPerRevolution=2048;
- int stepsPerRevolution2=2048;
- Stepper myStepper(stepsPerRevolution, 8,10,9,11); //delcares pins
- int motSpeed=50;
- int d1=500;
- int buttonPin=2;
- int buttonPin2=4;
- int buttonF;
- int splitButton;
- int splitButton2=1;
- int buttonB=1;
- int motDir=1;
- int buttonRead;
- int buttonRead2;
- int servoPin=13;
- int servoPos=60;
- int d2=250;
- Servo myServo;
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(9600);
- myStepper.setSpeed(motSpeed); //sets motor speed
- pinMode(buttonPin,INPUT);
- pinMode(buttonPin2,INPUT);
- digitalWrite(buttonPin2,HIGH);
- digitalWrite(buttonPin,HIGH); //pin hack for internal pullup resister
- myServo.attach(servoPin);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- buttonF=digitalRead(buttonPin);
- splitButton=digitalRead(buttonPin2);
- Serial.println(buttonF);
- delay(d2);
- Serial.println(splitButton);
- delay(d2);
- if (buttonB==0 && buttonF==1) {
- if (motDir==0) {
- myStepper.step(stepsPerRevolution*3); //runs one full rotation
- motDir=1;
- myServo.write(8);
- } //how i did it
- else {
- myStepper.step(-stepsPerRevolution*3); //runs one full rotation in negative.
- motDir=0;
- myServo.write(45);
- }
- }
- buttonB=buttonF;
- if (splitButton==0 && splitButton2==1) {
- if (motDir==0) {
- myServo.write(45);
- myStepper.step(-stepsPerRevolution2+600); //runs one full rotation
- motDir=1;
- myServo.write(8);
- }
- else {
- myStepper.step(stepsPerRevolution2-300); //runs one full rotation in negative.
- motDir=0;
- myServo.write(45);
- myServo.write(8);
- myServo.write(45);
- }
- }
- splitButton2=splitButton;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement