/** @file fmrx_demo.ino @author www.elechouse.com @brief example of FMRX_MODULE For this demo, input character '1' from serial monitor to seek channel down, '2' to seek down '3' to volume up, '4' to volume down.'&xxxx' (x is for a number) to manually set receive FM frequency @section HISTORY V1.0 initial version Copyright (c) 2012 www.elechouse.com All right reserved. */ /** include library */ #include float channel; void setup(void) { Serial.begin(9600); Serial.print("FM-RX Demo By Elechosue\r\n"); /** I2C initial */ i2c_init(); fmrx_power(); fmrx_read_reg(fmrx_reg_r); Serial.print("FMRX Module Power up.\r\n"); /** set volume */ fmrx_set_volume(10); Serial.println("Volume Set"); /** receive signal strength set, range:0-127*/ fmrx_set_rssi(15); /** select a band, parameter: BAND_EU: 87-108MHz, Europe BAND_US: 87-108MHz, USA BAND_JP: 76-91MHz, JAPAN BAND_JP_WIDE: 76-108MHz, JAPAN wide */ fmrx_select_band(BAND_US); channel=fmrx_seek(SEEK_DOWN); Serial.println("Initial seek."); Serial.print("Channel:"); Serial.print(channel, 2); Serial.println("MHz"); } void loop(void) { static u8 vol=10; if(Serial.available()>0){ switch(Serial.read()){ case '1': Serial.println("Wait..."); channel = fmrx_seek(SEEK_DOWN); Serial.println("Seek down."); Serial.print("Channel:"); Serial.print(channel, 2); Serial.println("MHz"); break; case '2': Serial.println("Wait..."); channel = fmrx_seek(SEEK_UP); Serial.println("Seek up."); Serial.print("Channel:"); Serial.print(channel, 2); Serial.println("MHz"); break; case '3': Serial.println("Wait..."); if(vol < 0x0F){ vol++; } fmrx_set_volume(vol); Serial.print("Volume+:"); Serial.println(vol); break; case '4': Serial.println("Wait..."); if(vol > 0){ vol--; } fmrx_set_volume(vol); Serial.print("Volume-:"); Serial.println(vol); break; /** check data for setting new channel. Input data must start with '&' and followed by 4 numbers, the first 3 is the integer part (Unit: MHz), the last one is the decimal part.And the channel must between 76MHz and 108Mhz.(eg: &0756 for 75.6MHz, and &0666 is out of range) */ case '&': u8 i,buf[4]; float ch; i=0; delay(30); while(Serial.available()&&i<4){ buf[i]=Serial.read(); if (buf[i]<= '9' && buf[i]>= '0') { i++;} else{ i=0; break; } } if (i==4){ ch = (buf[0]-'0')*100+(buf[1]-'0')*10+(buf[2]-'0')*1+0.1*(buf[3]-'0'); Serial.println(fmrx_set_freq(ch),2); }else{ Serial.println("Input Error."); } /** dummy read for useless character */ while(Serial.available()){ Serial.read(); } break; } } }