potentiometer LED

Hi!

My components are 10 LEDs.. 10 resistors.. 1 potentiometer

1 - HIGH
0 - LOW

When rotating the potentiometer from 0 to its max.. It should go like this

0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0
1 1 1 0 0 0 0 0 0 0
1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0

But when it rotate it back to zero it should go like this

1 1 1 1 1 0 0 0 0 0
1 1 1 1 0 0 0 0 0 1
1 1 1 0 0 0 0 0 1 1
1 1 0 0 0 0 0 1 1 1
1 0 0 0 0 0 1 1 1 1
0 0 0 0 0 1 1 1 1 1

And turning it max again will follow the trend above

We were taught how to use IF - Else statement and gave us this as a laboratory exercise.

That’s a nice exercise they gave you indeed. You are lucky !

(You have a challenge that at min value you have two representations )

Please post the code that you have tried and if it doesn't work give an explanation as to what it does and how it differs from your expectations. Please remember to use the code tags (the </> button on the text editor).
This is a place to learn, not a place to get people to do your lab assignments for you. I (and many others) are willing to help you if you put in effort yourself, so please show what you have tried as evidence of that.

Yes.. Sorry about that..
My code so far is this

int ledpin1=3;
int ledpin2=4;
int ledpin3=5;
int ledpin4=6;
int ledpin5=7;
int ledpin6=8;
int ledpin7=9;
int ledpin8=10;
int ledpin9=11;
int ledpin10=12;

int th1=102;
int th2=204;
int th3=306;
int th4=408;
int th5=510;
int th6=612;
int th7=714;
int th8=816;
int th9=918;
int th10=1020;

void setup() {
  Serial.begin(9600);
  pinMode(ledpin1,OUTPUT);
  pinMode(ledpin2,OUTPUT);
  pinMode(ledpin3,OUTPUT);
  pinMode(ledpin4,OUTPUT);
  pinMode(ledpin5,OUTPUT);
  pinMode(ledpin6,OUTPUT);
  pinMode(ledpin7,OUTPUT);
  pinMode(ledpin8,OUTPUT);
  pinMode(ledpin9,OUTPUT);
  pinMode(ledpin10,OUTPUT);
  

}

void loop() {
int sensorValue=analogRead(A0);
  Serial.println(sensorValue);
  delay(100);

if(sensorValue>=15 && sensorValue<=th2){
  digitalWrite(ledpin1,LOW);
  digitalWrite(ledpin2,LOW);
  digitalWrite(ledpin3,LOW);
  digitalWrite(ledpin4,LOW);
  digitalWrite(ledpin5,LOW);
  digitalWrite(ledpin6,HIGH);
  digitalWrite(ledpin7,HIGH);
  digitalWrite(ledpin8,HIGH);
  digitalWrite(ledpin9,HIGH);
  digitalWrite(ledpin10,HIGH);
  
}
else if(sensorValue>=th2 && sensorValue<=th4){
  digitalWrite(ledpin1,HIGH);
  digitalWrite(ledpin2,LOW);
  digitalWrite(ledpin3,LOW);
  digitalWrite(ledpin4,LOW);
  digitalWrite(ledpin5,LOW);
  digitalWrite(ledpin6,LOW);
  digitalWrite(ledpin7,HIGH);
  digitalWrite(ledpin8,HIGH);
  digitalWrite(ledpin9,HIGH);
  digitalWrite(ledpin10,HIGH);


}

else if(sensorValue>=th4 && sensorValue<=th6){
  digitalWrite(ledpin1,HIGH);
  digitalWrite(ledpin2,HIGH);
  digitalWrite(ledpin3,LOW);
  digitalWrite(ledpin4,LOW);
  digitalWrite(ledpin5,LOW);
  digitalWrite(ledpin6,LOW);
  digitalWrite(ledpin7,LOW);
  digitalWrite(ledpin8,HIGH);
  digitalWrite(ledpin9,HIGH);
  digitalWrite(ledpin10,HIGH);


}

else if(sensorValue>=th6 && sensorValue<=th8){
  digitalWrite(ledpin1,HIGH);
  digitalWrite(ledpin2,HIGH);
  digitalWrite(ledpin3,HIGH);
  digitalWrite(ledpin4,LOW);
  digitalWrite(ledpin5,LOW);
  digitalWrite(ledpin6,LOW);
  digitalWrite(ledpin7,LOW);
  digitalWrite(ledpin8,LOW);
  digitalWrite(ledpin9,HIGH);
  digitalWrite(ledpin10,HIGH);


}

else if(sensorValue>=th8 && sensorValue<=th10){
  digitalWrite(ledpin1,HIGH);
  digitalWrite(ledpin2,HIGH);
  digitalWrite(ledpin3,HIGH);
  digitalWrite(ledpin4,HIGH);
  digitalWrite(ledpin5,LOW);
  digitalWrite(ledpin6,LOW);
  digitalWrite(ledpin7,LOW);
  digitalWrite(ledpin8,LOW);
  digitalWrite(ledpin9,LOW);
  digitalWrite(ledpin10,HIGH);

}

else if(sensorValue>=th10 && sensorValue<=1023){
  digitalWrite(ledpin1,HIGH);
  digitalWrite(ledpin2,HIGH);
  digitalWrite(ledpin3,HIGH);
  digitalWrite(ledpin4,HIGH);
  digitalWrite(ledpin5,HIGH);
  digitalWrite(ledpin6,LOW);
  digitalWrite(ledpin7,LOW);
  digitalWrite(ledpin8,LOW);
  digitalWrite(ledpin9,LOW);
  digitalWrite(ledpin10,LOW);

}



}
/code]

But this can only do the 2nd part of what we were trying to do.. What can I change/add to my code?

Since you want to have a different output based on the direction the potentiometer is being turned, you need to somehow determine the direction. Can you think of a way to do that?

You need to write code to find out if the potentiometer is going up or down, then based on the value decide what the led state should be

To know the direction (up or down) you need to memorize the previous value and compare to the new one

You could calculate a step number which you could obtain by dividing the pot value that goes between 0 and 1023 by xxx to get an integer between 0 and 4

Then if the step number z has changed and is going up then display led pattern for step z-up and if it has changed going down then display led pattern for step z-down

int ledpin1=3;
int ledpin2=4;
int ledpin3=5;
int ledpin4=6;
int ledpin5=7;
int ledpin6=8;
int ledpin7=9;
int ledpin8=10;
int ledpin9=11;
int ledpin10=12;

Do you really need an int variable to store values from 3 to 12? Perhaps an unsigned long or a long long would be more appropriate.

When you start numbering variables, you REALLY should think arrays. You'd have about 10% as much code with arrays and for loops.