Solving Approach:

How do you plan to solve it?

potentiometer wiper: A3
led: anode to digital pin 10, 9, 6, 5, 3
Value on A3: 0-1023
Led 0 on when potval > 0, brightness varies between potval 0 to 204
Led 1 on when potval > 204, brightness varies between potval 204 to 409
Led 2 on when potval > 409, brightness varies between potval 409 to 614
Led 3 on when potval > 614, brightness varies between potval 614 to 819
Led 4 on when potval >819, brightness varies between potval 819 to 1023

 

Code

/*Paste your code here*/
const int led[5] = {10, 9, 6, 5, 3};
const int potpin = A3;
int potval = 0;
void setup()
{
  for(int i=0;i<5;i++){
    pinMode(led[i], OUTPUT);
  }
}

void loop()
{
  potval = analogRead(potpin);
  led_write(potval);
  delay(10);
}

void led_write(int val){
  int pwm_val = val;
  for(int j=0;j<5;j++){
    analogWrite(led[j], min_max(pwm_val));
    pwm_val -= 205;
  }
}

int min_max(int val) {
  if (val > 255) return 255;
  if (val < 0)   return 0;
  return val;
}


 

Output

Video

Add video of output (know more)

 

 

 

 

 

Photo of Output

Add a photo of your hardware showing the output.

 

 

 

 

Upvote
Downvote

Submit Your Solution

Note: Once submitted, your solution goes public, helping others learn from your approach!