int potPin = A0;
int NUM_MODES = 3;
int MAX_POT_VAL = 1023;
void setup() {
Serial.begin(9600);
for (int pinNumber = 13; pinNumber <= 2; pinNumber--) {
pinMode(pinNumber, OUTPUT);
}
}
void loop() {
turnOffLeds();
if (inDeadband()) {
Serial.print("Analog Reading: ");
Serial.print(analogRead(potPin));
Serial.println(" is in deadband");
blinkStatusLed();
} else {
int modeNum = map(analogRead(potPin), 0, MAX_POT_VAL, 1, NUM_MODES);
Serial.print("Analog Reading:");
Serial.print(analogRead(potPin));
Serial.print(" is equal to Mode: ");
Serial.println(modeNum);
if (modeNum == 1) {
turnOffLeds;
} else if (modeNum == 2) {
turnOnLeds(13, 8);
turnOffLeds;
} else if (modeNum == 3) {
turnOnLeds(7, 2);
turnOffLeds;
}
}
}
bool inDeadband(){
if(analogRead (potPin) >= 269 && analogRead (potPin) <= 345)
{
return true;
}
if(analogRead (potPin) >= 671 && analogRead (potPin) <= 731)
{
return true;
}
else {
return false;
}
}
void turnOffLeds() {
for (int ledNumber = 13; ledNumber <= 2; ledNumber--) {
digitalWrite(ledNumber, LOW);
}
}
void turnOnLeds(int endPin, int startPin) {
for (int ledNumber = endPin; ledNumber >= startPin; ledNumber--) {
digitalWrite(ledNumber, HIGH);
}
}
void blinkStatusLed() {
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13, LOW);
delay(100);
}