Switch LED on/off based using 5 levels of potentiometer sensitivity

Hello,

I am struggling with my project to make it work.
Basically, I would like to switch an LED on as long as a potentiometer is rotating.
I would also like to change the sensitivity of the potentiometer to different levels.

Is this possible with Arduino?

Here is my code:

int p = 1;
int current_sensorValue = 0;
int new_Value = 0;


void setup() {
Serial.begin(9600);

int min = 5;
int max = 13;
for (int i=5; i<14; i++)
  {
    digitalWrite(i, OUTPUT);
  }

    digitalWrite(10,LOW);
    digitalWrite(9, LOW);
    digitalWrite(8, LOW);
    digitalWrite(7, LOW);
    digitalWrite(6, LOW);
}

void loop() {

int buttState = digitalRead(4);
 if (buttState == HIGH)
    {
       p++;
    }

Serial.println(p);
delay(500);

if (p==1)
  {
    digitalWrite(10,HIGH);
    digitalWrite(9, LOW);
    digitalWrite(8, LOW);
    digitalWrite(7, LOW);
    digitalWrite(6, LOW);

    current_sensorValue = analogRead(A0)/2;   
  }

else if (p==2)
  {
    digitalWrite(10,HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(8, LOW);
    digitalWrite(7, LOW);
    digitalWrite(6, LOW);

   current_sensorValue = analogRead(A0)/4; 
       
        
  }
else if (p==3)
  {
    digitalWrite(10,HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(8, HIGH);
    digitalWrite(7, LOW);
    digitalWrite(6, LOW);

    current_sensorValue = analogRead(A0)/6; 
        
    
  }

else if (p==4)
  {
    digitalWrite(10,HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(8, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(6, LOW);

    current_sensorValue = analogRead(A0)/8; 
     
       
  }

else if (p==5)
  {
    digitalWrite(10,HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(8, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(6, HIGH);


    current_sensorValue = analogRead(A0)/10; 
        
  }

else if (p==6)
  {
    p=1;
  }

     if (current_sensorValue != new_Value)  
            {
               digitalWrite(4, HIGH);
            }
            new_Value = current_sensorValue;        
        
}

Any help would be appreciated.

Pin 4 is the LED?
You only seem to be writing it high.
Perhaps you should write it LOW if current_sensorValue == new_Value, although good luck getting a stable ADC read from a pot even if it’s not changing.

You may want to have a look at the state change detection tutorial to see how to count button presses. That example increments when the button becomes pressed as opposed to while the button is pressed. Then you can get rid of the delay that makes the program unresponsive.

You need to define two things. How much change in the potentiometer value is required to indicate a real (meaningful) change. How long should the reading remain the same, with the tolerance specified by the first question, before you decide that no change is happening.

You can’t write code with knowing those two things. When you do know them, writing the code is trivial.

PaulS:
You need to define two things. How much change in the potentiometer value is required to indicate a real (meaningful) change. How long should the reading remain the same, with the tolerance specified by the first question, before you decide that no change is happening.

You can't write code with knowing those two things. When you do know them, writing the code is trivial.

I don't know this information. I was hopping to do it by trial an error.