Analizzando la parte dove vengono analizzati i pin di arduino collegati ai pulsanti:
// DEFINE ARDUINO PINS FOR THE NAVIGATION BUTTONS
#define UP_BUTTON_PIN 9
#define DOWN_BUTTON_PIN 10
#define LEFT_BUTTON_PIN 7
#define RIGHT_BUTTON_PIN 8
#define CONFIRM_BUTTON_PIN 12
#define ESCAPE_BUTTON_PIN 11
è possibile battezzare invece dei pin 9, 10, 7, 8, 12, 11, degli ingressi di un PCF8574 tipo P0, P1, P2 ....?
Ad esempio, in questo codice:
//The full code is in library example file Quick_tour.ino
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <buttons.h>
#include <MENWIZ.h>
#include <EEPROM.h>
#include <IOexp.h>
#define IO_ADDR (0x21) //Definisco l'indirizzo del pcf8574 dei bottoni
IOexp myIOexpander(IO_ADDR);
// DEFINE ARDUINO PINS FOR THE NAVIGATION BUTTONS
#define UP_BOTTON_PIN 9
#define DOWN_BOTTON_PIN 10
#define LEFT_BOTTON_PIN 7
#define RIGHT_BOTTON_PIN 8
#define CONFIRM_BOTTON_PIN 12
#define ESCAPE_BOTTON_PIN 11
menwiz tree;
// create lcd obj using LiquidCrystal lib
LiquidCrystal_I2C lcd(0x20);
int list,sp=110;
void setup(){
_menu *r,*s1,*s2;
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(19200);
tree.begin(&lcd,20,4); //declare lcd object and screen size to menwiz lib
r=tree.addMenu(MW_ROOT,NULL,F("Root"));
s1=tree.addMenu(MW_SUBMENU,r, F("Node1"));
s2=tree.addMenu(MW_VAR,s1, F("Node3"));
s2->addVar(MW_LIST,&list);
s2->addItem(MW_LIST, F("Option1"));
s2->addItem(MW_LIST, F("Option2"));
s2->addItem(MW_LIST, F("Option3"));
s2=tree.addMenu(MW_VAR,s1, F("Node4"));
s2->addVar(MW_AUTO_INT,&sp,0,120,10);
s1=tree.addMenu(MW_VAR,r, F("Node2"));
s1->addVar(MW_ACTION,myfunc);
tree.navButtons(UP_BOTTON_PIN,DOWN_BOTTON_PIN,LEFT_BOTTON_PIN,RIGHT_BOTTON_PIN,ESCAPE_BOTTON_PIN,CONFIRM_BOTTON_PIN);
}
void loop(){
tree.draw();
int data;
bool bool1, bool2, bool3, bool4, bool5, bool6; // the bool vars bool1 and bool2 are to store the status of the Inputs we wish to read.
Serial.print("teste ! ");
bool1 = myIOexpander.read(P0);
bool2 = myIOexpander.read(P1);
bool3 = myIOexpander.read(P2);
bool4 = myIOexpander.read(P3);
bool5 = myIOexpander.read(P4);
bool6 = myIOexpander.read(P5);
Serial.print(bool1);
Serial.print(" ");
Serial.print(bool2);
Serial.print(" ");
Serial.print(bool3);
Serial.print(" ");
Serial.print(bool4);
Serial.print(" ");
Serial.print(bool5);
Serial.print(" ");
Serial.print(bool6);
Serial.print(" \n ");
delay(500);
}
void myfunc(){
Serial.println("ACTION FIRED");
}
ho unito l'esempio della libreria MENWIZ con l'esempio della libreria IOexp e quello che ottengo è di vedere il menu sul display collegato al primo PCF8574, e di poter cambiare lo stato degli ingressi (da alto a basso) di un secondo PCF8574 e visualizzarli sul monitor seriale.
Considerando il secondo codice che ho postato, vorrei capire se si può fare una cosa di questo tipo con la giusta sintassi:
#define UP_BOTTON_PIN myIOexpander.read(P0)
#define DOWN_BOTTON_PIN myIOexpander.read(P1)
#define LEFT_BOTTON_PIN myIOexpander.read(P2)
#define RIGHT_BOTTON_PIN myIOexpander.read(P3)
#define CONFIRM_BOTTON_PIN myIOexpander.read(P4)
#define ESCAPE_BOTTON_PIN myIOexpander.read(P5)