//Author: Stephen Mathis //Project: Final Exam Project - LED Control int potPin = A5; // Sets the potentiometer to A5 on the Arduino int selectedLED = 0; // Sets the chosen LED int potPosition = 0; // This sets the starting position of the potentiometer int arrLED[] = {13, 12, 11, 10, 9}; // LED array to make choosing the desired LED a little easier void setup() { // This sets the serial begin and the pinMode() for each LED in the Array and the potentiometer Serial.begin(9600); pinMode(potPin, INPUT); pinMode(arrLED[0], OUTPUT); pinMode(arrLED[1], OUTPUT); pinMode(arrLED[2], OUTPUT); pinMode(arrLED[3], OUTPUT); pinMode(arrLED[4], OUTPUT); }//end setup() void loop() { potPosition = analogRead(potPin); // Read the potentiometer value selectedLED = map(potPosition, 0, 1023, 0, 4); // This will map the potentiometer value to a number between 0 and 4 // which points to the index in the LED array delay(150); if(potPosition == 1023) { selectedLED = 4; }//end if() //Loop through all the LED indexes and compare them to the potentiometer values for(int i = 0; i < 5; i++) { if(selectedLED == i) { clearPins(); // Clears the pins: got this idea from the Arduino website if(i == 0) { analogWrite(arrLED[i], 255); analogWrite(arrLED[i+1], 30); analogWrite(arrLED[i+2], 10); }//end if() else if(i == 1) { analogWrite(arrLED[i-1], 30); analogWrite(arrLED[i], 255); analogWrite(arrLED[i+1], 30); analogWrite(arrLED[i+2], 10); }//end else if() else if(i == 2) { analogWrite(arrLED[i-2], 10); analogWrite(arrLED[i-1], 30); analogWrite(arrLED[i], 255); analogWrite(arrLED[i+1], 30); analogWrite(arrLED[i+2], 10); }//end else if() else if(i == 3) { analogWrite(arrLED[i-2], 10); analogWrite(arrLED[i-1], 30); analogWrite(arrLED[i], 255); analogWrite(arrLED[i+1], 30); }//end else if() else if(i == 4) { analogWrite(arrLED[i-2], 10); analogWrite(arrLED[i-1], 30); analogWrite(arrLED[i], 255); }//end else if() }//end if() }//end for() }//end loop() //Again, I got the idea for this method on the Arduino website //It helps with fading the LEDs and making sure the last LEDs are off and the other start at bright and get dimmer void clearPins() { for(int i = 0; i < 5; i++) { digitalWrite(arrLED[i], LOW); }//end for() }//end clearPins()