Seesaw Effect Using LEDs

AliToufaily
AliToufaily

Solving Approach:

How do you plan to solve it?

Read the potentiometer on A0 with default reference: 

A0 Potentiometer reading 0..1023  maps  to 0 ..100% . 

Control brightness by pwm : duty cycle 0 .. 255  maps to brightness 0 to 100%

Potentiometer reading=x

I did this in EXCEL sheet: 

Percentage-wise:

potentiometer LED0LED1LED2LED3LED4
slope, a 10.50-0.5-1
intercept, b 0255075100
potentiometer, xpercentage, xy=ax+by=ax+by=ax+by=ax+by=ax+b
 00255075100
 252537.55062.575
 505050505050
 757562.55037.525
 1001007550250

 

using raw measurements, potentometer range 0 to 1023.

Controlling brightness by pwm: 

0 % maps to 0 on the pwm pin

25% maps to 63 analogWrite on th epwm pin

50 % map sto 127

75% maps to 191

100% maps to 255

potentiometer, xraw, xLED0LED1LED2LED3LED4
 0063127191255
 2566395127159191
 512127127127127127
 7681911591279563
 1023255191127630

 

 

using 330Ohm resistors and 10K pot.

Code

/*Paste your code here*/
int potPin = 0;
int pwmPin[5] = {10, 9, 6, 5, 3};

  int pot;
  int poti;

void setup()
{
  int i;
  poti=1023;
  for (i=0; i < 5; i++) {
    pinMode(pwmPin[i], OUTPUT);
  }
  Serial.begin(9600);
}


void loop()
{

  int brightness[5];
  int i;

    pot = analogRead(potPin);
    // print only if potentiometer is moved
    if (pot != poti) {
      Serial.print("Potentiometer: ");
      Serial.println(pot);
      brightness[0] = map(pot, 0, 1023, 0, 255) ;
      brightness[1] = map(pot, 0, 1023, 63, 191) ;
      brightness[2] = 127;
      brightness[3] = map(pot, 0, 1023, 191, 63) ;
      brightness[4] = map(pot, 0, 1023, 255, 0) ;
  

    for (i=0; i < 5; i++) {
      analogWrite(pwmPin[i], brightness[i]);
      Serial.print(brightness[i]);
      Serial.print("  ");
    }
    Serial.println("");
    poti=pot;
  }
  delay(100);
}


 

Output

Video

Add video of output (know more)

 

 

 

 

Photo of Output

Add a photo of your hardware showing the output.

 

 

 

 

 

Submit Your Solution

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