7 segments

IMG_20130610_233118
4-Digit LED de type 5641 BS
CaptureCapture3 Capture27segment2circuit_TYC-365GWB
Les 4 chiffres sont constitués de 7 segments et utilisent 12 digital pins. 4 anodes sont communes ; 1 pour chaque chiffre. 8 pins pour chaque segment (y compris le point).La connexion se fait en reliant les 4 anodes avec des résistances de 330 ohms aux pins analogiques ou digitales de l’Arduino. Les 8 cathodes sont aussi à connecter  aux pins analogiques ou digitales de l’Arduino.Les broches sont réparties suivant l’ordre (à vérifier)
Broches en haut des chiffres :
(DIGIT 1), A, F,( DIGIT 2),  ( DIGIT 3), B
Broches en bas des chiffres :
E, D, DP, C, G, (DIGIT 4)
These is a Common Anode LEDs, which means that the positive end of every LED on each digit is connected together
You should use a 330Ω resistor in series with each diode. Ideally you should have one for each cathode (negative end), but using one on each anode will work, but give uneven lighting – saves a lot of wiring though!
Quad Display (Decimal points or Colon is same pinout and connections), connect:
  • Pin 6 (Chiffre de droite Digit 4)      : résistance  330Ω puis Arduino pin 10
  • Pin 8 (2ième chiffre Digit 3)           : résistance  330Ω puis Arduino pin 11
  • Pin 9 (3ième chiffre Digit 2)           : résistance  330Ω puis Arduino pin 12
  • Pin 12 (Chiffre de gauche Digit 1) : résistance  330Ω puis Arduino pin 13
  • Pin 11 : Segment A Arduino pin 2
  •  Pin 7  : Segment B Arduino pin 3
  • Pin  4  : Segment C Arduino pin 4
  •  Pin 2  : Segment D Arduino pin 5
  •  Pin 1  : Segment E Arduino pin 6
  •  Pin 10 : Segment F Arduino pin 7
  •  Pin 5  : Segment G Arduino pin 8
  • Pin 3 : Point (DP) Arduino pin 9

2014-11-08 15.52.22

Le principe est de créer une boucle est d’afficher très rapidement  pour chaque digit tous les segments que l’on souhaite afficher cf code suivant disponible ici

 ///////////////   
  int Digit1=10, Digit2=11, Digit3=12, Digit4=13;  
  int Segments[8] = {2, 3, 4, 6 ,7 ,5, 8, 9};   
 //////////////  
  void setup() {   
   Serial.begin(9600);  
   Serial.println("Initit");  
   //-- Activation du chiffre de gauche  
   pinMode(Digit1, OUTPUT);   
   digitalWrite(Digit1, 0);   
   pinMode(Digit2, OUTPUT);   
   digitalWrite(Digit2, 0);   
   pinMode(Digit3, OUTPUT);   
   digitalWrite(Digit3, 0);  
   pinMode(Digit4, OUTPUT);   
   digitalWrite(Digit4, 0);   
   //-- Initialize all segments pins as outputs   
   for(int i=0; i < 8; i++)   
    pinMode(Segments[i], OUTPUT);    
  }   
 ///////////////  
 void loop() {  
   compte();  
 }  
 ///////////////  
 void clearseg()  
 {for(int i=0; i < 8; i++)     
   digitalWrite(Segments[i], 1);  
 }  
 ///////////////  
 void compte()  
 {for(int compte=0; compte<500; compte++)  
  for(int Digit=1; Digit < 5; Digit++)   
  {  
   switch(Digit) {  
   case 1:  
    digitalWrite(Digit1, 1);  
    digitalWrite(Digit2, 0);  
    digitalWrite(Digit3, 0);  
    digitalWrite(Digit4, 0);  
    //-- Incrémentation du chiffre 1  
    if(compte<100)      
      zero();  
    if (compte>100 && compte<200)      
      un();  
    if (compte>200 && compte<300)  
      deux();  
     if (compte>300 )  
      trois();  
    break;  
   case 2:  
    digitalWrite(Digit1, 0);     
    digitalWrite(Digit2, 1);  
    digitalWrite(Digit3, 0);  
    digitalWrite(Digit4, 0);  
    deux();  
    break;  
   case 3:  
    digitalWrite(Digit3, 1);  
    digitalWrite(Digit2, 0);  
    digitalWrite(Digit4, 0);  
    digitalWrite(Digit1, 0);  
    zero();  
    break;  
   case 4:  
    digitalWrite(Digit4, 1);  
    digitalWrite(Digit2, 0);  
    digitalWrite(Digit3, 0);  
    digitalWrite(Digit1, 0);  
    zero();  
    break;  
   }  
   delay(3);  
  }   
 }  
 void un()  
 { clearseg();  
   digitalWrite(Segments[1], 0);   
   digitalWrite(Segments[2], 0);   
 }  
 void deux()  
 { clearseg();  
   digitalWrite(Segments[0], 0);   
   digitalWrite(Segments[1], 0);   
   digitalWrite(Segments[6], 0);  
   digitalWrite(Segments[4], 0);  
   digitalWrite(Segments[3], 0);    
 }  
 void trois()  
 { clearseg();  
   digitalWrite(Segments[0], 0);   
   digitalWrite(Segments[1], 0);   
   digitalWrite(Segments[2], 0);   
   digitalWrite(Segments[6], 0);  
   digitalWrite(Segments[3], 0);   
 }  
 void zero()  
 { clearseg();  
   digitalWrite(Segments[0], 0);   
   digitalWrite(Segments[1], 0);   
   digitalWrite(Segments[2], 0);   
   digitalWrite(Segments[4], 0);  
   digitalWrite(Segments[5], 0);  
   digitalWrite(Segments[3], 0);   
 }  


Exemple de code :

 ////////////////////////////////////////////////  
 // 7-Seg Counter  
 // Counts seconds using 2, 3 or 4-digit Common-Anode 7-segment LEDs  
 //  
 // This code may be freely used and copied.  
 //  
 // Gareth Davies - June 2012  
 //  
 ////////////////////////////////////////////////  
 int NumberDigits = 4; // select number of digits in the display  
 //Digits[] defines the Arduino pins used for the digit select  
 int Digits[4] = {10, 11, 12, 13}; // only define the number of pins for the numebr of digits you have  
 //Segments[] defines the Arduino pins used for the segment select  
 int Segments[8] = {2, 3, 4, 5 ,6 ,7 ,8, 9};  
 int counter=0;  
 int millisecondspercount = 1000; // set the speed of counting  
 int lookup[11] = {  
  B00111111, B00000110, B01011011, B01001111, B01100110, B01101101, B01111101, B00000111, B01111111, B01101111, B10000000};  
 unsigned long tPrev = 0, tNow;  
 int maxValue = 1;  
 void setup() {          
  // initialize all pins as outputs  
  for(int i=0; i < NumberDigits; i++)  
  {  
   pinMode(Digits[i], OUTPUT);  
   digitalWrite(Digits[i], 0);  
   maxValue = maxValue * 10; // determine maximum value display can show  
  }  
  for(int i=0; i < 8; i++)  
  {  
   pinMode(Segments[i], OUTPUT);  
   digitalWrite(Segments[i], 0);  
  }  
  tPrev = millis();  
 }  
 void loop()  
 {  
  tNow = millis();  
  if(tNow - tPrev > millisecondspercount)  
  {  
   tPrev = tNow;   
   counter++;  
   if(counter >= maxValue)  
    counter = 0;  
  }  
  int count = counter;  
  for(int i = 0; i < NumberDigits; i++)  
  {  
   showdigit(i, count%10);  
   delay(2);  
   count = count/10;  
  }  
 }  
 // digit must be 0..3 and value must be 0..9  
 void showdigit(int digit, int value)  
 {  
  int seg = getsegs(value);  
  for(int i = 0; i < 8; i++) // clear all segments to avoid background flickering  
   digitalWrite(Segments[i], 1);  
  for(int i = 0; i < NumberDigits; i++) // address selected digit only  
  {  
   if(i == digit)  
    digitalWrite(Digits[i], 1);  
   else  
    digitalWrite(Digits[i], 0);  
  }  
  for (int i = 0; i < 8; i++) // select correct segments  
  {  
   if(bitRead(seg, i)==1)  
    digitalWrite(Segments[i], 0);  
   else  
    digitalWrite(Segments[i], 1);  
  }  
 }  
 int getsegs(int value)  
 {  
  return lookup[value];  
 }  

 

Votre commentaire

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:

Logo WordPress.com

Vous commentez à l’aide de votre compte WordPress.com. Déconnexion /  Changer )

Image Twitter

Vous commentez à l’aide de votre compte Twitter. Déconnexion /  Changer )

Photo Facebook

Vous commentez à l’aide de votre compte Facebook. Déconnexion /  Changer )

Connexion à %s

Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur la façon dont les données de vos commentaires sont traitées.

Articles récents
Commentaires récents
fatima dans Bienvenue !
AdminDroid dans Bienvenue !
fatima dans Bienvenue !
Archives
Catégories
%d blogueurs aiment cette page :