//Brightness Scale const byte High = 255; const byte Low = 30; const byte Dim = 4; const byte Off = 0; //Potentiometer Pin byte potPin = A5; //LED Pins byte pins[] = {11,10,9,6,3}; //0,1,2,3,4 //Potentiometer Value Tracking int potValue = 0; int lastPotValue = 0; //LED State Tracking byte LEDOn = 0; void setup() { //Initialize Input and Output Pins pinMode(pins[0],OUTPUT); pinMode(pins[1],OUTPUT); pinMode(pins[2],OUTPUT); pinMode(pins[3],OUTPUT); pinMode(pins[4],OUTPUT); pinMode(potPin,INPUT); } void loop() { //Check potentiometer movement and move light accordingly checkPotDirection(); //Fade the lights next to the one that is on fadeAway(); } void fadeAway(){ if(LEDOn == 0){ analogWrite(pins[1], Low); analogWrite(pins[2], Dim); analogWrite(pins[3], Off); analogWrite(pins[4], Off); } else if(LEDOn == 1){ analogWrite(pins[0], Low); analogWrite(pins[2], Low); analogWrite(pins[3], Dim); analogWrite(pins[4], Off); } else if(LEDOn == 2){ analogWrite(pins[0], Dim); analogWrite(pins[1], Low); analogWrite(pins[3], Low); analogWrite(pins[4], Dim); } else if(LEDOn == 3){ analogWrite(pins[0], Off); analogWrite(pins[1], Dim); analogWrite(pins[2], Low); analogWrite(pins[4], Low); } else if(LEDOn == 4){ analogWrite(pins[0], Off); analogWrite(pins[1], Off); analogWrite(pins[2], Dim); analogWrite(pins[3], Low); } } void checkPotDirection(){ //Read the potentiometer value and then map it to 10 to decrease sensitivity potValue = analogRead(potPin); potValue = map(potValue, 0, 1023, 0, 10); //If the value has increased move the light right, if it decreased move the light left if(lastPotValue > potValue){ moveRight(); } else if (lastPotValue < potValue){ moveLeft(); } lastPotValue = potValue; } void moveLeft(){ if(LEDOn > 0){ LEDOn -= 1; analogWrite(pins[LEDOn], 255); } } void moveRight(){ if(LEDOn < 4){ LEDOn += 1; analogWrite(pins[LEDOn], 255); } }