#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
const int redLed = 12;
const int greenLed = 10;
const int yellowLed = 8;
const int blueLed = 7;
//Define constants for buttons and variables
float buttonAState = 0.0;
float buttonBState = 0.0;
unsigned long startTime = 0;
bool tuneUp = false;
bool tuneDown = false;
bool volUp = false;
bool volDown = false;
void setup() {
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(yellowLed, OUTPUT);
pinMode(blueLed, OUTPUT);
Serial.begin(9600);
// LCD stuff
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Issokay");
lcd.setCursor(0, 1);
lcd.print(" ANDREW ");
delay(1000);
lcd.clear();
}
void loop() {
// Read the seek station buttons states
buttonAState = (analogRead(A0) * 5.0)/1023;
buttonBState = (analogRead(A1) * 5.0)/1023;
// Update button press states with debounce
if (buttonAState >= 2.0 && buttonAState <= 3.0) {
startTime = millis();
tuneUp = true;
} else if (buttonAState <= 1.0) {
startTime = millis();
tuneDown = true;
} else {
tuneUp = false;
tuneDown = false;
}
if (buttonBState >= 2.0 && buttonBState <= 3.0) {
startTime = millis();
volUp = true;
} else if (buttonBState <= 1.0) {
startTime = millis();
volDown = true;
} else {
volUp = false;
volDown = false;
}
if (tuneUp){
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
Serial.println("Tuning up right now");
Serial.print("The value read is: ");
Serial.println(buttonAState);
} if (tuneDown){
digitalWrite(greenLed, HIGH);
digitalWrite(redLed, LOW);
Serial.println("Tuning down right now");
Serial.print("The value read is: ");
Serial.println(buttonAState);
} if (volUp) {
digitalWrite(yellowLed, HIGH);
digitalWrite(blueLed, LOW);
Serial.println("Turning Volume up right now");
Serial.print("The value read is: ");
Serial.println(buttonBState);
} if (volDown) {
digitalWrite(blueLed, HIGH);
digitalWrite(yellowLed, LOW);
Serial.println("Turning Volume down right now");
Serial.print("The value read is: ");
Serial.println(buttonBState);
} if (!tuneUp && !tuneDown && !volUp && !volDown) {
Serial.print("Tuning is Out of range: ");
Serial.println(buttonAState);
Serial.print("Volume is Out of range: ");
Serial.println(buttonBState);
}
// Print voltages to the LCD
lcd.setCursor(0, 0);
lcd.print("Voltage A0: ");
lcd.setCursor(13, 0);
lcd.print(analogRead(A0));
lcd.setCursor(0, 1);
lcd.print("Voltage A1: ");
lcd.setCursor(13, 1);
lcd.print(analogRead(A1));
delay(200); // Adjust delay as needed
}