#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);
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
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
for (int pinNumber = 2; pinNumber <= 13; pinNumber++) {
pinMode(pinNumber, OUTPUT);
}
{
// Init
lcd.init();
lcd.backlight();
// Print something
}
}
void loop() {
// put your main code here, to run repeatedly:
turnOffLeds();
if (inDeadband()) {
Serial.print("Analog Reading: ");
Serial.print(analogRead(potPin));
Serial.println(" is in deadband");
blinkStatusLed();
}
else if (0 <= analogRead(potPin) && analogRead(potPin) <= 299){
int modeNum = 0;
Serial.print("Analog Reading: ");
Serial.print(analogRead(potPin));
Serial.print(" is equal to Mode: ");
Serial.println(modeNum);
turnOnLeds();
}
else if (361 <= analogRead(potPin) && analogRead(potPin) <= 659){
int modeNum = 1;
Serial.print("Analog Reading: ");
Serial.print(analogRead(potPin));
Serial.print(" is equal to Mode: ");
Serial.println(modeNum);
Lad(100,3);
}
else if (721 <= analogRead(potPin) && analogRead(potPin) <= 1023){
int modeNum = 2;
Serial.print("Analog Reading: ");
Serial.print(analogRead(potPin));
Serial.print(" is equal to Mode: ");
Serial.println(modeNum);
Around(100,3);
}
if (300 <= analogRead(potPin) && analogRead(potPin) <= 360){
lcd.setCursor(2, 1);
lcd.print("Changing Modes");
}
else if (660 <= analogRead(potPin) && analogRead(potPin) <= 720){
lcd.setCursor(2, 1);
lcd.print("Changing Modes");
}
if (0 <= analogRead(potPin) && analogRead(potPin) <= 299){
lcd.setCursor(2, 1);
lcd.print(" ");
}
if (361 <= analogRead(potPin) && analogRead(potPin) <= 659){
lcd.setCursor(2, 1);
lcd.print(" ");
}
if (721 <= analogRead(potPin) && analogRead(potPin) <= 1023){
lcd.setCursor(2, 1);
lcd.print(" ");
}
}
bool inDeadband() {
/*
In this function you will determine if your potentiometer reading is within a deadband range. You will
be using analogRead as well as if statements.
You should return true if you ARE in deadband and false otherwise.
*/
if (300 < analogRead(potPin) && analogRead(potPin) < 360){
return true;
}
if (660 < analogRead(potPin) && analogRead(potPin) < 720){
return true;
}
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);
}
void Around(int onTime, int repeatCount)
{
int myFirstArray[12] = {
8,7,6,5,4,3,2,9,10,11,12,13 }; // creates an array of 14 integers / elements and initializes / assigns values to those integers
int index;
// Blinks LED's in the order defined by the array
for(index = 0; index <= 13; index++)
{
digitalWrite(myFirstArray[index], HIGH);
delay(100);
digitalWrite(myFirstArray[index], LOW);
delay(100);
}
}
void Lad(int onTime, int repeatCount)
{
for (int pinNumber2 = 2; pinNumber2 <= 13; pinNumber2++){
digitalWrite(pinNumber2, HIGH);
delay(100);
digitalWrite(pinNumber2, LOW);
delay(100);
}
}