go away spammer

Author Topic: 16-button keypad code question [RESOLVED]  (Read 1834 times)

0 Members and 1 Guest are viewing this topic.

Offline tzankoffTopic starter

  • Robot Overlord
  • ****
  • Posts: 122
  • Helpful? 0
16-button keypad code question [RESOLVED]
« on: September 02, 2014, 01:29:54 PM »
Hey guys! Long time no post.

I am rebuilding my robot skeleton and am rewriting the code from scratch and I have run  into a problem that has left me scratching my head. I am trying to install a 16-button keypad and despite using the keypad code from my previous robot build, it does not seem to work this time around and I am not sure why.

I am using the same keypad and wiring harness from the previous build.
I have confirmed that the keypad does work.
I have confirmed that the wiring to the Axon II is correct.
All variables are properly defined.
Compiling the code produces no errors.

In Project Designer,  I have the row pins (L0, L1, L2, and L3) set as digital outputs initially set to high. I have the column pins (L4, L5, L6, and L7) set as digital inputs with the internal pullup resistors enabled.

This leads me to believe that I have a code problem. However, when I compare it to the guideline that Webbot provided in a previous thread, I cannot find any difference. Everything else that I have plugged into the  Axon II (continuous servo, RGB LED, and a push button) works just fine. Does anyone have any idea what the problem is?

EDIT: Problems solved. See code and explanation below.
« Last Edit: September 13, 2014, 08:35:56 PM by tzankoff »

Offline tzankoffTopic starter

  • Robot Overlord
  • ****
  • Posts: 122
  • Helpful? 0
Re: 16-button keypad code question [RESOLVED]
« Reply #1 on: September 04, 2014, 05:36:57 AM »
Problem solved.
Apparently, "if (variable)..." and "if (variable==true)..." are not the same.
I guess I was not thinking along those lines as to that being the problem..
Anyway, here is my functioning code if anybody is interested. I am using this code as a means to control which track is played by an MP# Trigger.

Keypad:
1-2-3-A
4-5-6-B
7-8-9-C
*-0-#-D

Code: [Select]
keypadButton=false;
for (x=1; x<=4; x++){
switch(x){
case 1:
keypadR1.low();
break;
case 2:
keypadR2.low();
break;
case 3:
keypadR3.low();
break;
case 4:
keypadR4.low();
break;
}

keypadCheck[1]=keypadC1.isLow();
keypadCheck[2]=keypadC2.isLow();
keypadCheck[3]=keypadC3.isLow();
keypadCheck[4]=keypadC4.isLow();

for (y=1; y<=4; y++){
if (keypadCheck[y]){
keypadButton=((x-1)*4)+y;
temp=false;

switch(keypadButton){
case 1: // 1
temp='1';
break;
case 2: // 2
temp='2';
break;
case 3: // 3
temp='3';
break;
case 4: // A (speed dial)
keypadVal=11;
keypadStop=true;
break;
case 5: // 4
temp='4';
break;
case 6: // 5
temp='5';
break;
case 7: // 6
temp='6';
break;
case 8: // B (speed dial)
keypadVal=12;
keypadStop=true;
break;
case 9: // 7
temp='7';
break;
case 10: // 8
temp='8';
break;
case 11: // 9
temp='9';
break;
case 12: // C (speed dial)
keypadVal=13;
keypadStop=true;
break;
case 13: // * (clear existing input)
keypadVal=false;
break;
case 14: // 0
temp='0';
break;
case 15: // # (finish selecting track number)
keypadStop=true;
break;
case 16: // D (speed dial)
keypadVal=14;
keypadStop=true;
break;
}

if (temp){
keypadVal=keypadVal*10+(temp-'0');
}

if (keypadStop){
functionAudioPlayer(keypadVal);  // sends track info to MP3 Trigger
rprintf("VAL: %d\r\n",keypadVal);
keypadVal=false;
keypadStop=false;
}

rprintf("keypadButton: %d --> keypadVal: %d\r\n",keypadButton, keypadVal);
delay_ms(250);
break;
}
}

keypadR1.high();
keypadR2.high();
keypadR3.high();
keypadR4.high();
}

« Last Edit: September 13, 2014, 08:35:19 PM by tzankoff »

 


Get Your Ad Here

data_list