Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- UniHobbies Arduino
- edits by Jorik van den Bos
- */
- //this is a built-in library
- #include<Stepper.h>
- int steps=0;
- int cycles=0;
- int stepsamount=512;
- int cycleamount=0;
- int in1Pin =12;
- int in2Pin =11;
- int in3Pin =10;
- int in4Pin =9;
- Stepper motor(512, in1Pin, in2Pin, in3Pin, in4Pin);
- void setup()
- {
- pinMode(in1Pin, OUTPUT);
- pinMode(in2Pin, OUTPUT);
- pinMode(in3Pin, OUTPUT);
- pinMode(in4Pin, OUTPUT);
- // this line is for Leonardo’s, it delays the serial interface
- // until the terminal window is opened
- while(!Serial);
- Serial.begin(9600);
- motor.setSpeed(40);
- }
- void loop()
- {
- //parse the amount of cycles
- if(Serial.available()) cycleamount = Serial.parseInt();
- //cycleamount should not be zero, can be set with parseInt()
- if (cycleamount!=0)
- {
- //before the amount of cycles is reached, cycles<cyceleamount
- if (cycles<cycleamount)
- {
- //stepsamount should not be zero
- if (stepsamount!=0)
- {
- //do the steps for 1 cycle
- steps+=1;
- if (steps<stepsamount) motor.step(1); else
- if (steps<stepsamount*2) motor.step(-1); else /*reset step variables*/ {steps=0; cycles+=1;}
- }
- }
- //else reset cycle variables
- else {cycles=0; cycleamount=0;}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement