Bonjour,
Je suis un élève de terminale S et je débute en programmation. Je rencontre un problème après avoir créer trois programmes différents (afficheur 7 segments, clavier (3 col / 4row), commande vocale(EasyVR shield)).
Et j'aimerais en fait pouvoir les mettre tous les trois en même temps pour qu'ils agissent ensemble. Et c'est là que j'ai un problème.
Je vous explique clairement ce que j'essaie de faire : lorsque j'appuie sur une touche de mon clavier ou que la commande vocale reconnait un caractère ( par exemple, je dis "un") et l'afficheur affiche 1 ( pareil jusqu'à 9 donc). Pour l'instant je peux faire reconnaitre ma voix, écrire ce que je veux sur l'afficheur et connaître la touche appuyée sur le clavier (sur le moniteur série). J'ai déjà essayé de mélanger le tout mais cela ne donnait rien de concluant.
J'espère que vous pourrez m'aider.
Voici les programmes:
Clavier:
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {7, 6, 5, 4}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {3, 2, 8}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup(){
Serial.begin(9600);
}
void loop(){
char customKey = customKeypad.getKey();
if (customKey){
Serial.println(customKey);
}
}
L'afficheur (Décodeur BCD):
const int bit_A = 2;
const int bit_B = 3;
const int bit_C = 4;
const int bit_D = 5;
void setup()
{
pinMode(bit_A, OUTPUT);
pinMode(bit_B, OUTPUT);
pinMode(bit_C, OUTPUT);
pinMode(bit_D, OUTPUT);
digitalWrite(bit_A, LOW);
digitalWrite(bit_B, LOW);
digitalWrite(bit_C, LOW);
digitalWrite(bit_D, LOW);
}
void loop()
{
char i=0; //variable "compteur"
{
affichage(i); //on appel la fonction d'affichage
delay(1000); //on attend 1 seconde
}
}
void affichage(char chiffre)
{
digitalWrite(bit_A, LOW);
digitalWrite(bit_B, LOW);
digitalWrite(bit_C, LOW);
digitalWrite(bit_D, LOW);
if(chiffre >= 8)
{
digitalWrite(bit_D, HIGH);
chiffre = chiffre - 8;
}
if(chiffre >= 4)
{
digitalWrite(bit_C, HIGH);
chiffre = chiffre - 4;
}
if(chiffre >= 2)
{
digitalWrite(bit_B, HIGH);
chiffre = chiffre - 2;
}
if(chiffre >= 1)
{
digitalWrite(bit_A, HIGH);
chiffre = chiffre - 1;
}
}
Le programme commande vocale:
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#include "SoftwareSerial.h"
SoftwareSerial port(12,13);
#else // Arduino 0022 - use modified NewSoftSerial
#include "WProgram.h"
#include "NewSoftSerial.h"
NewSoftSerial port(12,13);
#endif
#include "EasyVR.h"
EasyVR easyvr(port);
//Groups and Commands
enum Groups
{
GROUP_0 = 0,
GROUP_1 = 1,
};
enum Group0
{
G0_ARDUINO = 0,
};
enum Group1
{
G1_ETAGE1 = 0,
G1_ETAGE2 = 1,
G1_ETAGE3 = 2,
G1_ETAGE0 = 3,
};
EasyVRBridge bridge;
int8_t group, idx;
void setup()
{
// bridge mode?
if (bridge.check())
{
cli();
bridge.loop(0, 1, 12, 13);
}
// run normally
Serial.begin(9600);
port.begin(9600);
if (!easyvr.detect())
{
Serial.println("EasyVR not detected!");
for (;;);
}
easyvr.setPinOutput(EasyVR::IO1, LOW);
Serial.println("EasyVR detected!");
easyvr.setTimeout(5);
easyvr.setLanguage(5);
group = EasyVR::TRIGGER; //<-- start group (customize)
}
void action();
void loop()
{
easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening)
Serial.print("Say a command in Group ");
Serial.println(group);
easyvr.recognizeCommand(group);
do
{
// can do some processing while waiting for a spoken command
}
while (!easyvr.hasFinished());
easyvr.setPinOutput(EasyVR::IO1, LOW); // LED off
idx = easyvr.getWord();
if (idx >= 0)
{
// built-in trigger (ROBOT)
// group = GROUP_X; <-- jump to another group X
return;
}
idx = easyvr.getCommand();
if (idx >= 0)
{
// print debug message
uint8_t train = 0;
char name[32];
Serial.print("Command: ");
Serial.print(idx);
if (easyvr.dumpCommand(group, idx, name, train))
{
Serial.print(" = ");
Serial.println(name);
}
else
Serial.println();
easyvr.playSound(0, EasyVR::VOL_FULL);
// perform some action
action();
}
else // errors or timeout
{
if (easyvr.isTimeout())
Serial.println("Timed out, try again...");
int16_t err = easyvr.getError();
if (err >= 0)
{
Serial.print("Error ");
Serial.println(err, HEX);
}
}
}
void action()
{
switch (group)
{
case GROUP_0:
switch (idx)
{
case G0_ARDUINO:
// write your action code here
// group = GROUP_X; <-- or jump to another group X for composite commands
break;
}
break;
case GROUP_1:
switch (idx)
{
case G1_ETAGE1:
// write your action code here
// group = GROUP_X; <-- or jump to another group X for composite commands
break;
case G1_ETAGE2:
// write your action code here
// group = GROUP_X; <-- or jump to another group X for composite commands
break;
case G1_ETAGE3:
// write your action code here
// group = GROUP_X; <-- or jump to another group X for composite commands
break;
case G1_ETAGE0:
// write your action code here
// group = GROUP_X; <-- or jump to another group X for composite commands
break;
}
break;
}
}
Merci.