int potPin = A0; // TODO: Replace this value with the pin number associated with the SIG pin on the potentiometer
int NUM_MODES = 3;
int MAX_POT_VAL = 1023; // TODO: Replace this value with the maximum value reading from the potentiometer
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
void setup() {
// put your setup code here, to run once:
lcd.init();
lcd.backlight();
Serial.begin(9600);
for (int pinNumber = 2; pinNumber <= 13; pinNumber++) {
pinMode(pinNumber, OUTPUT);
}
}
void loop() {
turnOffLeds();
if (inDeadband()) {
lcd.clear();
tone(A3, 200, 500);
lcd.print("In Deadband :) ");
Serial.print("Analog Reading: ");
Serial.print(analogRead(potPin));
Serial.println(" is in deadband");
blinkStatusLed();
} else {
lcd.clear();
int modeNum = 0; //TODO: Replace this with the correct mode number based on the potentiometer reading
if (analogRead(0) >= 280) {
modeNum = 0;
}
if (analogRead(0) >= 290 && analogRead(0) <= 710) {
modeNum = 1;
if ("Anolog Reading: ");
turnOnLeds();
}
if (analogRead(0) >= 720 && analogRead(0) <= 1023) {
modeNum = 2;
if ("Anolog Reading: ");
turnOnLeds();
}
Serial.print("Analog Reading: ");
Serial.print(analogRead(potPin));
Serial.print(" is equal to Mode: ");
Serial.println(modeNum);
if (modeNum == 0) {
turnOnLeds();
}
if (modeNum == 1) {
for (int ledNumber = 8; ledNumber <= 13; ledNumber++) {
digitalWrite(ledNumber, HIGH);
delay(100);
digitalWrite(ledNumber, LOW);
delay(100);
}
}
if (modeNum == 2) {
for (int ledNumber = 2; ledNumber <= 7; ledNumber++) {
digitalWrite(ledNumber, HIGH);
delay(100);
digitalWrite(ledNumber, LOW);
delay(100);
}
}
}
}
bool inDeadband() {
if (analogRead(potPin)>= 280 && analogRead(potPin)<+ 290){
return true;
}
if(analogRead(potPin)>= 710 && analogRead(potPin)<+ 720){
return true;
}
else{
return false;
}
}
void turnOffLeds() {
for (int ledNumber = 2; ledNumber <= 13; ledNumber++) {
digitalWrite(ledNumber, LOW);
}
}
void turnOnLeds() {
for (int ledNumber = 2; ledNumber <= 13; ledNumber++) {
digitalWrite(ledNumber, HIGH);
}
}
void blinkStatusLed() {
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13, LOW);
delay(100);
}