#include "SevSeg.h"
SevSeg sevseg; // Instantiate a seven-segment controller object
const int potPin = A0; // Pin connected to the potentiometer
const int ledPin = 1; // Pin connected to the LED
const int buzzerPin = 1; // Pin connected to the piezo buzzer
void setup() {
Serial.begin(9600);
byte numDigits = 4;
byte digitPins[] = {2, 3, 4, 5};
byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13}; // Adjust these pins as needed
bool resistorsOnSegments = false; // 'false' means resistors are on digit pins
byte hardwareConfig = COMMON_ANODE; // See README.md for options
bool updateWithDelays = false; // Default 'false' is Recommended
bool leadingZeros = false; // Use 'true' to keep leading zeros for 3-digit frequencies
bool disableDecPoint = false; // Use 'true' if your decimal point doesn't exist or isn't connected
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments,
updateWithDelays, leadingZeros, disableDecPoint);
sevseg.setBrightness(90);
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT); // Set buzzer pin as an output
}
void loop() {
int potValue = analogRead(potPin);
float frequency = map(potValue, 0, 1023, 875, 1080);
// FM Display
sevseg.setNumber(frequency, 1);
// FM frequencies LED
if (frequency == 889 || frequency == 909 || frequency == 925 ||
frequency == 969 || frequency == 1025 || frequency == 1079) {
digitalWrite(ledPin, HIGH);
// Buzz the piezo buzzer
buzzBuzzer();
} else {
digitalWrite(ledPin, LOW);
// Turn off the piezo buzzer
noTone(buzzerPin);
}
if (frequency == 889) {
Serial.println("KXPR - CSU-Sacramento");
}
if (frequency == 909) {
Serial.println("KXJZ - CSU-Sacramento");
}
if (frequency == 925) {
Serial.println("KBEB - Country");
}
if (frequency == 969) {
Serial.println("KSEG - Classic Rock");
}
if (frequency == 1025) {
Serial.println("KSFM - Hip Hop");
}
if (frequency == 1079) {
Serial.println("KDND - Top 40");
}
sevseg.refreshDisplay();
}
void buzzBuzzer() {
// Play a tone on the piezo buzzer
tone(buzzerPin, 1000, 100); // You can adjust the frequency (1000) and duration (100) as needed
}