All submissions

Seesaw Effect Using LEDs

Solving Approach:

How do you plan to solve it?

 

 

Code

const int ledPins[] = {11, 10, 9, 6, 3};
int potValue = 0;

void setup() {
  for (int i = 0; i < 5; i++) {
    pinMode(ledPins[i], OUTPUT);
  }
}

void loop() {
  potValue = analogRead(A0);
  setLEDBrightness(potValue);
}

void setLEDBrightness(int potValue) {
  int brightnessLed0 = map(potValue, 0, 1023, 0, 255);
  int brightnessLed1 = map(potValue, 0, 1023, 64, 191);
  int brightnessLed2 = 127;
  int brightnessLed3 = map(potValue, 0, 1023, 191, 64);
  int brightnessLed4 = map(potValue, 0, 1023, 255, 0);

  if (brightnessLed4 < 2) {
    brightnessLed4 = 0;
  }

  analogWrite(ledPins[0], brightnessLed0);
  analogWrite(ledPins[1], brightnessLed1);
  analogWrite(ledPins[2], brightnessLed2);
  analogWrite(ledPins[3], brightnessLed3);
  analogWrite(ledPins[4], brightnessLed4);

  delay(10);
}



 

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!