Led control using potentiometer

Hello! Im making shool project and I need some help in programming.
Topic of my project is to control 5 LEDs with potentiometer, so when I start to rotate potentiometer diferent leds turning on in order from 1st to 5th.
I tryed but it seems incorrect ,here is my code :

const int analogInPin = A0;
int anOutPin1 = 3;
int anOutPin2 = 5;
int anOutPin3 = 6;
int anOutPin4 = 9;
int anOutPin5 = 10;

int sensorValue = 0;
int outputValue = 0;


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

}

void loop() {
 sensorValue = analogRead(analogInPin);
 if (sensorValue == 204.6)
 {
   led1();
 }
 if (sensorValue == 409.6)
 {
   led2();
 }
  if (sensorValue == 613.8)
 {
   led3();
 }
  if (sensorValue == 818.4)
 {
   led4();
 }
  if (sensorValue == 1023)
 {
   led5();
 }
}

//prepoznavanje ledica radi lakseg nacina rada
void led1()
{
 analogWrite(anOutPin1, HIGH);
 analogWrite(anOutPin2, LOW);
 analogWrite(anOutPin3, LOW);
 analogWrite(anOutPin4, LOW);
 analogWrite(anOutPin5, LOW);
}  
void led2()
{
 analogWrite(anOutPin1, LOW);
 analogWrite(anOutPin2, HIGH);
 analogWrite(anOutPin3, LOW);
 analogWrite(anOutPin4, LOW);
 analogWrite(anOutPin5, LOW);
}  
void led3()
{
 analogWrite(anOutPin1, LOW);
 analogWrite(anOutPin2, LOW);
 analogWrite(anOutPin3, HIGH);
 analogWrite(anOutPin4, LOW);
 analogWrite(anOutPin5, LOW);
}  
void led4()
{
 analogWrite(anOutPin1, LOW);
 analogWrite(anOutPin2, LOW);
 analogWrite(anOutPin3, LOW);
 analogWrite(anOutPin4, HIGH);
 analogWrite(anOutPin5, LOW);
}  
void led5()
{
 analogWrite(anOutPin1, LOW);
 analogWrite(anOutPin2, LOW);
 analogWrite(anOutPin3, LOW);
 analogWrite(anOutPin4, LOW);
 analogWrite(anOutPin5, HIGH);
}  

//kraj

Please help :smiley:

You need to make these ranges with integer #s (0 to 1023)
if (sensorValue == 204.6)
as that' what analogRead read returns, and it's doubtful your pot reading will return the 5 specific numbers you may put in there.

if (sensorValue == someNumber)
Use a range as alluded to:
if (sensorValue >= someNumber && sensorValue <= someOtherNumber)

Why are you use analogWrite and not digitalWrite?
.

OK, all sorts of confusion here!

Never mind.

“int” means an integer or “whole number”. If you declare a value in “C” as an “int”, then that is how it is allocated, nothing other than a 16-bit integer (a value between -32,768 to 32,767) is allocated.

Now if you attempt to compare such a number for equality to a “float” - such as 204.6 - it will obviously never match because neither 204 nor 205 will ever be equal to 204.6.

Now another matter is purely procedural in terms of the forum here - you need to go and read the instructions, then go back and modify your post (use the “More → Modify” option to the bottom right of the post) to mark up the code as such so we can review it conveniently and accurately.

Until you reply and demonstrate that you understand these points that have been made so far, there is absolutely no point working through the other problems with the code, so I will leave it at that for the present.

Thanks to all who replyed, i fixed my code and it works, yayyyyy! :smiley:
Next time ill mark code! :slight_smile:
:smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley:

luco19:
Next time ill mark code! :slight_smile:

Why not just do it now?

Paul__B:
Why not just do it now?

Ok i did :smiley:

That's more like it.