int LEDs[] = {5,6,9,10,11};//To store which pins the leds are in int potPin = A0; //Potentiometer int LED = 0; //Selected LED int pos = 0; //position of potentiometer void setup() { //Set pinmode for LEDs and Potentiometer Serial.begin(9600); pinMode(LEDs[0], OUTPUT); pinMode(LEDs[1], OUTPUT); pinMode(LEDs[2], OUTPUT); pinMode(LEDs[3], OUTPUT); pinMode(LEDs[4], OUTPUT); pinMode(potPin, INPUT); } void loop() { //Read potentiometer value pos = analogRead(potPin); //Map the value to a number between 0 and 4 so it will point to an LED's index LED = map(pos, 0, 1023, 0, 4); delay(100); //Eliminates most of the issue with the map function not properly mapping the 1023 if(pos == 1023) { LED = 4; } //for each i in the array, check if the selected LED = the index for(int i=0; i<5;i++){ if(LED == i){ //Clear the pins clearPins(); //Display the correct pattern based on what the index that was selected is if(i == 0){ analogWrite(LEDs[i], 255); analogWrite(LEDs[i+1], 30); analogWrite(LEDs[i+2], 10); } else if(i == 1){ analogWrite(LEDs[i-1], 30); analogWrite(LEDs[i], 255); analogWrite(LEDs[i+1], 30); analogWrite(LEDs[i+2], 10); } else if(i == 2) { analogWrite(LEDs[i-2], 10); analogWrite(LEDs[i-1], 30); analogWrite(LEDs[i], 255); analogWrite(LEDs[i+1], 30); analogWrite(LEDs[i+2], 10); } else if(i == 3) { analogWrite(LEDs[i-2], 10); analogWrite(LEDs[i-1], 30); analogWrite(LEDs[i], 255); analogWrite(LEDs[i+1], 30); } else if(i == 4) { analogWrite(LEDs[i-2], 10); analogWrite(LEDs[i-1], 30); analogWrite(LEDs[i], 255); } } } } //Helper function to clear all pins void clearPins(){ for(int i=0; i < 5; i++){ digitalWrite(LEDs[i], LOW); } }