Ardumotive Arduino Greek Playground
  • Home
    • About us
    • Contact
    • License
  • Arduino
    • Tutorials
    • Workshop
  • Raspberry Pi
  • DIY 3D Printer
  • News
    • Events >
      • Unboxing & Review
    • Blog
The 1st Arduino Playground in Greece - Open Source Hardware

2-Digit 7 Segment Display 74HC595 module

Available Languages
Picture
Picture

Εισαγωγή

Picture
Σε αυτόν τον οδηγό θα μάθουμε πως να χρησιμοποιούμε ενα 7 seg display 2 ψηφίων με το Arduino UNO.  Η συγκεκριμένη πλακέτα έχει ένα 74HC595 (shift register) IC για κάθε ψηφίο του. Στο συγκεκριμένο tutorial θα χρησιμοποιήσουμε την συνάρτηση countUp()  για να μετρήσουμε απ' το 0 μέχρι τον αριθμό 'number' και την countDown() για να μετρήσουμε απ' τον αριθμό αυτό μέχρι το 0. Ο αριθμός 'number' μπορεί να αλλάξει με όποιο νούμερο θέλετε από 0 μέχρι  99.

Τα υλικά που θα χρειαστούμε


Για το tutorial αυτό θα χρειαστούμε:
  • Arduino uno
  • 2-Digit Seven Segment Display Module ​

Το κύκλωμα

Η συνδεσμολογία είναι αρκετά εύκολη:
H συνδεσμολογία του Display:
  • VCC στα 5V του Arduino 
  • GND στο GND του Arduino
  • SDD στο Pin 2  του Arduino
  • CLK στο Pin 3 του Arduino 
  • LOAD στο Pin 4  του Arduino

Ο κώδικας

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* 
 *  2 Digitl 7 segment display PCB board with (2) 74HC595 shift register ICs
 *  Arduino Tutorial - www.Ardumotive.com
 *  Dev: Michalis Vasilakis // Date: 31/1/2018 // Ver:1.0
 */
#include <ShiftRegister74HC595.h>
// create shift register object (number of shift registers, data pin, clock pin, latch pin)
ShiftRegister74HC595 sr (2, 2, 3, 4); 

int number=99; // <--- Change it from 0 to 99

int value,digit1,digit2,digit3,digit4; 
uint8_t  numberB[] = {B11000000, //0
                      B11111001, //1 
                      B10100100, //2
                      B10110000, //3 
                      B10011001, //4
                      B10010010, //5
                      B10000011, //6
                      B11111000, //7
                      B10000000, //8
                      B10011000 //9
                     };
                        
void setup() {
  //Count from 0 to 'number' 
  countUp();
  //Count from 'number' to 0
  //countDown();  // <--- Comment countUp and uncomment countDown
  //Blink 4 times all on and all off.
  blink();  
}

void loop() {

}

void countUp(){
  for (int i = 0; i<=number; i++){
    //Split number to digits:
    digit2=i % 10 ;
    digit1=(i / 10) % 10 ;
    //Send them to 7 segment displays
    uint8_t numberToPrint[]= {numberB[digit2],numberB[digit1]};
    sr.setAll(numberToPrint); 
    //Reset them for next time
    digit1=0;
    digit2=0;
    delay(1000); // Repeat every 1 sec
  }
}

void countDown(){
  for (number; number>=0; number--){
    //Split number to digits:
    digit2=number % 10 ;
    digit1=(number / 10) % 10 ;
    //Send them to 7 segment displays
    uint8_t numberToPrint[]= {numberB[digit2],numberB[digit1]};
    sr.setAll(numberToPrint); 
    //Reset them for next time
    digit1=0;
    digit2=0;
    delay(1000); // Repeat every 1 sec
  }
}

//Blink
void blink(){
  for(int i = 0; i<4; i++){
    sr.setAllLow(); // set all pins Low (off)
    delay(1000);
    sr.setAllHigh(); // set all pins High (on)
    delay(1000);
  }
}
Κατεβάστε τον κώδικα απ' εδώ και ανοίξτε το αρχείο με το Arduino IDE. Μέσα θα βρείτε και την απαραίτητη βιβλιοθήκη,
twodigit7seg595.zip
File Size: 2 kb
File Type: zip
Download File

Συγχαρητήρια!

Picture
Μόλις ολοκληρώσατε άλλο ένα "How to" tutorial και μάθατε πως να χρησιμοποιείτε το 2-Digit Seven Segment Display 74HC595 module.
​​
Ελπίζω να σας άρεσε, αν θέλετε μπορείτε να αφήσετε το σχόλιο σας παρακάτω. 
Picture

Search Engine

Picture

Licence 

Picture

Help us to grow up!

Picture


Donate us
About us
License
Cookies policy

Visit the biggest Arduino Shop in Greece!

Picture
find us on dwrean.net
find us on Codebender
find us on Instructables
Developed and designed by Vasilakis Michalis Copyright © 2013 Ardumotive All Rights Reserved
All trademarks referenced herein are properties of their
Powered by Create your own unique website with customizable templates.
Design by DivTag Templates