Ok that is the code:
const int sharpPin = 2;
const int sharpPin2 = 4;
const int ledPin = 13;
const int motorPin1 = 11;
const int motorPin2 = 10;
int sharpState = 0;
int sharpState2 = 0;
void setup() {
Serial.begin(9600);
pinMode (motorPin1, OUTPUT);
pinMode (motorPin2, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(sharpPin, INPUT);
pinMode(sharpPin2, INPUT);
}
void loop(){
sharpState = digitalRead(sharpPin);
sharpState2 = digitalRead(sharpPin2);
if (sharpState == LOW) {
analogWrite(motorPin2, LOW);
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
delay(200);
analogWrite(motorPin2, 100);
// turn LED off:
digitalWrite(ledPin, LOW);
}
if (sharpState2 == LOW) {
digitalWrite (motorPin1, LOW);
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
delay(200);
analogWrite(motorPin1, 100);
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
Soon I will add l293 integral circuit,to control the motors in both directions.
Now the motors are controled via 2N3904 (work like a switch.)