Buenas tardes, soy nuevo en programación y con Arduino.
Estoy intentando crear un proyecto con Mega 2560, usando varios expansores PCF8575, con sus interrupciones.
La interrupción de cada expansor, la conecto a los pines 2 y3 (posteriormente serán 4 expansores conectados a las interrupciones (pines: 2, 3, 19 y 18).
Al ejecutar el sketch, sea cual sea el conexionado de las interrupciones, solo funciona la primera, en el caso de este programa, solo funciona la del pin 2.
Necesito ayuda, me he estancado aquí y después de una semana haciendo cambios, no consigo avanzar.
Un saludo¡
/* Direccionamiento de los Expansores, HEXADECIMAL:
HEX-----DEC A2 A1 A0 Correcto en simulador PROTEUS
0X20 32 0 0 0 SI
OX21 33 0 0 1 SI
0X22 34 0 1 0 SI
0X23 35 0 1 1 SI
0X24 36 1 0 0 SI
0X25 37 1 0 1 SI
0X26 38 1 1 0 SI
0X27 39 1 1 1 SI
*/
#include <Wire.h>
#include "Arduino.h"
#include "PCF8575.h"
//Asignación de Interrupciones
//#define INTERRUPCION_EXPANSOR_PCF8575_EL1 2
const int INTERRUPCION_EXPANSOR_PCF8575_EL1 = 2;
//#define INTERRUPCION_EXPANSOR_PCF8575_EL2 3
const int INTERRUPCION_EXPANSOR_PCF8575_EL2 = 3;
// Asignación de direcciones I2C a cada expansor
PCF8575 PCF8575_EL1(0x20);
PCF8575 PCF8575_EL2(0x21);
//Declaración de los pines de Salidas Digitales
const int PinLed = 50;
//Declaramos la variable del PinLed como volatile bool
volatile bool LuzLed = HIGH;
// Bandera de tecla presionada en Expansor
volatile bool teclaPresionadaExpansorPCF8575_EL1 = false;
volatile bool teclaPresionadaExpansorPCF8575_EL2 = false;
//Funciones de las Interrupciones
void ISRExpansor_PCF8575_EL1() {
teclaPresionadaExpansorPCF8575_EL1 = true;
}
void ISRExpansor_PCF8575_EL2() {
teclaPresionadaExpansorPCF8575_EL2 = true;
}
//SETUP
void setup() {
//Serial.begin(115200);
Wire.begin(); //Probar a ver cual es la velocidad idónea
pinMode(INTERRUPCION_EXPANSOR_PCF8575_EL1, INPUT_PULLUP); // SEGURAMENTE HABRÁ QUE DESACTIVAR ESTA LÍNEA
attachInterrupt(digitalPinToInterrupt(INTERRUPCION_EXPANSOR_PCF8575_EL1), ISRExpansor_PCF8575_EL1, FALLING); // FALLING // RISING
pinMode(INTERRUPCION_EXPANSOR_PCF8575_EL2, INPUT_PULLUP); // SEGURAMENTE HABRÁ QUE DESACTIVAR ESTA LÍNEA
attachInterrupt(digitalPinToInterrupt(INTERRUPCION_EXPANSOR_PCF8575_EL2), ISRExpansor_PCF8575_EL2, FALLING);
//Entradas de cada uno de los expansores, en decimal a partir de 0
//ENTRADAS DEL EXPANSOR PCF8575_EL1
PCF8575_EL1.pinMode(4,INPUT); //Pulsador 4 DE EL1
//ENTRADAS DEL EXPANSOR PCF8575_EL2
PCF8575_EL2.pinMode(10,INPUT); //Pulsador 10 DE EL2
//Inicializamos los expansores de Entradas
PCF8575_EL1.begin();
PCF8575_EL2.begin();
}
//FUNCIONES PARA ENCENDER LAS LUCES , SALIDAS DIGITALES DEL ARDUINO MEGA 2560
void enciendeLuzLed(){
LuzLed = !LuzLed;
digitalWrite(PinLed,LuzLed);
}
//Entradas de cada uno de los expansores, en propiedades del IC
void loop() {
//EXPANSOR PCF8575_EL1
if (teclaPresionadaExpansorPCF8575_EL1) {
PCF8575::DigitalInput Pin_EL1 = PCF8575_EL1.digitalReadAll();
if (Pin_EL1.p4 == HIGH) {
enciendeLuzLed();
//Pulsador DE EL1
}
teclaPresionadaExpansorPCF8575_EL1 = false; // false
}
//EXPANSOR PCF8575_EL2
if (teclaPresionadaExpansorPCF8575_EL2) {
PCF8575::DigitalInput Pin_EL2 = PCF8575_EL2.digitalReadAll();
if (Pin_EL2.p12 == HIGH) {
enciendeLuzLed();
//Pulsador DE EL2
}
teclaPresionadaExpansorPCF8575_EL2 = false; // false
}
}
He trasladado su tema de una categoría de idioma inglés del foro a la categoría International > Español@tigre_1964.
En adelante por favor usar la categoría apropiada a la lengua en que queráis publicar. Esto es importante para el uso responsable del foro, y esta explicado aquí la guía "How to get the best out of this forum".
Este guía contiene mucha información útil. Por favor leer.
Buenas tardes.
Primero, les pido disculpas, no me dí cuenta que estaba en el foro en inglés, lo siento !!!
En cuanto al software facilitado, voy a estudiarlo a fondo, seguro que puedo adaptarlo a mis necesidades.
Muchas gracias por su inestimable ayuda !
Un saludo !!!
Buenas noches.
Creo que ya tengo la solución, voy a hacer unas pruebas reales, y si todo funcione correctamente, subiré el sotfware final.
Muchas gracias por vuestra ayuda.
Un cordial saludo de Miguel Llorca.