voilà le code (le pull-up est bien activé)
je ne comprends pas la série de 1 avec les broches 2 et 7 reliées.
je devrais avoir 01000000000000000000000000000000 au lieu de 01000000111111111111111111111111
sortie :
configuration Serie : 6
configuration Serie : 7
configuration Serie : 8
configuration Serie : 9
configuration Serie : 10
configuration Serie : 11
configuration Serie : 12
configuration Serie : 13
configuration Entree : 2
configuration Entree : 3
configuration Entree : 4
configuration Entree : 5
nbr entrees : 4
nbr series : 8
debut series : 6
Nombre touches : 32
01000000111111111111111111111111
nbr entrees : 4
nbr series : 8
debut series : 6
Nombre touches : 32
01000000111111111111111111111111
nbr entrees : 4
nbr series : 8
debut series : 6
Nombre touches : 32
01000000111111111111111111111111
#include <string.h>
#include <stdlib.h> //atoi()
//Constantes
#define NBR_ENTREE 4
#define DEBUT_ENTREE 2
#define FIN_ENTREE (DEBUT_ENTREE + NBR_ENTREE) -1
#define NBR_SERIES 8
#define DEBUT_SERIES FIN_ENTREE + 1
#define FIN_SERIES (DEBUT_SERIES + NBR_SERIES) -1
#define NBR_TOUCHES NBR_ENTREE*NBR_SERIES
void setup() {
int i = 0;
Serial.begin(115200);
// init sorties (séries)
for (i=DEBUT_SERIES; i<=FIN_SERIES; i++)
{
Serial.print("configuration Serie : ");
Serial.println(i, DEC);
pinMode(i, OUTPUT);
//digitalWrite(i, LOW);
}
// init entrées
for (i=DEBUT_ENTREE; i<=FIN_ENTREE; i++)
{
Serial.print("configuration Entree : ");
Serial.println(i, DEC);
pinMode(i,INPUT);
digitalWrite(i, HIGH); //active la résistance interne de pull-up (évite la résistance suplémentaire)
}
delay(500);
}
void loop(){
int nEtat[NBR_TOUCHES] = {0};
int oEtat[NBR_TOUCHES] = {0};
Serial.print("\nnbr entrees : ");
Serial.print(NBR_ENTREE, DEC);
Serial.print("\nnbr series : ");
Serial.print(NBR_SERIES, DEC);
Serial.print("\ndebut series : ");
Serial.print(DEBUT_SERIES , DEC);
Serial.print("\nNombre touches : ");
Serial.println(NBR_TOUCHES , DEC);
lireEtat(nEtat, DEBUT_ENTREE , FIN_ENTREE , DEBUT_SERIES , FIN_SERIES);
afficherEtat(nEtat, NBR_TOUCHES);
delay(1000);
}
void lireEtat( int *etat, int eD, int eF, int sD, int sF )
{
int s = 0;
int e = 0;
int res = 0;
int i = 0; //compte bits
for (e=eD; e<=eF; e++)
{
for(s=sD; s<=sF; s++)
{
digitalWrite(s, HIGH);
res = digitalRead(e);
digitalWrite(s, LOW);
etat[i] = res;
i++;
}
}
delay(100);
}
void afficherEtat( int *etat, int nbrMax)
{
for (int i = 0; i <nbrMax; i++)
{
Serial.print(etat[i], DEC);
//delay(200);
}
Serial.println("");
}