/*
Forum: https://forum.arduino.cc/t/dc-motor-mit-l293d-zufallig-ansteuern/1210964/6
Wokwi: https://wokwi.com/projects/386922640522676225
*/
const byte motorA = 12;
const byte motorB = 8;
unsigned long zuletzt = 0;
byte stateA = 0;
void setup() {
Serial.begin(115200);
pinMode(motorA, OUTPUT);
pinMode(motorB, OUTPUT);
controlMotor(stateA,stateA);
randomSeed(millis());
}
void loop() {
if (millis()-zuletzt >= 2000){
zuletzt = millis();
stateA = random(2);
Serial.println(stateA);
controlMotor(stateA,!stateA);
}
}
void controlMotor(byte A, byte B){
digitalWrite(motorA, A);
digitalWrite(motorB, B);
}