So I've gotten the multitude of wires finally wired up, from the radio to the analog switches, to the Arduino Mega. I mapped all of the pins to their various functions (I decided to forgo trying to remember which trigger pin triggered which of the 4 switches on which of the 4 IC's, so I just wired it up, and then made a simple Arduino sketch to test each digital pin and see what function it performed. The findings were as follows.
pinMode(16, OUTPUT); // Keypad 5
pinMode(17, OUTPUT); // Keypad 9
pinMode(18, OUTPUT); // Keypad 6
pinMode(19, OUTPUT); // Keypad 8
pinMode(20, OUTPUT); // Keypad 0
pinMode(21, OUTPUT); // Keypad 7
pinMode(22, OUTPUT); // Keypad 4
pinMode(23, OUTPUT); // UNUSED BROWN WIRE
pinMode(24, OUTPUT); // DOWN
pinMode(25, OUTPUT); // Keypad 3
pinMode(26, OUTPUT); // UP
pinMode(27, OUTPUT); // Keypad 2
pinMode(28, OUTPUT); // EXIT
pinMode(29, OUTPUT); // SCAN
pinMode(30, OUTPUT); // MENU
pinMode(31, OUTPUT); // Keypad 1
(Unused brown wire is a spare, and I'm trying to decide if I use it for A/B switch [which switches the radio between two settable frequencies] or the channel / frequency modes, or the FM mode, if I want to enable the FM tuner. A/B or FM makes most sense to me.)
Oddly enough, the rotary encode stopped working unless I commented out the pinMode declaration for the pin 16. I moved the encoder switch button from pin 6 to pin 12, and it works fine. So for some reason, pin 6 and pin 16 interfered somehow... But once the encoder was moved to pin 12, it all worked perfectly!
Scrolling through UHF Channels and the radio tuning to the correct frequency.
The scan function also works, tonight I'm going to build more functions to pack this out!
The tune functions look like this
void CALLBACK_FUNCTION UHFCH01(int id) {
Serial.println("Tune to UHF 1");
key_exit(); // press exit key
key_num(4); // press passed number key
key_num(7); // press passed number key
key_num(6); // press passed number key
key_num(4); // press passed number key
key_num(2); // press passed number key
key_num(5); // press passed number key
}
void CALLBACK_FUNCTION UHFCH02(int id) {
Serial.println("Tune to UHF 2");
key_exit(); // press exit key
key_num(4); // press passed number key
key_num(7); // press passed number key
key_num(6); // press passed number key
key_num(4); // press passed number key
key_num(5); // press passed number key
key_num(0); // press passed number key
}
And the key_num(x) function, and other key functions look like this
void key_num(int x) {
switch (x) {
case 0:
digitalWrite(20, HIGH); // press button
delay(delayTime); // pause
digitalWrite(20, LOW); // release button
delay(delayTime);
Serial.println("0");
break;
case 1:
digitalWrite(31, HIGH); // press button
delay(delayTime); // pause
digitalWrite(31, LOW); // release button
delay(delayTime);
Serial.println("1");
break;
case 2:
digitalWrite(27, HIGH); // press button
delay(delayTime); // pause
digitalWrite(27, LOW); // release button
delay(delayTime);
Serial.println("2");
break;
case 3:
digitalWrite(25, HIGH); // press button
delay(delayTime); // pause
digitalWrite(25, LOW); // release button
delay(delayTime);
Serial.println("3");
break;
case 4:
digitalWrite(22, HIGH); // press button
delay(delayTime); // pause
digitalWrite(22, LOW); // release button
delay(delayTime);
Serial.println("4");
break;
case 5:
digitalWrite(16, HIGH); // press button
delay(delayTime); // pause
digitalWrite(16, LOW); // release button
delay(delayTime); // pause
Serial.println("5");
break;
case 6:
digitalWrite(18, HIGH); // press button
delay(delayTime); // pause
digitalWrite(18, LOW); // release button
delay(delayTime); // pause
Serial.println("6");
break;
case 7:
digitalWrite(21, HIGH); // press button
delay(delayTime); // pause
digitalWrite(21, LOW); // release button
delay(delayTime); // pause
Serial.println("7");
break;
case 8:
digitalWrite(19, HIGH); // press button
delay(delayTime); // pause
digitalWrite(19, LOW); // release button
delay(delayTime); // pause
Serial.println("8");
break;
case 9:
digitalWrite(17, HIGH); // press button
delay(delayTime); // pause
digitalWrite(17, LOW); // release button
delay(delayTime); // pause
Serial.println("9");
break;
}
}
void key_menu(){
digitalWrite(30, HIGH); // press button
delay(delayTime); // pause
digitalWrite(30, LOW); // release button
delay(delayTime);
Serial.println("menu");
}
void key_up(){
digitalWrite(26, HIGH); // press button
delay(delayTime); // pause
digitalWrite(26, LOW); // release button
delay(delayTime);
Serial.println("up");
}
void key_down(){
digitalWrite(24, HIGH); // press button
delay(delayTime); // pause
digitalWrite(24, LOW); // release button
delay(delayTime);
Serial.println("down");
}
void key_exit(){
digitalWrite(28, HIGH); // press button
delay(delayTime); // pause
digitalWrite(28, LOW); // release button
delay(delayTime);
Serial.println("exit");
}
void key_scan(){
digitalWrite(29, HIGH); // press button
delay(2100); // pause
digitalWrite(29, LOW); // release button
delay(delayTime);
Serial.println("scan");
}
Could they be done more efficiently? Yep! Do I care? Nope! I have tons of ram on the Mega, and enough IO pins to do this the lazy way, so that's the way I'm doing it. There's a contest deadline, and I haven't even started on the housing yet...
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.