#include #include #include LiquidCrystal_I2C lcd (0x27,16,2); // I2C address should be correct!! // Radio stations at my home int fm_stations[23] = { 89.1, // KBS 2 89.7, // WBS 91.9, // MBC FM4U 93.1, // KBS 1 FM 93.9, // CBS FM 94.5, // YTN FM 95.1, // TBS 95.9, // MBC 96.7, // Military 97.3, // KBS 1 98.1, // CBS FM 99.1, // Korean folk 101.3, // TBS eFM 101.9, // BBS 102.7, // AFN Eagle FM 103.5, // SBS Lover FM 104.5, // EBS 104.9, // KBS 3 105.3, // CPBC 106.1, // KBS 2 106.9, // febc 107.7 // SBS Power FM }; int analogPin = A3; int reading; int current; TEA5767Radio radio = TEA5767Radio(); void setup() { Wire.begin(); // set up the LCD's number of columns and rows: lcd.begin(16, 2); lcd.setBacklight(HIGH); // Print a message to the LCD. lcd.print("DIY Radio V1.0"); // Serial.begin(9600); current = analogRead(analogPin); Serial.begin(9600); Serial.print("current: "); Serial.println(current); } void loop() { reading = analogRead(analogPin); Serial.print("reading: "); Serial.println(reading); if (reading != current) { Frequency_set(); } delay(100); } void Frequency_set() { // Serial.println(reading); if (reading >= 0 && reading <= 44) { // KBS 2 radio.setFrequency(89.1); lcd.setCursor(0, 1); // print the radio station info to LCD lcd.print(" "); lcd.setCursor(0, 1); lcd.print("KBS 2, 89.1Mhz"); } else if (reading >= 45 && reading <= 89) { // WBS radio.setFrequency(89.7); lcd.setCursor(0, 1); // print the radio station info to LCD lcd.print(" "); lcd.setCursor(0, 1); lcd.print("WBS, 89.7Mhz"); } else if (reading >= 90 && reading <= 133) { // MBC FM4U radio.setFrequency(91.9); lcd.setCursor(0, 1); // print the radio station info to LCD lcd.print(" "); lcd.setCursor(0, 1); lcd.print("MBC FM4U, 91.9Mhz"); } else if (reading >= 134 && reading <= 178) { // KBS 1 FM radio.setFrequency(93.1); lcd.setCursor(0, 1); // print the radio station info to LCD lcd.print(" "); lcd.setCursor(0, 1); lcd.print("KBS 1 FM, 93.1Mhz"); } else if (reading >= 179 && reading <= 222) { // CBS FM radio.setFrequency(93.9); lcd.setCursor(0, 1); // print the radio station info to LCD lcd.print(" "); lcd.setCursor(0, 1); lcd.print("CBS FM, 93.9Mhz"); } else if (reading >= 223 && reading <= 267) { // YTN FM radio.setFrequency(94.5); lcd.setCursor(0, 1); // print the radio station info to LCD lcd.print(" "); lcd.setCursor(0, 1); lcd.print("YTN FM, 94.5Mhz"); } else if (reading >= 268 && reading <= 311) { // TBS radio.setFrequency(95.1); lcd.setCursor(0, 1); // print the radio station info to LCD lcd.print(" "); lcd.setCursor(0, 1); lcd.print("TBS, 95.1Mhz"); } else if (reading >= 312 && reading <= 356) { // MBC radio.setFrequency(95.9); // pick your own frequency lcd.setCursor(0, 1); // print the radio station info to LCD lcd.print(" "); lcd.setCursor(0, 1); lcd.print("MBC, 95.9Mhz"); } else if (reading >= 357 && reading <= 400) { // Military -> changed kung-in bangsong radio.setFrequency(90.7); // pick your own frequency lcd.setCursor(0, 1); // print the radio station info to LCD lcd.print(" "); lcd.setCursor(0, 1); lcd.print("Military, 90.7Mhz"); } else if (reading >= 401 && reading <= 445) { // KBS 1 radio.setFrequency(97.3); lcd.setCursor(0, 1); // print the radio station info to LCD lcd.print(" "); lcd.setCursor(0, 1); lcd.print("KBS 1, 97.3Mhz"); } else if (reading >= 446 && reading <= 489) { // CBS FM radio.setFrequency(98.1); // lcd.setCursor(0, 1); // print the radio station info to LCD lcd.print(" "); lcd.setCursor(0, 1); lcd.print("CBS FM, 98.1Mhz"); } else if (reading >= 490 && reading <= 534) { // Korean folk music -> Kunggi-Radio radio.setFrequency(99.9); // pick your own frequency lcd.setCursor(0, 1); // print the radio station info to LCD lcd.print(" "); lcd.setCursor(0, 1); lcd.print("Korean folk, 99.9Mhz"); } else if (reading >= 535 && reading <= 578) { // TBS eFM -> Military radio.setFrequency(96.9); lcd.setCursor(0, 1); // print the radio station info to LCD lcd.print(" "); lcd.setCursor(0, 1); lcd.print("TBS eFM, 96.9Mhz"); } else if (reading >= 579 && reading <= 623) { // BBS radio.setFrequency(101.9); lcd.setCursor(0, 1); // print the radio station info to LCD lcd.print(" "); lcd.setCursor(0, 1); lcd.print("BBS, 101.9Mhz"); } else if (reading >= 624 && reading <= 667) { // AFN Eagle FM radio.setFrequency(102.7); // pick your own frequency lcd.setCursor(0, 1); // print the radio station info to LCD lcd.print(" "); lcd.setCursor(0, 1); lcd.print("AFN Eagle, 102.7Mhz"); } else if (reading >= 668 && reading <= 712) { // SBS Lover FM radio.setFrequency(103.5); lcd.setCursor(0, 1); // print the radio station info to LCD lcd.print(" "); lcd.setCursor(0, 1); lcd.print("SBS Love FM, 103.5Mhz"); } else if (reading >= 713 && reading <= 756) { // EBS radio.setFrequency(104.5); lcd.setCursor(0, 1); // print the radio station info to LCD lcd.print(" "); lcd.setCursor(0, 1); lcd.print("EBS, 104.5Mhz"); } else if (reading >= 757 && reading <= 801) { // KBS 3 -> Incheon bangsong radio.setFrequency(100.5); lcd.setCursor(0, 1); // print the radio station info to LCD lcd.print(" "); lcd.setCursor(0, 1); lcd.print("KBS 3, 100.5"); } else if (reading >= 802 && reading <= 845) { // CPBC radio.setFrequency(105.3); lcd.setCursor(0, 1); // print the radio station info to LCD lcd.print(" "); lcd.setCursor(0, 1); lcd.print("CPBC, 105.3Mhz"); } else if (reading >= 846 && reading <= 890) { // KBS 2 radio.setFrequency(106.1); lcd.setCursor(0, 1); // print the radio station info to LCD lcd.print(" "); lcd.setCursor(0, 1); lcd.print("KBS 2, 106.1Mhz"); } else if (reading >= 891 && reading <= 934) { // febc radio.setFrequency(102.7); // pick your own frequency lcd.setCursor(0, 1); // print the radio station info to LCD lcd.print(" "); lcd.setCursor(0, 1); lcd.print("FEBC, 102.7Mhz"); } else { // SBS Power FM radio.setFrequency(107.7); // pick your own frequency lcd.setCursor(0, 1); // print the radio station info to LCD lcd.print(" "); lcd.setCursor(0, 1); lcd.print("SBS Power FM, 107.7Mhz"); } current = reading; }