int hallSensorPin = 9;
int hallSensorPin2 = 10;
# define dirPin 2
# define stepPin 3
# define pwrOff 4
# define STEP_PERIOD 400
void setup() {
Serial.begin(115200);
Serial.println("step thing happening!");
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(pwrOff, OUTPUT);
pinMode(hallSensorPin, INPUT);
digitalWrite(dirPin, HIGH);
// digitalWrite(stepPin, HIGH);
// for (; ; );
}
static unsigned char doStep = 0;
static unsigned char phase;
void loop() {
static unsigned char doStep = 0;
static unsigned char phase;
static unsigned long lastStep;
// swtich to micros for stepping for real
// unsigned long now = micros();
// use millis for development
unsigned long now = millis();
if (now - lastStep >= STEP_PERIOD) {
if (doStep) {
lastStep = now;
digitalWrite(pwrOff, LOW);
if (phase & 1)
digitalWrite(stepPin, LOW);
else
digitalWrite(stepPin, HIGH);
phase++;
}
else {
digitalWrite(pwrOff, HIGH);
digitalWrite(stepPin, LOW);
}
doStep = digitalRead(hallSensorPin);
}
/*
Serial.print(" do step ");
Serial.print(doStep);
Serial.print(" phase ");
Serial.println(phase);
delay(100);
*/
}