Sei sulla pagina 1di 1

Connect Potentiometer center pin to A0 of Arduino

Connect Toggle Switch Right to 7


Connect Toggle Switch Left to 4
Connect center of toggle to GND of Digital side
connect IBT-2 pin 1 (RPWM) to 5
connect IBT-2 pin 1 (LRPWM) to 6

int sensorpin = A0; // center pin of the potentiometer


int inPin = 7; // Toggle Switch right
int inPin = 4; //Toggle Switch Left

int RPWM_Output = 5; // Arduino PWM output pin 5; connect to IBT-2 pin 1 (RPWM)
int LPWM_Output = 6; // Arduino PWM output pin 6; connect to IBT-2 pin 2 (LPWM)

int sensorValue = 0; //value read from pot


int outputValue = 0; //Analog output to the pwm
int val = 0; //variable for reading the pin status

void setup()
{
pinmode(inPin, INPUT);
pinmode(sensorpin, INPUT);
pinMode(RPWM_Output, OUTPUT);
pinMode(LPWM_Output, OUTPUT);
}

void loop()
{
int sensorValue = analogRead(SENSOR_PIN);
outputValue = map(sensorValue, 0, 1023, 0, 255);
val = digitalRead (inPin);

if (val == HIGH) {
digitalWrite(RPWM_Output, HIGH);
analogWrite(RPWM_Output, outputValue);
}
else
{
digitalWrite(LPWM_Output, HIGH);
analogWrite(LPWM_Output, outputValue);
delay (50);
digitalWrite(RPWM_Output, HIGH);
analogWrite(RPWM_Output, outputValue);
delay (50);
}

// print the results to the Serial Monitor:


Serial.print("sensor = ");
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);

// wait 2 milliseconds before the next loop for the analog-to-digital


// converter to settle after the last reading:
delay(2);
}

Potrebbero piacerti anche