Problème clavier Arduino/latex

Bonjour,
Je suis en train de réaliser un clavier permettant de taper des elements Latex avec un Arduino Due et un clavier matriciel
Les touches ne tapent pas les suites de character mais seulement ù,9,5,7 ou Enter ou Suppr

Merci par avance pour votre aide

 #include <Keypad.h>
 #include <Keyboard.h>
const byte ROWS = 6; // nombre de lignes
const byte COLS = 18; // nombre de colonnes

const char* touches[ROWS][COLS] = {
  {"\\alpha", "\\beta", "\\gamma", "\\Gamma", "\\delta", "\\Delta", "\\epsilon", "\\nu", "\\mu", "\\theta", "\\Phi", "\\rho", "\\tau", "\\sigma", "\\pi", "\\omega", "\\Omega","\\eta"}, // 18
  {"\\times", "\\sum", "\\int", "\\iint", "\\iiint", "\\prodd", "\\otimes", "\\land", "\\frac{\\partial}{\partial t}", "\\frac{D}{Dt}", "\\vert", "\\sqrt{}", "+", "-", "\\div","\\pm", "\\mathcal{F}" }, // 18
  {"\\chapter{}", "\\section{}", "\\subsection{}", "\\subsection{}", "\\begin{align}", "\\end{align}", "\\begin{equation}", "\\end{equation}", "\\begin{itemize}", "\\end{itemize}", "\\begin{enumerate}", "\\end{enumerate}", "\\begin{cases}", "\\end{cases}"}, // 13
  {"\\dot{}", "\\ddot{}", "\\dddot{}", "\\overline{\\overline{}}", "\\overrightarrow{}", "_", "^", "{", "}", "\\left(", "\\right)", "\\left[", "\\right]", "\\mathbb{R}^1, \\mathbb{R}^2, \\mathbb{R}^3", "\\hat{}", "\\"}, // 18
  {"\\infty", "\\leq", "<", "\\geq", ">", "\\neq", "\\in", "\\notin", "\\exists", "\\nexists", "\\cup", "\\cap", "\\perp", "\\parallel", "\\forall","\\sum"}, // 16
  { "=", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9","\\","\[","\]"} // 14
};


byte lignesPins[ROWS] = {A1,A2,A4,A5,A7,A8};
byte colonnesPins[COLS] ={A0,20,23,25,27,29,33,35,37,39,41,45,47,49,32,36,38,40};

Keypad clavier = Keypad(makeKeymap((char*)touches), lignesPins, colonnesPins, ROWS, COLS); 

void setup() {
  Serial.begin(9600);
}
void loop() {
  char touche = clavier.getKey();

  if (touche) {
    Serial.print("Touche pressee : ");
    Serial.println(touche);
  }

  if (Serial.available() > 0) {
    char key = Serial.read();
    Keyboard.write(key);
  }
}

La bibliothèque keyboard ne gère qu’un seul octet par touche - à vous de faire le mapping vers la séquence de caractères à envoyer

Comme cela?

#include <Keyboard.h>

const byte L1 = 13;
const byte L2 = 12;
const byte L3 = 11;
const byte L4 = 8;
const byte L5 = 7;
const byte L6 = 6;

// Colonnes
const byte C1 = 34;
const byte C2 = 41;
const byte C3 = 16;
const byte C4 = 39;
const byte C5 = 45;
const byte C6 = 42;
const byte C7 = 49;
const byte C8 = 39;
const byte C9 = 29;
const byte C10 = 27;
const byte C11 = 40;
const byte C12 = 20;
const byte C13 = 43;
const byte C14 = 46;
const byte C15 = 26;
const byte C16 = 33;
const byte C17 = 25;

void setup() {
   Serial.begin(9600);
}

void loop() {
  if (digitalRead(L1) == HIGH && digitalRead(C1) == HIGH) {
    Keyboard.print("\");
    Keyboard.print("a");
    Keyboard.print("l");
    Keyboard.print("p");
    Keyboard.print("h");
    Keyboard.print("a");
  }

Vous pouvez utiliser la bibliothèque keyboard pour gérer votre matrice de boutons et faire un switch sur le code reçu pour envoyer les bonne touches

Bonjour,

Je suis désolée mais je ne vois pas comment faire pour gérer la matrice de boutons autrement que comme je l'ai fait ci-dessus. Je suppose que la réponse doit être une évidence mais je débute tout juste donc je ne voie pas.

Merci par avance

Utilisez la bibliothèque Keypad mais les touches ne peuvent être identifiées que par UN SEUL caractère.

Donc ça n’est pas possible

Il faut un truc comme cela (ici en 4x3)

char touches[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};

Prenez un des codes d’exemple qui imprime la lettre ou chiffre de la matrice

Ensuite votre code doit dire

Si touche == '1' alors envoyer X Y Z
Sinon
Si touche == '2' alors envoyer A B C D E F
Sinon
Si touche == '3' alors envoyer N B V C

(Ou mieux avec un switch/case à la place des if/else)

Bonjour,
Après de nombreux tests, je n'arrive pas à coder votre solution pour les 108 touche donc je suis parti sur l'utilisation des coordonnés. Le problème est que si je teste l'état haut toutes les touches se déclenche en même temps (donc le code fonction) mais dès lors que je teste l'état bas plus aucune touche fonctionnent à la frappe.

#include <Arduino.h>
#include <Keyboard.h>

const int ROWS = 6;
const int COLS = 18;

byte lignesPins[ROWS] = {13, 12, 11, 8, 7, 6};
byte colonnesPins[COLS] = {34, 41, 16, 39, 45, 42, 49, 39, 29, 27, 40, 20, 43, 46, 26, 33, 25, 28};

void setup()
{
  Keyboard.begin();
  for (int i = 0; i < ROWS; i++) {
    pinMode(lignesPins[i], OUTPUT);
    digitalWrite(lignesPins[i], HIGH);
  }
  for (int i = 0; i < COLS; i++) {
    pinMode(colonnesPins[i], INPUT_PULLUP);
  }
}

void loop()
{
  for (int L = 0; L < ROWS; L++) {
    digitalWrite(lignesPins[L], LOW);
    for (int C = 0; C < COLS; C++) {
      if (digitalRead(colonnesPins[C]) == LOW) {
        // Envoyer le code LaTeX correspondant à la touche enfoncée
        if (L == 0 && C == 0) { Keyboard.println("\\alpha"); }
        else if (L == 0 && C == 1) { Keyboard.println("\\beta"); }
        else if (L == 0 && C == 2) { Keyboard.println("\\gamma"); }
        else if (L == 0 && C == 3) { Keyboard.println("\\Gamma"); }
        else if (L == 0 && C == 4) { Keyboard.println("\\delta"); }
        else if (L == 0 && C == 5) { Keyboard.println("\\Delta"); }
        else if (L == 0 && C == 6) { Keyboard.println("\\epsilon"); }
        else if (L == 0 && C == 7) { Keyboard.println("\\nu"); }
        else if (L == 0 && C == 8) { Keyboard.println("\\mu"); }
        else if (L == 0 && C == 9) { Keyboard.println("\\theta"); }
        else if (L == 0 && C == 10) { Keyboard.println("\\Phi"); }
        else if (L == 0 && C == 11) { Keyboard.println("\\rho"); }
        else if (L == 0 && C == 12) { Keyboard.println("\\tau"); }
        else if (L == 0 && C == 13) { Keyboard.println("\\sigma"); }
        else if (L == 0 && C == 14) { Keyboard.println("\\pi"); }
        else if (L == 0 && C == 15) { Keyboard.println("\\omega"); }
        else if (L == 0 && C == 16) { Keyboard.println("\\Omega"); }
        else if (L == 0 && C == 17) { Keyboard.println("\\eta"); }
        else if (L == 1 && C == 0) { Keyboard.println("\\times"); }
        else if (L == 1 && C == 1) { Keyboard.println("\\sum"); }
        else if (L == 1 && C == 2) { Keyboard.println("\\int"); }
        else if (L == 1 && C == 3) { Keyboard.println("\\iint"); }
        else if (L == 1 && C == 4) { Keyboard.println("\\iiint"); }
        else if (L == 1 && C == 5) { Keyboard.println("\\prod"); }
        else if (L == 1 && C == 6) { Keyboard.println("\\otimes"); }
        else if (L == 1 && C == 7) { Keyboard.println("\\land"); }
        else if (L == 1 && C == 8) { Keyboard.println("\\frac{\\partial}{\\partial t}"); }
        else if (L == 1 && C == 9) { Keyboard.println("\\frac{D}{Dt}"); }
        else if (L == 1 && C == 10) { Keyboard.println("\\vert"); }
        else if (L == 1 && C == 11) { Keyboard.println("\\sqrt"); }
        else if (L == 1 && C == 12) { Keyboard.println("+"); }
        else if (L == 1 && C == 13) { Keyboard.println("-"); }
        else if (L == 1 && C == 14) { Keyboard.println("\\div"); }
        else if (L == 1 && C == 15) { Keyboard.println("\\pm"); }
        else if (L == 1 && C == 16) { Keyboard.println("\\mathcal{F}"); }
        else if (L == 1 && C == 17) { Keyboard.println("\\chapter"); }
        else if (L == 2 && C == 0) { Keyboard.println("\\section"); }
        else if (L == 2 && C == 1) { Keyboard.println("\\subsection"); }
        else if (L == 2 && C == 2) { Keyboard.println("\\subsubsection"); }
        else if (L == 2 && C == 3) { Keyboard.println("\\begin{align}"); }
        else if (L == 2 && C == 4) { Keyboard.println("\\end{align}"); }
        else if (L == 2 && C == 5) { Keyboard.println("\\begin{equation}"); }
        else if (L == 2 && C == 6) { Keyboard.println("\\end{equation}"); }
        else if (L == 2 && C == 7) { Keyboard.println("\\begin{itemize}"); }
        else if (L == 2 && C == 8) { Keyboard.println("\\end{itemize}"); }
        else if (L == 2 && C == 9) { Keyboard.println("\\begin{enumerate}"); }
        else if (L == 2 && C == 10) { Keyboard.println("\\end{enumerate}"); }
        else if (L == 2 && C == 11) { Keyboard.println("\\begin{cases}"); }
        else if (L == 2 && C == 12) { Keyboard.println("\\end{cases}"); }
        else if (L == 2 && C == 13) { Keyboard.println("\\dot"); }
        else if (L == 2 && C == 14) { Keyboard.println("\\ddot"); }
        else if (L == 2 && C == 15) { Keyboard.println("\\dddot"); }
        else if (L == 2 && C == 16) { Keyboard.println("\\overline{\\overline}"); }
        else if (L == 2 && C == 17) { Keyboard.println("\\overrightarrow"); }
        else if (L == 3 && C == 0) { Keyboard.println("_"); }
        else if (L == 3 && C == 1) { Keyboard.println("^"); }
        else if (L == 3 && C == 2) { Keyboard.println("{"); }
        else if (L == 3 && C == 3) { Keyboard.println("}"); }
        else if (L == 3 && C == 4) { Keyboard.println("("); }
        else if (L == 3 && C == 5) { Keyboard.println(")"); }
        else if (L == 3 && C == 6) { Keyboard.println("["); }
        else if (L == 3 && C == 7) { Keyboard.println("]"); }
        else if (L == 3 && C == 8) { Keyboard.println("\\mathbb{R}^1"); }
        else if (L == 3 && C == 9) { Keyboard.println("\\mathbb{R}^2"); }
        else if (L == 3 && C == 10) { Keyboard.println("\\mathbb{R}^3"); }
        else if (L == 3 && C == 11) { Keyboard.println("\\hat"); }
        else if (L == 3 && C == 12) { Keyboard.println("\\,"); }
        else if (L == 3 && C == 13) { Keyboard.println("\\infty"); }
        else if (L == 3 && C == 14) { Keyboard.println("\\leq"); }
        else if (L == 3 && C == 15) { Keyboard.println("<"); }
        else if (L == 3 && C == 16) { Keyboard.println("\\geq"); }
        else if (L == 3 && C == 17) { Keyboard.println(">"); }
        else if (L == 4 && C == 0) { Keyboard.println("\\neq"); }
        else if (L == 4 && C == 1) { Keyboard.println("\\in"); }
        else if (L == 4 && C == 2) { Keyboard.println("\\notin"); }
        else if (L == 4 && C == 3) { Keyboard.println("\\exists"); }
        else if (L == 4 && C == 4) { Keyboard.println("\\nexists"); }
        else if (L == 4 && C == 5) { Keyboard.println("\\cup"); }
        else if (L == 4 && C == 6) { Keyboard.println("\\cap"); }
        else if (L == 4 && C == 7) { Keyboard.println("\\perp"); }
        else if (L == 4 && C == 8) { Keyboard.println("\\parallel"); }
        else if (L == 4 && C == 9) { Keyboard.println("\\forall"); }
        else if (L == 4 && C == 10) { Keyboard.println("="); }
        else if (L == 4 && C == 11) { Keyboard.println("0"); }
        else if (L == 4 && C == 12) { Keyboard.println("1"); }
        else if (L == 4 && C == 13) { Keyboard.println("2"); }
        else if (L == 4 && C == 14) { Keyboard.println("3"); }
        else if (L == 4 && C == 15) { Keyboard.println("4"); }
        else if (L == 4 && C == 16) { Keyboard.println("5"); }
        else if (L == 4 && C == 17) { Keyboard.println("6"); }
        else if (L == 5 && C == 0) { Keyboard.println("7"); }
        else if (L == 5 && C == 1) { Keyboard.println("8"); }
        else if (L == 5 && C == 2) { Keyboard.println("9"); }
        else if (L == 5 && C == 3) { Keyboard.println("\\,"); }
        else if (L == 5 && C == 4) { Keyboard.println("\\["); }
        else if (L == 5 && C == 5) { Keyboard.println("\\]"); }
        else if (L == 5 && C == 6) { Keyboard.println("\\overrightarrow"); }
        else if (L == 5 && C == 7) { Keyboard.println("_"); }
        else if (L == 5 && C == 8) { Keyboard.println("^"); }
        else if (L == 5 && C == 9) { Keyboard.println("{"); }
        else if (L == 5 && C == 10) { Keyboard.println("}"); }
        else if (L == 5 && C == 11) { Keyboard.println("("); }
        else if (L == 5 && C == 12) { Keyboard.println(")"); }
        else if (L == 5 && C == 13) { Keyboard.println("["); }
        else if (L == 5 && C == 14) { Keyboard.println("]"); }
        else if (L == 5 && C == 15) { Keyboard.println("\\mathbb{R}^1"); }
        else if (L == 5 && C == 16) { Keyboard.println("\\mathbb{R}^2"); }
        else if (L == 5 && C == 17) { Keyboard.println("\\mathbb{R}^3"); }
      }
      digitalWrite(lignesPins[L], HIGH);
    }
  }
}

Merci par avance pour votre réponse

L'idée serait quelque chose comme cela:

#include <Keypad.h>
#include <Keyboard.h>

const int NB_LIGNES = 6;
const int NB_COLS = 18;

byte rowPins[NB_LIGNES] = {13, 12, 11, 8, 7, 6};
byte colPins[NB_COLS] = {34, 41, 16, 39, 45, 42, 49, 39, 29, 27, 40, 20, 43, 46, 26, 33, 25, 28};

const char * commandes[NB_LIGNES][NB_COLS] = {
  {"\\alpha", "\\beta", "\\gamma", "\\Gamma", "\\delta", "\\Delta", "\\epsilon", "\\nu", "\\mu", "\\theta", "\\Phi", "\\rho", "\\tau", "\\sigma", "\\pi", "\\omega", "\\Omega", "\\eta"},
  {"\\times", "\\sum", "\\int", "\\iint", "\\iiint", "\\prod", "\\otimes", "\\land", "\\frac{\\partial}{\\partial t}", "\\frac{D}{Dt}", "\\vert", "\\sqrt", "+", "-", "\\div", "\\pm", "\\mathcal{F}", "\\chapter"},
  {"\\section", "\\subsection", "\\subsubsection", "\\begin{align}", "\\end{align}", "\\begin{equation}", "\\end{equation}", "\\begin{itemize}", "\\end{itemize}", "\\begin{enumerate}", "\\end{enumerate}", "\\begin{cases}", "\\end{cases}", "\\dot", "\\ddot", "\\dddot", "\\overline{\\overline}", "\\overrightarrow"},
  {"_", "^", "{", "}", "(", ")", "[", "]", "\\mathbb{R}^1", "\\mathbb{R}^2", "\\mathbb{R}^3", "\\hat", "\\,", "\\infty", "\\leq", "<", "\\geq", ">"},
  {"\\neq", "\\in", "\\notin", "\\exists", "\\nexists", "\\cup", "\\cap", "\\perp", "\\parallel", "\\forall", "=", "0", "1", "2", "3", "4", "5", "6"},
  {"7", "8", "9", "\\,", "\\[", "\\]", "\\overrightarrow", "_", "^", "{", "}", "(", ")", "[", "]", "\\mathbb{R}^1", "\\mathbb{R}^2", "\\mathbb{R}^3"}
};


char touches[NB_LIGNES][NB_COLS];
Keypad keypad = Keypad( makeKeymap(touches), rowPins, colPins, NB_LIGNES, NB_COLS );


void setup() {
  Keyboard.begin();
  Serial.begin(115200);
  for (byte ligne = 0; ligne < NB_LIGNES; ligne++)
    for (byte col = 0; col < NB_COLS; col++)
      touches[ligne][col] = 10 * col + ligne + 1; // +1 car la valeur 0 n'est pas autorisée (utilisée pour dire "aucune touche appuyée" par getKey)
  Serial.println("PRET");
}

void loop() {
  byte key = (byte) keypad.getKey();

  if (key) {
    byte colonne = (key - 1) / 10;
    byte ligne = (key - 1) % 10;
    Serial.print("col=");    Serial.print(colonne);
    Serial.print(", ligne="); Serial.print(ligne);
    Serial.print(" ==> "); Serial.println(commandes[ligne][colonne]);
    Keyboard.println(commandes[ligne][colonne]);
  }
}

l'astuce consiste à remplir le tableau des touches par un code qui permet de retrouver le N° de ligne et colonne de la touche appuyée. Lors de l'appui ce code est retourné et on extrait la ligne et la colonne et on s'en sert pour aller chercher le bon texte dans le tableau des commandes.

Cela suppose bien sûr que votre matrice de boutons fonctionne correctement pour la bibliothèque Keypad

Bonjour
Merci, pour votre réponse
Votre code fonctionne, mais pour avoir la disposition AZERTY, j'ai dû passer à la bibliothèque KeyboardAzertyFr. De plus cette librairie a une erreur de codage de "" , il faut modifier la ligne de 0X25 à 0X5c

#include <Keypad.h>
#include <KeyboardAzertyFr.h> // Inclusion de la bibliothèque Azerty

// Définition du nombre de lignes et de colonnes du clavier
const int NB_LIGNES = 6;
const int NB_COLS = 18;

// Définition des broches de ligne et de colonne
byte RowPins[NB_LIGNES] = {8, 7, 10, 11, 12, 13}; // Réorganiser les rangées
byte ColPins[NB_COLS] = {46, 43, 35, 20, 40,27,25,33,26,29,39,49,38,45,37,16,41,34}; // Réorganiser les colonnes

// Tableau des caractères à afficher
const char * commandes[NB_LIGNES][NB_COLS] = {
  {"\\alpha ", "\\beta ", "\\delta ", "\\Delta", "\\begin{itemize}", "\\end{itemize}", "\\chapter","\\overrightarrow{" , "\\overline{\\overline{\\sigma}}", "\\exists", "\\nexists", "\\in", "\\notin", "\\forall", "", "7", "8", "9"},
  {"\\sigma ", "\\Sigma ", "\\varphi ", "\\Phi", "\\begin{enumerate}", "\\end{enumerate}", "\\section", "\\dot{", "\\overline{\\overline{\\epsilon}}", "\\times", "\\div", "\\land", "\\otimes", "","", "4", "5", "6"},
  {"\\nabla ", "\\theta ", "\\pi ", "\\rho ", "\\begin{cases}", "\\end{cases}", "\\subsection", "\\dddot{", "\\overline{\\overline{\\text{grad}}}", "\\int", "\\iint", "\\iiint", "\\sum", "\\prod", "", "1", "2", "3"},
  {"\\eta ", "\\nu ", "\\m u", "\\epsilon ", "\\[", "\\]", "\\subsubsection","\\ddot{" , "\\overline{\\nabla}", "\\mathbb{R}^1", "\\mathbb{R}^2", "\\mathbb{R}^3", "\\Leftrightarrow", "\\Rightarrow", "", "","0", ""},
  {"\\gamma ", "\\Gamma ", "\\lambda ", "\chi ", "\\left( ", "\\right)", "","\\overline{", "\\overline{\\text{div}}", "\\leq", "<", "\\approx", ">", "\\geq", "\\neq", "", "", ""},
  {"\\", "{", "}", "$", "\\left[", "\\right]","~","\\overline{\\overline{" ,  "\\overline{\\text{rot}}", "\\vert", "\\Vert", "\\perp", "\\infty", "", "", "", ""}
};


// Déclaration du clavier et association des touches
char touches[NB_LIGNES][NB_COLS];
Keypad keypad = Keypad( makeKeymap(touches), RowPins, ColPins, NB_LIGNES, NB_COLS );

void setup() {
  // Initialisation du clavier Azerty
  KeyboardAzertyFr.begin();
  // Début de la communication série
  Serial.begin(115200);

  // Initialisation des touches
  for (byte ligne = 0; ligne < NB_LIGNES; ligne++) {
    for (byte col = 0; col < NB_COLS; col++) {
      touches[ligne][col] = 10 * col + ligne + 1; // +1 car 0 est utilisé pour "aucune touche appuyée"
    }
  }

  // Affichage d'un message de confirmation
  Serial.println("PRET");
}

void loop() {
  // Détection d'une touche pressée
  byte key = (byte) keypad.getKey();

  // Si une touche est pressée
  if (key) {
    // Détermination de la colonne et de la ligne de la touche
    byte colonne = (key - 1) / 10;
    byte ligne = (key - 1) % 10;

    // Affichage des informations de la touche
    Serial.print("Colonne : "); Serial.print(colonne);
    Serial.print(", Ligne : "); Serial.print(ligne);
    Serial.print(" ==> "); Serial.println(commandes[ligne][colonne]);

    // Envoi du caractère correspondant à la touche
    KeyboardAzertyFr.print(commandes[ligne][colonne]);
  }
}

très bien

bonne continuation, ravi si mon code a pu vous aider

en y repensant, il vaudrait mieux faire l'Initialisation des touches avant d'appeler KeyboardAzertyFr.begin();, même si ça ne changer rien, c'est "plus propre" car la fonction begin() aura ainsi le tableau des touches correctement configuré.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.