BANDデータの出力はアナログ電圧で最大値は8Vなのに対してArduinoのアナログ入力端子はMax 5Vなので分圧抵抗を介して最大値でも5V未満になるようにしてから入力する。
測定した電圧は機種によって差異がある。
次回アップグレードする際にはBANDデータと一緒に出力されている8V基準電圧の端子と比較演算させてみるが今回は判定電圧の設定範囲を広くして対応。
void setup() {
pinMode(2, OUTPUT); // 1.9MHz
pinMode(3, OUTPUT); // 3.5MHz
pinMode(4, OUTPUT); // 7MHz
pinMode(5, OUTPUT); // 10MHz
pinMode(6, OUTPUT); // 14MHz
pinMode(7, OUTPUT); // 18,21MHz
pinMode(8, OUTPUT); // 24,28MHz
pinMode(9, OUTPUT); // 50MHz
pinMode(10, OUTPUT); // DP
pinMode(11, OUTPUT); // 218H
pinMode(12, OUTPUT); // CL6A
pinMode(13, OUTPUT); // Tuner
int band ;
}
void loop() {
band = AnalogRead(0) ;
if (band >= 900) {
digitalWrite(2, HIGH); // 1.9MHz
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, HIGH); //tuner
}
if (band >= 700 && band <= 800) {
digitalWrite(3, HIGH); // 3.5MHz
digitalWrite(2, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH); // DP
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
}
if (band >= 600 && band <= 670) {
digitalWrite(4, HIGH); // 7MHz
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH); // DP
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
}
if (band <= 50) {
digitalWrite(5, HIGH); // 10MHz
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, HIGH); //tuner
}
if (band >= 470 && band <= 550) {
digitalWrite(6, HIGH); // 14MHz
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH); // DP
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
}
if (band >= 350 && band <= 430) {
digitalWrite(7, HIGH); // 18,21MHz
digitalWrite(2, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(3, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, HIGH); // 218H
digitalWrite(12, LOW);
digitalWrite(13, LOW);
}
if (band >= 246 && band <= 300) {
digitalWrite(8, HIGH); // 24,28MHz
digitalWrite(2, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(3, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, HIGH); // 218H
digitalWrite(12, LOW);
digitalWrite(13, LOW);
}
if (band >= 180 && band <= 245) {
digitalWrite(9, HIGH); // 50MHz
digitalWrite(2, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(3, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);// CL6A
digitalWrite(13, LOW);
}
}