Potentiometer in sync with slider widget

Im trying to sync a potentiometer with the slider widget. I figured out how to sync a button with a widget button but i can’t seen to figure this out.
Can anyone point me in the right direction ?
Thanks

1 Like

Blynk.virtualWrite(slider, analogRead(potPin));

When not being more specific that should do it

Unfortunately, short of motorizing the pot (something like how a Servo works, but without the hold position tendencies), then every time you adjust the slider, it will readjust back to the potentiometer position… so it really becomes a one way sync… or more precisely, just an position indicator for the potentiometer, and a Level or Graph Widget would work just as well in that case.

I just figured this out 10 seconds ago when i finished my code with the use of an old post of yours :stuck_out_tongue:

int potPin= A0;  //Declare potPin to be analog pin A0
int LEDPin= D4;  // Declare LEDPin to be arduino pin 9
int readValue;  // Use this variable to read Potentiometer
int writeValue; // Use this variable for writing to LED
int brightness = 0; // Start off with LED off

void setup() {
  Serial.begin(9600);      // turn on Serial Port
  Blynk.begin(auth, ssid, pass);
  pinMode(potPin, INPUT);  //set potPin to be an input
  pinMode(LEDPin, OUTPUT); //set LEDPin to be an OUTPUT
}

BLYNK_WRITE(V1) // Slider widget function, runs everytime slider is adjusted.
{
  brightness = param.asInt(); // Get slider value.
  analogWrite(LEDPin, brightness); //Send data to LED
}

void Potentiometer()
{
  readValue = analogRead(potPin); //Read data of Potentiometer
  brightness = (255./1023.) * readValue; //Calculate Write Value for LED
  Blynk.virtualWrite(V1, brightness); //Send feedback to slider Widget
  analogWrite(LEDPin, brightness); //Send data to LED
}

void loop() {
 Blynk.run();
 Potentiometer();
}

I might switch to buttons in stead or i should try to figure out how to make Blynk ignore potentiometer input when the slider is being adjusted.

Some form of comparator flag? Give the slider priority of movement and only readjust if pot moves from last pre-slider adjustment position.

1 Like

I guess that should work. I’ll try it out :slight_smile:

This is where i got so far now its just a matter of resyncing the slider and the potentiometer without looping the whole thing.

    int potPin= A0;  //Declare potPin to be analog pin A0
    int LEDPin= D4;  // Declare LEDPin to be arduino pin 9
    int readValue;  // Use this variable to read Potentiometer
    int writeValue; // Use this variable for writing to LED
    int brightness = 0; // Start off with LED off
    int potValue ;

void setup() {
  Serial.begin(9600);      // turn on Serial Port
  Blynk.begin(auth, ssid, pass);
  pinMode(potPin, INPUT);  //set potPin to be an input
  pinMode(LEDPin, OUTPUT); //set LEDPin to be an OUTPUT
  potValue = analogRead(potPin);
}

BLYNK_WRITE(V1) // Slider to led
{

  brightness = param.asInt(); // Get slider value.
  analogWrite(LEDPin, brightness); //Send data to LED
}

void Potentiometer() // Potentiometer to led
{
  readValue = analogRead(potPin);
  if(potValue != readValue){
    brightness = (255./1023.) * readValue; //Calculate Write Value for LED
    analogWrite(LEDPin, brightness); //Send data to LED
    potValue = analogRead(potPin);
    //Blynk.virtualWrite(V1, brightness); //Send feedback to slider Widget
  }
  delay(300);
}

void loop() {
 Blynk.run();
 Potentiometer();
}