// FM Radio RDA5807 #include #include #include RDA5807 radio; LiquidCrystal_I2C lcd(0x27, 16, 2); // Piny const int btnUp = 11; const int btnDown = 9; const int btnSwitch = 10; const int potVolume = A0; float frequency = 90.1; // Start frequency bool showRDS = false; void setup() { Serial.begin(9600); delay(200); // Piny pinMode(btnUp, INPUT_PULLUP); pinMode(btnDown, INPUT_PULLUP); pinMode(btnSwitch, INPUT_PULLUP); // LCD lcd.begin(16, 2); lcd.backlight(); lcd.clear(); lcdPrintBoth(0, 0, "Start radia..."); // Radio radio.setup(); radio.setVolume(8); radio.setFrequency((uint16_t)(frequency * 100)); radio.setRdsFifo(true); radio.setRDS(true); // Włącz obsługę RDS delay(300); lcd.clear(); updateDisplay(); } void loop() { static unsigned long lastUpdate = 0; // przyciski if (digitalRead(btnUp) == LOW) { frequency += 0.1; if (frequency > 108.0) frequency = 108.0; radio.setFrequency((uint16_t)(frequency * 100)); updateDisplay(); delay(300); } if (digitalRead(btnDown) == LOW) { frequency -= 0.1; if (frequency < 87.5) frequency = 87.5; radio.setFrequency((uint16_t)(frequency * 100)); updateDisplay(); delay(300); } // Potencjometr - głośność int vol = map(analogRead(potVolume), 0, 1023, 0, 15); radio.setVolume(vol); // Przełącznik widoku if (digitalRead(btnSwitch) == LOW) { showRDS = !showRDS; updateDisplay(); delay(300); } // Aktualizacja RDS co 2 sekundy if (showRDS && millis() - lastUpdate > 2000) { lastUpdate = millis(); updateDisplay(); } } // Funkcja pomocnicza: wyświetla tekst na LCD i w Serialu void lcdPrintBoth(int col, int row, String text) { lcd.setCursor(col, row); lcd.print(text); Serial.print("LCD ["); Serial.print(row); Serial.print(":"); Serial.print(col); Serial.print("] "); Serial.println(text); } void updateDisplay() { lcd.clear(); Serial.println("--- LCD Update ---"); if (!showRDS) { // Wyświetlanie częstotliwości i głośności lcdPrintBoth(0, 0, "FM:" + String(frequency, 1)); lcdPrintBoth(0, 1, "Vol:" + String(map(analogRead(potVolume), 0, 1023, 0, 15))); } else { // Wyświetlanie danych RDS lcdPrintBoth(0, 0, "RDS:"); if (radio.getRdsReady()) { // Sprawdź czy są nowe dane RDS // getRdsAllData(char **stationName, char **stationInformation, char **programInformation, char **utcTime) char *utc, *sn, *si, *pi; radio.getRdsAllData(&sn, &si, &pi, &utc); if (pi && strlen(pi) > 0) { lcdPrintBoth(0, 1, String(pi)); } else { lcdPrintBoth(0, 1, "Brak danych"); } } else { lcdPrintBoth(0, 1, "Oczekuję..."); } } }