Stap 5:
Dit is een eenvoudige regel volgeling programma
int leftInput = 3;
int rightInput = 2;
int leftMotor = 1;
int rightMotor = 0;
int leftValue = 0;
int rightValue = 0;
VOID Setup {}
Serial.begin(9600);
pinMode (leftMotor, OUTPUT);
pinMode (rightMotor, OUTPUT);
}
void loop {}
leftValue = digitalRead(leftInput);
rightValue = digitalRead(rightInput);
Als (leftValue == HIGH & & rightValue == HIGH)
{
digitalWrite (leftMotor, hoge); digitalWrite (rightMotor, hoge);
} else {}
Als (leftValue == LOW & & rightValue == HIGH)
{
digitalWrite (leftMotor, laag); digitalWrite (rightMotor, hoge);
} else {}
Als (leftValue == HIGH & & rightValue == laag)
{
digitalWrite (rightMotor, laag);
digitalWrite (leftMotor, hoge);
} else {}
Als (leftValue == LOW & & rightValue == laag)
{
digitalWrite (rightMotor, laag);
digitalWrite (leftMotor, laag);
}}
}
}}