○パーツリスト
1
|
|
1
|
|
1
|
|
1
|
|
1
|
|
1
|
|
3
|
|
1
|
|
1
|
|
2
|
|
1
|
|
1
|
|
20kΩ半固定抵抗、または20kΩ抵抗
|
1
|
電解コンデンサ4.7μF
|
2
|
ミンティアブリーズケース
|
1
|
その他、配線用ワイヤー、ホットボンドなど。
○回路図
○実装・配線
○ファームウェア(Arduinoプログラム)
・必要ライブラリ Adafruit_SSD1306、
This file contains 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> | |
#include <Adafruit_SSD1306.h> | |
#include <EEPROM.h> | |
#define OLED_RESET 4 | |
Adafruit_SSD1306 display(OLED_RESET); | |
#define DOWN_BTN 4 | |
#define CENTER_BTN 5 | |
#define UP_BTN 6 | |
#define LED 13 | |
#define STATION_ADDRESS 0 | |
// ----- 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 81.80 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 key=-1; | |
int oldkey=-1; | |
unsigned int count=20000; | |
int get_key() { | |
unsigned int pcount = 0; | |
bool wait = 0; | |
if(digitalRead(DOWN_BTN)==LOW) { | |
delay(50); | |
while(digitalRead(DOWN_BTN)==LOW){ | |
pcount++; | |
if(pcount > count){ | |
wait = 1; | |
digitalWrite(LED,HIGH); | |
} | |
} | |
if(wait == 1) { | |
return 0; | |
} else return 2; | |
} | |
if(digitalRead(CENTER_BTN)==LOW) { | |
delay(50); | |
while(digitalRead(CENTER_BTN)==LOW){ | |
pcount++; | |
if(pcount > count*5){ | |
wait = 1; | |
digitalWrite(LED,HIGH); | |
} | |
} | |
if(wait == 1) { | |
return 5; | |
} else return 4; | |
} | |
if(digitalRead(UP_BTN)==LOW) { | |
delay(50); | |
while(digitalRead(UP_BTN)==LOW){ | |
pcount++; | |
if(pcount > count){ | |
wait = 1; | |
digitalWrite(LED,HIGH); | |
} | |
} | |
if(wait == 1) { | |
return 1; | |
} else return 3; | |
} | |
return -1; | |
} | |
void setFrequency(){ | |
uint16_t currentFreq; | |
EEPROM.get(STATION_ADDRESS, currentFreq); | |
if(currentFreq > radio.getMinFrequency() && currentFreq < radio.getMaxFrequency()){ | |
radio.setFrequency(currentFreq); | |
} else { | |
radio.setFrequency(FIX_STATION); | |
} | |
} | |
/// Setup a FM only radio configuration | |
/// with some debugging on the Serial port | |
void setup() { | |
pinMode(4, INPUT_PULLUP); | |
pinMode(5, INPUT_PULLUP); | |
pinMode(6, INPUT_PULLUP); | |
pinMode(13, OUTPUT); | |
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!) | |
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64) | |
// init done | |
delay(2000); | |
// Clear the buffer. | |
display.clearDisplay(); | |
// 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.setBand(FIX_BAND); | |
setFrequency(); | |
//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)); | |
display.clearDisplay(); | |
display.setTextSize(2); | |
display.setTextColor(WHITE); | |
display.setCursor(0,0); | |
display.println(s); | |
display.setCursor(12,16); | |
display.print("Vol:"); | |
display.setCursor(64,16); | |
display.println(radio.getVolume()); | |
display.display(); | |
digitalWrite(LED,LOW); | |
int key = get_key(); | |
if (key != oldkey) { | |
oldkey = key; | |
if (key >=0) { | |
int v; | |
switch(key) | |
{ | |
case 0:radio.seekDown(true); | |
break; | |
case 1:radio.seekUp(true); | |
break; | |
case 2:v = radio.getVolume(); | |
if (v > 0) radio.setVolume(--v); | |
break; | |
case 3: v = radio.getVolume(); | |
if (v < 15) radio.setVolume(++v); | |
break; | |
case 4:setFrequency(); | |
break; | |
case 5:EEPROM.put(STATION_ADDRESS, radio.getFrequency()); | |
break; | |
} | |
} | |
} | |
delay(100); | |
} // loop |
・上ボタンでボリュームアップ、長押しでシークアップ
・下ボタンでボリュームダウン、長押しでシークダウン
・中央ボタンでメモリーした周波数(既定は81.8MHz)で選局、規定の周波数は、FIX_STATIONで設定
・中央ボタン長押しで現在の周波数をメモリー
0 件のコメント:
コメントを投稿