#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(A2) * 5)/1023;
buttonBState = (analogRead(A3) * 5)/1023;
// Update button press states with debounce
if (buttonAState >= 2.0 && buttonAState <= 2.8) {
startTime = millis();
tuneUp = true;
} else if (buttonAState <= 1.5) {
startTime = millis();
tuneDown = true;
}else {
tuneUp = false;
tuneDown = false;
}
if (buttonBState >= 2.0 && buttonBState <= 2.8) {
startTime = millis();
volUp = true;
} else if (buttonBState <= 1.5) {
startTime = millis();
volDown = true;
}else {
volUp = false;
volDown = false;
}
// Check button states and press duration
unsigned long pressDuration = millis() - startTime;
// Check for the tune button
if (tuneUp && pressDuration < 150) {
digitalWrite(redLed, HIGH);
} else if (tuneDown && pressDuration < 150) {
digitalWrite(greenLed, HIGH);
} else if (tuneUp) {
digitalWrite(redLed, LOW);
} else if (tuneDown) {
digitalWrite(greenLed, LOW);
}
// Check for the volume button
if (volUp) {
digitalWrite(yellowLed, HIGH);
} else if (volDown) {
digitalWrite(blueLed, HIGH);
}
/*
// Reset code
if (tuneUp && volUp) {
si4735.setFM(8700, 10850, 8750, 10);
delay(100);
} else if (tuneDown && volDown) {
si4735.setFM(8700, 10850, 10850, 10);
delay(100);
}
*/
// Print voltages to the LCD
lcd.setCursor(0, 0);
lcd.print("Voltage A0: ");
lcd.setCursor(13, 0);
lcd.print(buttonAState);
lcd.setCursor(0, 1);
lcd.print("Voltage A1: ");
lcd.setCursor(13, 1);
lcd.print(buttonBState);
delay(100); // Adjust delay as needed
}