//global array variable
int leds[] = {0, 13, 12, 11, 10, 9, 8, 7}; // Parked, SW, W, NW, N, NE, E, SE
void setup() {
Serial.begin(9600);
for (int i = 0; i <= 7; i++) {
pinMode(leds[i], OUTPUT);
}
pinMode(A0, INPUT);
}
void loop() {
int sensorValue = analogRead(A0);
float voltage = sensorValue * (5.0 / 1023.0);
// Map potentiometer value to 0-7
int direction = map(sensorValue, 0, 1023, 0, 7);
// Because an array's first variable is in position 0; int leds[] has a range of 0-6
// Thus the 0 is used as a neutral/parked position
for (int i = 0; i <= 7; i++) { // 7 == stopped/parked so that it's functional
if (i == direction) {
digitalWrite(leds[i], HIGH); // Turn on the LED for the current direction
} else {
digitalWrite(leds[i], LOW); // Turn off all other LEDs
}
}
// Management code to gain a deeper understanding of what is occurring inside the machine
Serial.print("Analog Voltage: ");
Serial.println(voltage);
Serial.print("ADC Reading: "); //ADC stands for Analog to Digital Converter
Serial.println(sensorValue);
delay(100); // This is milliseconds
}