lehrkraefte:blc:math:formi:stepper

stepmotor28byh-48.ino
#define PINA 8
#define PINB 9
#define PINC 10
#define PIND 11
 
int pins[] = {PINA, PINB, PINC, PIND};
 
void setup() {
  for (int i=0; i<4; i++) {
    pinMode(pins[i], OUTPUT);
  }
}
 
void step(int s) {
  if (s<0 || s>7) {
    for (int i=0; i<4; i++) {
      digitalWrite(pins[i], LOW);
    }
  } else {
    int on = LOW;
    for (int i=0; i<4; i++) {
      if (i==s/2 || i==(s/2+s%2)%4) {
        on = HIGH;
      } else {
        on = LOW;
      }
      digitalWrite(pins[i], on);
    }  
  }
}
 
int dly = 1;
 
void loop() {
  for (int i=0; i<512; i++) {
    step(i % 8);
    delay(dly);
  }
  step(-1);
  delay(200);
  for (int i=511; i>0; i--) {
    step(i % 8);
    delay(dly);
  }
  step(-1);
  delay(500);
}
  • lehrkraefte/blc/math/formi/stepper.txt
  • Last modified: 2017/02/25 14:58
  • by Ivo Blöchliger