I have one project with few buttons and I am using some pins as inputs with internal pullup.
Prolem is when I use D13 immidiatelly after bootup it register D13 pin as pressed and starts to spin motor, but when I use D6 or any other pin it behaves as expected, but just on pin 13 i can't make it work.
does anyone have idea how to block whatever is happening until button press,what I need it to do.
Here is the code:
const int dirPin = 7;
const int stepperPin = 8;
const int homepolozaj = 2;
const int brzina1 = 3;
const int brzina2 = 4;
const int brzina3 = 5;
const int gore = 13;
const int dole = 6;
const int ms1 = 11;
const int ms2 = 10;
const int ms3 = 9;
byte stanje;
long brzina = 100;
void setup() {
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(A3, OUTPUT);
pinMode(ms1, OUTPUT);
pinMode(ms2, OUTPUT);
pinMode(ms3, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(stepperPin, OUTPUT);
pinMode(homepolozaj, INPUT);
digitalWrite(homepolozaj, HIGH);
pinMode(brzina1, INPUT);
digitalWrite(brzina1, HIGH);
pinMode(brzina2, INPUT);
digitalWrite(brzina2, HIGH);
pinMode(brzina3, INPUT);
digitalWrite(brzina3, HIGH);
pinMode(gore, INPUT);
digitalWrite(gore, HIGH);
pinMode(dole, INPUT);
digitalWrite(dole, HIGH);
// pocetak();
}
void loop() {
tipkalo();
}
void pocetak() {
digitalWrite(dirPin, LOW );
stanje = digitalRead(homepolozaj);
while (stanje == HIGH)
{
digitalWrite(stepperPin, HIGH);
delayMicroseconds(1000);
digitalWrite(stepperPin, LOW);
delayMicroseconds(1000);
stanje = digitalRead(homepolozaj);
}
delayMicroseconds(500);
digitalWrite(dirPin, HIGH );
stanje = digitalRead(homepolozaj);
while (stanje == LOW)
{
digitalWrite(stepperPin, HIGH);
delayMicroseconds(1000);
digitalWrite(stepperPin, LOW);
delayMicroseconds(1000);
stanje = digitalRead(homepolozaj);
}
}
void tipkalo() {
if (digitalRead(brzina1) == LOW) {
brzina = 36999;
digitalWrite(ms1, LOW);
digitalWrite(ms2, HIGH);
digitalWrite(ms3, HIGH);
digitalWrite(A0, HIGH);
digitalWrite(A1, LOW);
digitalWrite(A2, LOW);
}
else if (digitalRead(brzina2) == LOW) {
brzina = 24000;
digitalWrite(ms1, LOW);
digitalWrite(ms2, HIGH);
digitalWrite(ms3, LOW);
digitalWrite(A0, LOW);
digitalWrite(A1, HIGH);
digitalWrite(A2, LOW);
}
else if (digitalRead(brzina3) == LOW) {
digitalWrite(A2, HIGH);
brzina = 10000;
digitalWrite(ms1, LOW);
digitalWrite(ms2, HIGH);
digitalWrite(ms3, LOW);
digitalWrite(A0, LOW);
digitalWrite(A1, LOW);
}
else if (digitalRead(dole) == LOW) {
digitalWrite(dirPin, HIGH );
stanje = digitalRead(homepolozaj);
while (stanje == HIGH)
{
digitalWrite(stepperPin, HIGH);
delayMicroseconds(1000);
digitalWrite(stepperPin, LOW);
delayMicroseconds(1000);
stanje = digitalRead(homepolozaj);
}
delayMicroseconds(500);
digitalWrite(dirPin, LOW );
stanje = digitalRead(homepolozaj);
while (stanje == LOW)
{
digitalWrite(stepperPin, HIGH);
delayMicroseconds(1000);
digitalWrite(stepperPin, LOW);
delayMicroseconds(1000);
stanje = digitalRead(homepolozaj);
}
}
}