Hi--
I am running a DC motor controlled with a 10k potentiometer. I want to get the motor to only run when one of two push buttons/snap action switches are pushed. I have tried what other recommended by putting my potentiometer analog read and write into an if statement when the push button is low. However, I am not sure what I am doing wrong. When i upload my current code:
int analogInPin = A0;
int transistorPin = 3;
int sensorValue = 0;
int outputValue = 0;
int switch1 = 11;
int switch2 = 10;
void setup()
{
Serial.begin(9600);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(transistorPin, OUTPUT);
pinMode(switch1, INPUT_PULLUP);
pinMode(switch2, INPUT_PULLUP);
}
void loop()
{int val1 = digitalRead(switch1);
int val2 = digitalRead(switch2);
if (val1 == LOW)
{
int sensorValue = analogRead(analogInPin)/4;
int outputValue = map(sensorValue, 0, 1023, 0, 255);
analogWrite(transistorPin, sensorValue);}
if (val2 == LOW)
{
int sensorValue = analogRead(analogInPin)/4;
int outputValue = map(sensorValue, 0, 1023, 0, 255);
analogWrite(transistorPin, sensorValue);}
}
it still only runs as if there is only a potentiometer. I am pretty sure everything is wired correctly.
Thanks!