int1 = 3;
int2 = 4;
const byte buttonPin = 4; // const because they won't
change
const byte KNOB = A0; // use A notation for analog inputs
bool buttonState = 0; // current state of the button
bool lastButtonState = 0; // previous state of the button
bool adjustspeed= true; // create the flag variable
void setup()
{
Serial.begin(115200);
pinMode(int1, OUTPUT);
pinMode(int2, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop()
{
readButton();
if (adjustspeed == true)
{
// Read the value of the potentiometer knob
int knobValue = analogRead(KNOB);
// Map the potentiometer value to 1-255
int intensity = map(knobValue, 1, 1024, 1, 255);
// Output the respective value to the motor
analogWrite( " ------------------ ", intensity); // how can i mention int1 and int2 of motor in analog write
}
}
void readButton()
{
static unsigned long timer = 0;
unsigned long interval = 50; // check switch 20 times per
second
if (millis() - timer >= interval)
{
timer = millis();
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
// compare the new buttonState to its previous state
if (buttonState != lastButtonState)
{
if (buttonState == LOW)
{
// if the current state is LOW then the button
// went from off to on:
adjustspeed = !adjustspeed; // toggle value of adustspeed
//Serial.println(adjustspeed);
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
}
}
hi
, i am doing a small but interesting project , will u help me.
i want that , when i press the push button the current flowing to motor controlled by potentiometer should not not be changed after the push button is pressed .” In simple ways arduino should not take any order from potentiometer until the button is pressed again to give it back it's control .
But i don't know how to disables it's command for a while and give it back after the button is pressed.
please let me know how can i turn my code into what i told u. ![]()