Components and supplies
1
Resistor 220 ohm
1
Shift Register- Serial to Parallel
1
Breadboard (generic)
20
Jumper wires (generic)
1
Arduino UNO
1
4 Digit 7 Segment Common Anode Display
Apps and platforms
1
Arduino IDE
Project description
Code
4 Digit 7 Segment + Shift Register
c_cpp
Code with lots of //comments!
1 2int latchPin = 5; 3int dataPin = 4; 4int clockPin = 6; 5const float segSpeed = .05; //How quickly to flash each led segment. 6const int digLoop = 100; //How many times to repeat the segment sequence. 7const int nextPin = 200; //Delay before moving to the next digit on the display. 8const int repeatSeq = 300; //Delay before starting over from the first digit. 9const int pinArray[4] = {3, 9, 10, 11}; //Defines PWM pins, the pins that activate each digiti. 10const int digArray[11][9] = { 11 {127, 191, 223, 239, 247, 251, 255, 254, 255}, //0: 127 top led segment 12 {255, 191, 223, 255, 255, 255, 255, 254, 255}, //1: 191 top right seg 13 {127, 191, 255, 239, 247, 255, 253, 254, 255}, //2: 255 is NO segment 14 {127, 191, 223, 239, 255, 255, 253, 254, 255}, //3: 223 bottom right seg 15 {255, 191, 223, 255, 255, 251, 253, 254, 255}, //4: 16 {127, 255, 223, 239, 255, 251, 253, 254, 255}, //5: 239 bottom seg 17 {127, 191, 223, 239, 247, 255, 253, 254, 255}, //6: 247 bottom left seg 18 {127, 191, 223, 255, 255, 255, 255, 254, 255}, //7: 19 /*Example for the number 7: 20 * 127: |_ON | 21 * 251:OFF ON:191 22 * 253: OFF | | 23 * 247:OFF ON:223 24 * 239: OFF |_| 25 */ 26 {127, 191, 223, 239, 247, 251, 253, 254, 255}, //8: 251 top left seg 27 {127, 191, 223, 239, 255, 251, 253, 254, 255}, //9: 253 center seg 28 {255, 255, 255, 255, 255, 255, 255, 254, 255}, //DP: Decimal Point seg 29}; 30const int arrHeight = 9; // (0-9) 9 displays digits 0-9. 31const int arrWidth = 6; // (0-8) how many segments from each row to use. 7 will add the decimal row. 32 33void setup() { 34 //Serial.begin(9600); //which port to output serial display data. unused. slows display down. 35 pinMode(latchPin, OUTPUT); 36 pinMode(dataPin, OUTPUT); 37 pinMode(clockPin, OUTPUT); 38} 39 40void loop() { 41 for (int i = 0; i <= 3; i++) { //cycles through all PWM pins 42 for (int k = 0; k <= arrHeight; k++) { //cycles through countTo number of digArray rows 43 analogWrite((pinArray[i]), 255); //turns PWM pin(i) on 44 for (int h = 0; h <= digLoop; h++) { //how many times to cycle through columns 45 for (int j = 0; j <= arrWidth; j++) { //cycles through all displayed column data 46 digitalWrite(latchPin, HIGH); 47 shiftOut(dataPin, clockPin, MSBFIRST, digArray[k][j]); 48 digitalWrite(latchPin, LOW); 49 delay(segSpeed); //delay until next segment displayed sequence 50 } 51 } 52 analogWrite((pinArray[i]), 0); //turns PWM pin(i) off 53 delay(nextPin); //delay until next displayed digit sequence 54 } 55 } 56 delay(repeatSeq); //delay until everything is started over again 57}
4 Digit 7 Segment + Shift Register
c_cpp
Code with lots of //comments!
1 2int latchPin = 5; 3int dataPin = 4; 4int clockPin = 6; 5const 6 float segSpeed = .05; //How quickly to flash each led segment. 7const int digLoop 8 = 100; //How many times to repeat the segment sequence. 9const int nextPin = 200; 10 //Delay before moving to the next digit on the display. 11const int repeatSeq = 12 300; //Delay before starting over from the first digit. 13const int pinArray[4] 14 = {3, 9, 10, 11}; //Defines PWM pins, the pins that activate each digiti. 15const 16 int digArray[11][9] = { 17 {127, 191, 223, 239, 247, 251, 255, 254, 255}, //0: 18 127 top led segment 19 {255, 191, 223, 255, 255, 255, 255, 254, 255}, //1: 191 20 top right seg 21 {127, 191, 255, 239, 247, 255, 253, 254, 255}, //2: 255 is NO 22 segment 23 {127, 191, 223, 239, 255, 255, 253, 254, 255}, //3: 223 bottom right 24 seg 25 {255, 191, 223, 255, 255, 251, 253, 254, 255}, //4: 26 {127, 255, 223, 27 239, 255, 251, 253, 254, 255}, //5: 239 bottom seg 28 {127, 191, 223, 239, 247, 29 255, 253, 254, 255}, //6: 247 bottom left seg 30 {127, 191, 223, 255, 255, 255, 31 255, 254, 255}, //7: 32 /*Example for the number 7: 33 * 127: |_ON | 34 35 * 251:OFF ON:191 36 * 253: OFF | | 37 * 247:OFF ON:223 38 * 39 239: OFF |_| 40 */ 41 {127, 191, 223, 239, 247, 251, 253, 254, 255}, //8: 42 251 top left seg 43 {127, 191, 223, 239, 255, 251, 253, 254, 255}, //9: 253 center 44 seg 45 {255, 255, 255, 255, 255, 255, 255, 254, 255}, //DP: Decimal Point seg 46}; 47const 48 int arrHeight = 9; // (0-9) 9 displays digits 0-9. 49const int arrWidth = 6; // 50 (0-8) how many segments from each row to use. 7 will add the decimal row. 51 52void 53 setup() { 54 //Serial.begin(9600); //which port to output serial display data. 55 unused. slows display down. 56 pinMode(latchPin, OUTPUT); 57 pinMode(dataPin, 58 OUTPUT); 59 pinMode(clockPin, OUTPUT); 60} 61 62void loop() { 63 for (int 64 i = 0; i <= 3; i++) { //cycles through all PWM pins 65 for (int k = 0; k <= 66 arrHeight; k++) { //cycles through countTo number of digArray rows 67 analogWrite((pinArray[i]), 68 255); //turns PWM pin(i) on 69 for (int h = 0; h <= digLoop; h++) { //how 70 many times to cycle through columns 71 for (int j = 0; j <= arrWidth; j++) 72 { //cycles through all displayed column data 73 digitalWrite(latchPin, 74 HIGH); 75 shiftOut(dataPin, clockPin, MSBFIRST, digArray[k][j]); 76 digitalWrite(latchPin, 77 LOW); 78 delay(segSpeed); //delay until next segment displayed sequence 79 80 } 81 } 82 analogWrite((pinArray[i]), 0); //turns PWM pin(i) 83 off 84 delay(nextPin); //delay until next displayed digit sequence 85 } 86 87 } 88 delay(repeatSeq); //delay until everything is started over again 89}
Downloadable files
4 Digit 7 Segment + Shift Register
Schematic
4 Digit 7 Segment + Shift Register

Comments
Only logged in users can leave comments