Phi_Interfaces question.

Hi,

Just having a bit of trouble with the Luidr Interface - I have 3 analog buttons, which detect fine in Phi_Prompt but if I try and see if a button is pressed outside of the menu, I cannot seem to detect it properly.

It will give the right response to the serial port (Button 1, 2, 3) but if I try and detect it by the value, it will accept any button press rather than just the one I want - button 2.

Code follows:

...

#define buttons_per_column 3 // Three buttons in the column
#define buttons_per_row 1 // One row of buttons

...

#include <LiquidCrystal.h>
#include <phi_interfaces.h>
#include <phi_prompt.h>

byte keypad_type=Analog_keypad;
char mapping[]={'1','2','3'}; // This is an analog keypad.
byte pins[]={0}; // The pin numbers are analog pin numbers.

int values[]={0, 109, 333}; //These numbers need to increase monotonically.
phi_analog_keypads panel_keypad(mapping, pins, values, buttons_per_row, buttons_per_column);
multiple_button_input* pad1=&panel_keypad;

...

phi_serial_keypads debug_keypad(&Serial,9600);
multiple_button_input * keypads[]={&panel_keypad,&debug_keypad,0};
char up_keys[]={
  "1"}; ///< All keys that act as the up key are listed here.
char down_keys[]={
  "3"}; ///< All keys that act as the down key are listed here.
char left_keys[]={
}; ///< All keys that act as the left key are listed here.
char right_keys[]={
}; ///< All keys that act as the right key are listed here.
char enter_keys[]={
  "2"}; ///< All keys that act as the enter key are listed here.
char escape_keys[]={
}; ///< All keys that act as the escape key are listed here.
char * function_keys[]={
  up_keys,down_keys,left_keys,right_keys,enter_keys,escape_keys}; ///< All function key names are gathered here fhr phi_prompt.

...

void loop()
{
  lcd.clear();
  
  byte temp=pad1->getKey();
   if (temp!=NO_KEY) {
   Serial.write(temp);
   if (temp=2) {
     Serial.write("Menu 2");
   }
   }

I have left out sections of code that run other little things, and can post the full code for the menu I have written - I have left them out as I don’t think they are applicable for this issue.

I cannot get the interface to detect button 2 being pressed - every button press will give “Menu 2” written to the serial port and it is really frustrating that I cannot work this out.

Any help on this would be great.

Regards,
Des.

byte pins[]={0}; // The pin numbers are analog pin numbers.

An array of length one is not all that useful.

   if (temp=2) {

Assigning a value to a variable, as you are doing here, always results in a value equal to that assigned. This statement might as well read "if(2) {", which is always true.

An array of length one is not all that useful.

I agree - but this is how the Phi_Prompt/Interfaces works in the documentation.

Assigning a value to a variable, as you are doing here, always results in a value equal to that assigned. This statement might as well read "if(2) {", which is always true.

I can't believe I missed that!

if (temp==2) {

That should do the trick - Will try that later when I get a chance.

Thanks for pointing out the obvious - I have been looking at this code and completely forgot it's TWO '=' to compare, one to assign!