Contrôler des LEDs avec le minimum de PINS sur ARDUINO

Vidéo

Liste des Composants

Arduino – Amazon

LEDs (Kit) – Amazon

Résistances (Kit) – Amazon

PCB Soudure – Amazon

Le Schéma

Le Code

Code Arduino

//------------------------------------------------------
//                https://gammatroniques.fr/
//                   Code CharlyPlexing
//               12/2020 - by GammaTroniques
//------------------------------------------------------
#include "leds.h"  //Fichier pour les LEDs
int t = 500; //Valeur de "t"

void setup()
{
}

void loop()
{
  led(1);   //Allumer LED 1
  delay(t); //Attendre la durée "t"
  led(12);  //Allumer LED 12
  delay(t); //Attendre la durée "t"

/*  for (int i = 1; i <= 12; i++) {
    led(i);
    delay(t);
  }     */
} 

Fichier "led.h"

const int LED_1 = 13;     //Pin 1
const int LED_2 = 12;     //Pin 2
const int LED_3 = 11;     //Pin 3
const int LED_4 = 10;     //Pin 4

void led (int i) {      //Fonction led();
  if (i == 1) {         //Pour led(1);
    pinMode(LED_1, INPUT);
    digitalWrite(LED_1, LOW); //Le courant ne passe pas
    pinMode(LED_2, INPUT);
    digitalWrite(LED_2, LOW); //Le courant ne passe pas
    pinMode(LED_3, OUTPUT);
    digitalWrite(LED_3, LOW); //- du courant
    pinMode(LED_4, OUTPUT);
    digitalWrite(LED_4, HIGH);//+ du courant
  }
  else if (i == 2) {   //Pour led(2);
    pinMode(LED_1, INPUT);
    digitalWrite(LED_1, LOW);
    pinMode(LED_2, OUTPUT);
    digitalWrite(LED_2, LOW);
    pinMode(LED_3, OUTPUT);
    digitalWrite(LED_3, HIGH);
    pinMode(LED_4, INPUT);
    digitalWrite(LED_4, LOW);
  }
  else if (i == 3) {   //Pour led(3);
    pinMode(LED_1, OUTPUT);
    digitalWrite(LED_1, LOW);
    pinMode(LED_2, OUTPUT);
    digitalWrite(LED_2, HIGH);
    pinMode(LED_3, INPUT);
    digitalWrite(LED_3, LOW);
    pinMode(LED_4, INPUT);
    digitalWrite(LED_4, LOW);
  }
  else if (i == 4) {   //Pour led(4);
    pinMode(LED_1, INPUT);
    digitalWrite(LED_1, LOW);
    pinMode(LED_2, INPUT);
    digitalWrite(LED_2, LOW);
    pinMode(LED_3, OUTPUT);
    digitalWrite(LED_3, HIGH);
    pinMode(LED_4, OUTPUT);
    digitalWrite(LED_4, LOW);
  }
  else if (i == 5) {   //Pour led(5);
    pinMode(LED_1, INPUT);
    digitalWrite(LED_1, LOW);
    pinMode(LED_2, OUTPUT);
    digitalWrite(LED_2, HIGH);
    pinMode(LED_3, OUTPUT);
    digitalWrite(LED_3, LOW);
    pinMode(LED_4, INPUT);
    digitalWrite(LED_4, LOW);
  }
  else if (i == 6) {
    pinMode(LED_1, OUTPUT);
    digitalWrite(LED_1, HIGH);
    pinMode(LED_2, OUTPUT);
    digitalWrite(LED_2, LOW);
    pinMode(LED_3, INPUT);
    digitalWrite(LED_3, LOW);
    pinMode(LED_4, INPUT);
    digitalWrite(LED_4, LOW);
  }
  else if (i == 7) {
    pinMode(LED_1, INPUT);
    digitalWrite(LED_1, LOW);
    pinMode(LED_2, OUTPUT);
    digitalWrite(LED_2, LOW);
    pinMode(LED_3, INPUT);
    digitalWrite(LED_3, LOW);
    pinMode(LED_4, OUTPUT);
    digitalWrite(LED_4, HIGH);
  }
  else if (i == 8) {
    pinMode(LED_1, OUTPUT);
    digitalWrite(LED_1, LOW);
    pinMode(LED_2, INPUT);
    digitalWrite(LED_2, LOW);
    pinMode(LED_3, INPUT);
    digitalWrite(LED_3, LOW);
    pinMode(LED_4, OUTPUT);
    digitalWrite(LED_4, HIGH);
  }
  else if (i == 9) {
    pinMode(LED_1, OUTPUT);
    digitalWrite(LED_1, LOW);
    pinMode(LED_2, INPUT);
    digitalWrite(LED_2, LOW);
    pinMode(LED_3, OUTPUT);
    digitalWrite(LED_3, HIGH);
    pinMode(LED_4, INPUT);
    digitalWrite(LED_4, LOW);
  }
  else if (i == 10) {
    pinMode(LED_1, INPUT);
    digitalWrite(LED_1, LOW);
    pinMode(LED_2, OUTPUT);
    digitalWrite(LED_2, HIGH);
    pinMode(LED_3, INPUT);
    digitalWrite(LED_3, LOW);
    pinMode(LED_4, OUTPUT);
    digitalWrite(LED_4, LOW);
  }
  else if (i == 11) {
    pinMode(LED_1, OUTPUT);
    digitalWrite(LED_1, HIGH);
    pinMode(LED_2, INPUT);
    digitalWrite(LED_2, LOW);
    pinMode(LED_3, INPUT);
    digitalWrite(LED_3, LOW);
    pinMode(LED_4, OUTPUT);
    digitalWrite(LED_4, LOW);
  }
  else if (i == 12) {
    pinMode(LED_1, OUTPUT);
    digitalWrite(LED_1, HIGH);
    pinMode(LED_2, INPUT);
    digitalWrite(LED_2, LOW);
    pinMode(LED_3, OUTPUT);
    digitalWrite(LED_3, LOW);
    pinMode(LED_4, INPUT);
    digitalWrite(LED_4, LOW);
  }
}