Radioのほうが機能も、サポートするチップも多くお勧めです。
○ライブラリのインストール
Radioライブラリをダウンロードしてインストールします。
○回路・配線図
PCからのUSB給電の場合、電源にノイズが乗りFMの受信に影響します。このため、RRD-102 v2.0の3.3Vは別電源から供給するのが望ましいです。
・FMラジオ
※I2Cのロジックレベル変換の部品は適当なモノで書いています。実際には、次の部品を使用しました。
・キーパッド
○プログラム
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include <Wire.h> | |
#include <radio.h> | |
#include <RDA5807M.h> | |
// ----- Fixed settings here. ----- | |
#define FIX_BAND RADIO_BAND_FMWORLD ///< The band that will be tuned by this sketch is FM. | |
#define FIX_STATION 8180 ///< The station that will be tuned by this sketch is 89.30 MHz. | |
#define FIX_VOLUME 4 ///< The volume that will be set by this sketch is level 4. | |
RDA5807M radio; // Create an instance of Class for RDA5807M Chip | |
int adc_key_val[5] ={100, 350, 500, 610, 900 }; | |
int NUM_KEYS = 5; | |
int adc_key_in; | |
int key=-1; | |
int oldkey=-1; | |
/// Setup a FM only radio configuration | |
/// with some debugging on the Serial port | |
void setup() { | |
// open the Serial port | |
Serial.begin(57600); | |
Serial.println("Radio..."); | |
delay(200); | |
// Initialize the Radio | |
radio.init(); | |
// Enable information to the Serial port | |
radio.debugEnable(); | |
// Set all radio setting to the fixed values. | |
radio.setBandFrequency(FIX_BAND, FIX_STATION); | |
radio.setVolume(FIX_VOLUME); | |
radio.setMono(false); | |
radio.setMute(false); | |
} // setup | |
/// show the current chip data every 3 seconds. | |
void loop() { | |
char s[12]; | |
radio.formatFrequency(s, sizeof(s)); | |
Serial.print("Station:"); | |
Serial.println(s); | |
/* | |
Serial.print("Radio:"); | |
radio.debugRadioInfo(); | |
Serial.print("Audio:"); | |
radio.debugAudioInfo(); | |
*/ | |
adc_key_in = analogRead(0); // read the value from the sensor | |
digitalWrite(13,LOW); | |
key = get_key(adc_key_in); // convert into key press | |
//Serial.println(adc_key_in); | |
if (key != oldkey) // if keypress is detected | |
{ | |
delay(50); // wait for debounce time | |
adc_key_in = analogRead(0); // read the value from the sensor | |
key = get_key(adc_key_in); // convert into key press | |
if (key != oldkey) { | |
oldkey = key; | |
if (key >=0) { | |
digitalWrite(13,HIGH); | |
int v; | |
switch(key) | |
{ | |
case 0:Serial.println("S1 OK"); | |
Serial.println("seek down"); | |
radio.seekDown(true); | |
break; | |
case 1:Serial.println("S2 OK"); | |
Serial.println("seek up"); | |
radio.seekUp(true); | |
break; | |
case 2:Serial.println("S3 OK"); | |
// decrease volume | |
Serial.println("decrease volume"); | |
v = radio.getVolume(); | |
if (v > 0) radio.setVolume(--v); | |
break; | |
case 3:Serial.println("S4 OK"); | |
// increase volume | |
Serial.println("increase volume"); | |
v = radio.getVolume(); | |
if (v < 15) radio.setVolume(++v); | |
break; | |
case 4:Serial.println("S5 OK"); | |
radio.setFrequency(FIX_STATION); | |
break; | |
} | |
} | |
} | |
} | |
delay(100); | |
} // loop | |
// Convert ADC value to key number | |
int get_key(unsigned int input) { | |
int k; | |
for (k = 0; k < NUM_KEYS; k++) { | |
if (input < adc_key_val[k]) { | |
return k; | |
} | |
} | |
if (k >= NUM_KEYS)k = -1; // No valid key pressed | |
return k; | |
} |
0 件のコメント:
コメントを投稿