I wrote a code that i thought would work, but when i hit my kill switch the motor simply started making a higher pitched hum.
Here is the code could you please explain why it didn't work;
const int buttonPin = 1;
int dirPin = 8;
int stepPin = 9;
int Distance = 0;
int buttonState = 0;
void setup() {
pinMode(buttonPin, INPUT);
pinMode(dirPin, OUTPUT);
pinMode(stepPin, OUTPUT);
digitalWrite(dirPin, LOW);
digitalWrite(stepPin, LOW);
}
void loop() {
digitalWrite(stepPin, HIGH);
delayMicroseconds(100);
digitalWrite(stepPin, LOW);
delayMicroseconds(100);
Distance = Distance + 1;
if (Distance == 5000)
{
if (digitalRead(dirPin) == LOW)
{
digitalWrite(dirPin, HIGH);
}
else
{
digitalWrite(dirPin, LOW);
}
Distance = 0;
delay(500);
}
if (digitalRead(buttonPin) == HIGH) {
digitalWrite(stepPin, LOW);
}
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.