int In1 =7; //the number of L298n h bridge
int In2 =8; // the number of L298n h bridge
int ENA =5; //the number of L298n h bridge
int SPEED =210;
int potVal = A0; // the number of the potentiometer pin
const int pushButton =9; // the number of the pushbutton pin
const int swi_pos2 =11; // the number of the selector switch pin
const int swi_pos3 =12; // the number of the selector switch pin
const int swi_pos4 =13; // the number of the selector switch pin
// variables will change:
int pushState=0 ;
int slecSwitch2= 0;
int slecSwitch3= 0 ;
int slecSwitch4 =0;
void setup()
{
int potVal = analogRead(A0); // Read potentiometer value
int SPEED = map(potVal,0,1023 , 0 , 255); // Map the potentiometer value from 0 to 255
analogWrite(ENA, SPEED); // Send PWM signal to L298N Enable pin
// put your setup code here, to run once:
pinMode (In1 , OUTPUT);
pinMode (In2 , OUTPUT);
pinMode (ENA , OUTPUT);
pinMode(pushButton, INPUT);
pinMode (swi_pos2, INPUT);
pinMode (swi_pos3, INPUT);
pinMode (swi_pos4, INPUT);
}
void loop()
{
pushState = digitalRead (pushButton);
slecSwitch2 = digitalRead (swi_pos2);
slecSwitch3 = digitalRead (swi_pos3);
slecSwitch4 = digitalRead (swi_pos4);
// put your main code here, to run repeatedly:
if ( pushState == HIGH && slecSwitch2 == HIGH)
{
// delay(2000);
digitalWrite(In2,HIGH); // turn direction for forward direction
digitalWrite(In1,LOW);//motor voltage on
}
if ( pushState == HIGH && slecSwitch3 == HIGH)
{
delay(2000);
digitalWrite(In2,LOW); // turn direction for reverse direction
digitalWrite(In1,HIGH);//motor voltage on
}
if ( pushState == HIGH && slecSwitch4 == HIGH)
{
delay(2000);
digitalWrite(In2,LOW); // turn direction for reverse direction(ultrasonic sensor)
digitalWrite(In1,HIGH);//motor voltage on
}
}