Hello,
Ihave a dc motor, which is meant to drive forward for 30s when pushing a push button. When this is finished and the button is pushed again, it is meant to drive the same time in the other direction.
I realised this by an l298 and with an if and else if. But the first rotation does not happen.
I gave the variable "ort" ehis is 0 in the setup. This means the starting plave, position 0. When the button is detected it is meant to dwitch to 1, so later it can drive to start position again.
I included the built in LED to look it the if-part works and the led shines for 30s but the motor does not start. In the next attempt the motor runs in the backwards direction, but never forwards.
Sorry, but I cant upload data, here is my Code:
int taster=2;
int tasterstatus=0;
int ort = 0;
int ena = 9;
int in1 = 8;
int in2 = 7;
void setup() {
pinMode(taster, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(ena, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
digitalWrite(ena, 255);
}
void loop() {
tasterstatus=digitalRead(taster);
if (tasterstatus == HIGH){
if (ort == 0) {
ort ++;
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
delay(30000);
digitalWrite(LED_BUILTIN, LOW);
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
}
else if (ort == 1){
ort --;
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
delay(30000);
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
}
}
}