Bonjour tout le monde,
J'ai 16 ans, et je compte faire une planche pour flight simulator avec plusieurs interrupteurs on off relié sur un multiplexer CD74HC4067 et 3 encodeurs le tout relies à un arduino pro micro qui agira comme un clavier grace a la library keyboard, pour pouvoir utiliser sur xbox comme pc. Lorsque chaque interrupteur est changé de position il doit envoyer un caractère pour la position off et un caractère different en position off, pour tout des interrupteurs. Pour les encodeurs rotatifs, ils doivent envoyer un caractère pour chaque pas dans le sens horaire et dans le sens anti horaire.
J'ai du mal avec le code j'ai essayé le code suivant sur un arduino une pour me servir de prototype ( il envoie serial.print à la place de keyboard car la library n'est pas compatible avec les uno ) mais il comporte beaucoup problème. Je me demande si quelqu'un peut m'aider s'il vous plait ![]()
#include <light_CD74HC4067.h>
#define inputCLK 4
#define inputDT 5
#define inputCLK1 6
#define inputDT1 7
#define inputCLK2 2
#define inputDT2 3
CD74HC4067 mux(A5, A4, A3, A2);
int currentStateCLK;
int previousStateCLK;
int currentStateCLK1;
int previousStateCLK1;
int currentStateCLK2;
int previousStateCLK2;
int previous[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
const int signal_pin = A1;
int current[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
void setup() {
pinMode (signal_pin,INPUT_PULLUP);
pinMode (inputCLK,INPUT);
pinMode (inputDT,INPUT);
pinMode (inputCLK1,INPUT);
pinMode (inputDT1,INPUT);
pinMode (inputCLK2,INPUT);
pinMode (inputDT2,INPUT);
// Setup Serial Monitor
Serial.begin (9600);
// Assign to previousStateCLK variable
previousStateCLK = digitalRead(inputCLK);
previousStateCLK1 = digitalRead(inputCLK1);
previousStateCLK2 = digitalRead(inputCLK2);
}
void loop() {
// Read the current state of inputCLK
currentStateCLK = digitalRead(inputCLK);
// If the previous and the current state of the inputCLK are different then a pulse has occured
if (currentStateCLK != previousStateCLK){
// If the inputDT state is different than the inputCLK state then
// the encoder is rotating counterclockwise
if (digitalRead(inputDT) != currentStateCLK) {
Serial.println("up");
} else {
// Encoder is rotating clockwise
Serial.println("down");
}
}
// Update previousStateCLK with the current state
previousStateCLK = currentStateCLK;
currentStateCLK1 = digitalRead(inputCLK1);
// If the previous and the current state of the inputCLK1 are different then a pulse has occured
if (currentStateCLK1 != previousStateCLK1){
// If the inputDT1 state is different than the inputCLK1 state then
// the encoder is rotating counterclockwise
if (digitalRead(inputDT1) != currentStateCLK1) {
Serial.println("up");
} else {
// Encoder is rotating clockwise
Serial.println("down");
}
}
// Update previousStateCLK1 with the current state
previousStateCLK1 = currentStateCLK1;
currentStateCLK2 = digitalRead(inputCLK2);
// If the previous and the current state of the inputCLK2 are different then a pulse has occured
if (currentStateCLK2 != previousStateCLK2){
// If the inputDT2 state is different than the inputCLK state then
// the encoder is rotating counterclockwise
if (digitalRead(inputDT2) != currentStateCLK2) {
Serial.println("up");
} else {
// Encoder is rotating clockwise
Serial.println("down");
}
}
// Update previousStateCLK2 with the current state
previousStateCLK2 = currentStateCLK2;
for (byte i = 0; i < 16; i++) {
mux.channel(i);
current[i]= digitalRead(signal_pin); // Read analog value
if(current[i]!= previous[i]){
if(current[i]== 0){
Serial.print(i);
Serial.println(". on");
} else {
Serial.print(i);
Serial.println(". off");
}
}
previous[i]=current[i];
delay(50);
}
}


