projets:brutpix:telecommande

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
projets:brutpix:telecommande [2021/06/24 15:46] – modification externe 127.0.0.1projets:brutpix:telecommande [2022/06/08 12:33] (Version actuelle) guillaume
Ligne 160: Ligne 160:
  
 Le code ci-dessous est une adaptation finalement assez simple de celui qui précède, le stockage des valeurs des 5 encodeurs se fait dans un tableau, qui sera réutilisé ensuite pour l'affichage des valeurs. Le code ci-dessous est une adaptation finalement assez simple de celui qui précède, le stockage des valeurs des 5 encodeurs se fait dans un tableau, qui sera réutilisé ensuite pour l'affichage des valeurs.
 +
 +
  
 ``` ```
 #include <Wire.h> #include <Wire.h>
 #include <Adafruit_MCP23017.h> #include <Adafruit_MCP23017.h>
- 
 Adafruit_MCP23017 mcp; Adafruit_MCP23017 mcp;
- 
 byte arduinoIntPinA = 14; byte arduinoIntPinA = 14;
 byte arduinoIntPinB = 12; byte arduinoIntPinB = 12;
- 
 //Les broches de l'encodeur //Les broches de l'encodeur
 //Rot1 //Rot1
 byte mcpPin1A = 6; byte mcpPin1A = 6;
 byte mcpPin1B = 7; byte mcpPin1B = 7;
- 
 //Rot2 //Rot2
 byte mcpPin2A = 4; byte mcpPin2A = 4;
 byte mcpPin2B = 5; byte mcpPin2B = 5;
- 
 //Rot3 //Rot3
 byte mcpPin3A = 2; byte mcpPin3A = 2;
 byte mcpPin3B = 3; byte mcpPin3B = 3;
- 
 //Rot4 //Rot4
 byte mcpPin4A = 0; byte mcpPin4A = 0;
 byte mcpPin4B = 1; byte mcpPin4B = 1;
- 
 //Rot5 //Rot5
 byte mcpPin5A = 14; byte mcpPin5A = 14;
 byte mcpPin5B = 11; byte mcpPin5B = 11;
- 
 // There is an issue with thin pin, don't use GPB7, microchip is aware of it !!!! // There is an issue with thin pin, don't use GPB7, microchip is aware of it !!!!
 //https://forum.arduino.cc/index.php?topic=437248.0  //https://forum.arduino.cc/index.php?topic=437248.0 
 //https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=91209&sid=f8679026e1943ee9b7d05e15f8b36f02&start=25 //https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=91209&sid=f8679026e1943ee9b7d05e15f8b36f02&start=25
- 
 byte mcpPins[10] = {mcpPin1A, mcpPin1B, mcpPin2A, mcpPin2B, mcpPin3A, mcpPin3B, mcpPin4A, mcpPin4B, mcpPin5A, mcpPin5B}; byte mcpPins[10] = {mcpPin1A, mcpPin1B, mcpPin2A, mcpPin2B, mcpPin3A, mcpPin3B, mcpPin4A, mcpPin4B, mcpPin5A, mcpPin5B};
- 
 int encoded[5]; int encoded[5];
 volatile int lastEncoded[5]; volatile int lastEncoded[5];
 volatile long encoderValue[5]; volatile long encoderValue[5];
- 
 long lastencoderValue[5]; long lastencoderValue[5];
- 
 int MSB[5]; int MSB[5];
 int LSB[5]; int LSB[5];
- 
 int lastMSB[5]; int lastMSB[5];
 int lastLSB[5]; int lastLSB[5];
- 
 uint16_t allGPIO; uint16_t allGPIO;
- 
 // 2 SWITCHES // 2 SWITCHES
 //Rot5 //Rot5
Ligne 216: Ligne 203:
 byte sw2 = 13; byte sw2 = 13;
 boolean sw1Pressed, sw2Pressed; boolean sw1Pressed, sw2Pressed;
- 
 long lastPrint = 0; long lastPrint = 0;
 int delayPrint = 50; int delayPrint = 50;
- 
 void setup() { void setup() {
- 
   Serial.begin(115200);   Serial.begin(115200);
   Serial.println("MCP23007 Interrupt Test");   Serial.println("MCP23007 Interrupt Test");
- 
   pinMode(arduinoIntPinA, INPUT);   pinMode(arduinoIntPinA, INPUT);
   pinMode(arduinoIntPinB, INPUT);   pinMode(arduinoIntPinB, INPUT);
- 
   mcp.begin();      // use default address 0   mcp.begin();      // use default address 0
- 
   mcp.pinMode(mcpPin1A, INPUT);   mcp.pinMode(mcpPin1A, INPUT);
   mcp.pinMode(mcpPin1B, INPUT);   mcp.pinMode(mcpPin1B, INPUT);
Ligne 240: Ligne 221:
   mcp.pinMode(mcpPin5A, INPUT);   mcp.pinMode(mcpPin5A, INPUT);
   mcp.pinMode(mcpPin5A, INPUT);   mcp.pinMode(mcpPin5A, INPUT);
- 
   //SW   //SW
   mcp.pinMode(sw1, INPUT);   mcp.pinMode(sw1, INPUT);
   mcp.pinMode(sw2, INPUT);   mcp.pinMode(sw2, INPUT);
- 
   //other pins   //other pins
   mcp.pinMode(8, INPUT);   mcp.pinMode(8, INPUT);
   mcp.pinMode(9, INPUT);   mcp.pinMode(9, INPUT);
   mcp.pinMode(10, INPUT);   mcp.pinMode(10, INPUT);
- 
   mcp.pinMode(15, INPUT);   mcp.pinMode(15, INPUT);
- 
   mcp.pullUp(8, INPUT);   mcp.pullUp(8, INPUT);
   mcp.pullUp(9, INPUT);   mcp.pullUp(9, INPUT);
   mcp.pullUp(10, INPUT);   mcp.pullUp(10, INPUT);
   mcp.pullUp(15, INPUT);   mcp.pullUp(15, INPUT);
- 
   mcp.setupInterrupts(false, false, LOW);   mcp.setupInterrupts(false, false, LOW);
   // Mirroring (first param) must be set to false, may cause crashes when turning multiples buttons   // Mirroring (first param) must be set to false, may cause crashes when turning multiples buttons
- 
   //SW1   //SW1
   mcp.setupInterruptPin(mcpPin1A, CHANGE);   mcp.setupInterruptPin(mcpPin1A, CHANGE);
Ligne 275: Ligne 250:
   mcp.setupInterruptPin(mcpPin5A, CHANGE);   mcp.setupInterruptPin(mcpPin5A, CHANGE);
   mcp.setupInterruptPin(mcpPin5B, CHANGE);   mcp.setupInterruptPin(mcpPin5B, CHANGE);
- 
   //BTN1/2   //BTN1/2
   mcp.setupInterruptPin(sw1, CHANGE);   mcp.setupInterruptPin(sw1, CHANGE);
   mcp.setupInterruptPin(sw2, CHANGE);   mcp.setupInterruptPin(sw2, CHANGE);
- 
   mcp.readGPIOAB();   mcp.readGPIOAB();
- 
   attachInterrupt(digitalPinToInterrupt(arduinoIntPinA), updateEncoderA, FALLING);   attachInterrupt(digitalPinToInterrupt(arduinoIntPinA), updateEncoderA, FALLING);
   attachInterrupt(digitalPinToInterrupt(arduinoIntPinB), updateEncoderB, FALLING);   attachInterrupt(digitalPinToInterrupt(arduinoIntPinB), updateEncoderB, FALLING);
- 
- 
 } }
- 
 ICACHE_RAM_ATTR void updateEncoderA() { ICACHE_RAM_ATTR void updateEncoderA() {
    readGPIO_MCP();    readGPIO_MCP();
 } }
- 
 ICACHE_RAM_ATTR void updateEncoderB() { ICACHE_RAM_ATTR void updateEncoderB() {
   readGPIO_MCP();   readGPIO_MCP();
 } }
- 
 ICACHE_RAM_ATTR void readGPIO_MCP() ICACHE_RAM_ATTR void readGPIO_MCP()
 { {
- 
   // on lit toutes les entrées d'un coup,   // on lit toutes les entrées d'un coup,
   // Reads all 16 pins (port A and B) into a single 16 bits variable.   // Reads all 16 pins (port A and B) into a single 16 bits variable.
   allGPIO = mcp.readGPIOAB();   allGPIO = mcp.readGPIOAB();
- 
   // On utilise bitRead pour récupérer la valeur pour chaque bouton   // On utilise bitRead pour récupérer la valeur pour chaque bouton
   //SW5   //SW5
   MSB[4] = bitRead(allGPIO, 11);   MSB[4] = bitRead(allGPIO, 11);
-  LSB[4] = bitRead(allGPIO, 14); +  LSB[4] = bitRead(allGPIO, 14); 
-  +
   //SW4   //SW4
   MSB[3] = bitRead(allGPIO, 0);   MSB[3] = bitRead(allGPIO, 0);
   LSB[3] = bitRead(allGPIO, 1);   LSB[3] = bitRead(allGPIO, 1);
- 
   //SW3   //SW3
   MSB[2] = bitRead(allGPIO, 2);   MSB[2] = bitRead(allGPIO, 2);
   LSB[2] = bitRead(allGPIO, 3);   LSB[2] = bitRead(allGPIO, 3);
- 
   //SW2   //SW2
   MSB[1] = bitRead(allGPIO, 4);   MSB[1] = bitRead(allGPIO, 4);
   LSB[1] = bitRead(allGPIO, 5);   LSB[1] = bitRead(allGPIO, 5);
- 
   //SW1   //SW1
   MSB[0] = bitRead(allGPIO, 6);   MSB[0] = bitRead(allGPIO, 6);
   LSB[0] = bitRead(allGPIO, 7);   LSB[0] = bitRead(allGPIO, 7);
- 
   //btn   //btn
   sw1Pressed = bitRead(allGPIO, 12);   sw1Pressed = bitRead(allGPIO, 12);
   sw2Pressed = bitRead(allGPIO, 13);   sw2Pressed = bitRead(allGPIO, 13);
- 
   for (int i = 0; i < 5; i++)   for (int i = 0; i < 5; i++)
   {   {
Ligne 337: Ligne 296:
     lastEncoded[i] = encoded[i]; //store this value for next time     lastEncoded[i] = encoded[i]; //store this value for next time
   }   }
- 
 } }
- 
- 
 void loop() { void loop() {
- 
   if (millis() - lastPrint > delayPrint)   if (millis() - lastPrint > delayPrint)
   {   {
Ligne 357: Ligne 312:
     lastPrint = millis();     lastPrint = millis();
   }   }
-     
 } }
 ``` ```
  
  
  • projets/brutpix/telecommande.1624542402.txt.gz
  • Dernière modification : 2021/06/24 15:46
  • de 127.0.0.1