Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //For motor: Nema 17 Bipolar Stepper 17HS13-0404S1
- int motorPin1 = 8; //BLÅ (Blue)
- int motorPin2 = 9; //SORT (Black)
- int motorPin3 = 10; //GRØN (Green)
- int motorPin4 = 11; //RØD (Red)
- int delayTime = 5;
- void setup() {
- Serial.begin(9600);
- pinMode(motorPin1, OUTPUT);
- pinMode(motorPin2, OUTPUT);
- pinMode(motorPin3, OUTPUT);
- pinMode(motorPin4, OUTPUT);
- }
- int stepmode = 0;
- void steponce(){
- switch(stepmode){
- case 0:
- digitalWrite(motorPin4, HIGH);
- digitalWrite(motorPin3, LOW);
- digitalWrite(motorPin2, LOW);
- digitalWrite(motorPin1, LOW);
- stepmode++;
- break;
- case 1:
- digitalWrite(motorPin4, LOW);
- digitalWrite(motorPin3, HIGH);
- digitalWrite(motorPin2, LOW);
- digitalWrite(motorPin1, LOW);
- stepmode++;
- break;
- case 2:
- digitalWrite(motorPin4, LOW);
- digitalWrite(motorPin3, LOW);
- digitalWrite(motorPin2, HIGH);
- digitalWrite(motorPin1, LOW);
- stepmode++;
- break;
- default:
- digitalWrite(motorPin4, LOW);
- digitalWrite(motorPin3, LOW);
- digitalWrite(motorPin2, LOW);
- digitalWrite(motorPin1, HIGH);
- stepmode = 0;
- break;
- }
- delay(delayTime);
- //Serial.println("Stepped once");
- }
- void steptimes(int n){
- for(int i = 0; i < n; i++){
- steponce();
- }
- Serial.print("Stepped ");
- Serial.print(n);
- Serial.println(" times");
- }
- void loop() {
- steptimes(100);
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement