Hi,
i have following code:
#include <Arduino.h>
#define DIRA 6
#define DIRB 5
uint8_t tst = 0;
int EcuMdMinusPIN = A1;
int ECUMDMinus; //Signal-close
void setup()
{
Serial.begin(9600);
pinMode(DIRA, OUTPUT);
pinMode(DIRB, OUTPUT);
digitalWrite(DIRA, LOW);
digitalWrite(DIRB, LOW);
digitalWrite(DIRA, HIGH);
digitalWrite(DIRB, LOW);
delay(1000);
digitalWrite(DIRA, LOW);
digitalWrite(DIRB, HIGH);
delay(1000);
digitalWrite(DIRA, LOW);
digitalWrite(DIRB, LOW);
}
void loop()
{
ECUMDMinus = analogRead(EcuMdMinusPIN);
if (ECUMDMinus > 100)
{
if (!tst)
{
tst = true;
Serial.println("Motor soll fahren");
digitalWrite(DIRA, HIGH);
digitalWrite(DIRB, LOW);
}
}
}
In the setup i use a LMD298 to drive a electric motor first to the left, than to the right. In the loop function i wait till i have voltage on ECUMDMinus. If i have voltage on it i set the LMD and the electric motor drives to the right.
Now to the behavior i didn´t unterstand:
If i have voltage on ECUMDMinus i print on Serial "Motor soll fahren" but the electric motor doens´t turn to a direction. If I release the Voltage on ECUMDMinus the electric motor starts to turn.
Why is that so? In my understanding the motor should start in that moment i have voltage on ECUMDMinus ?!