just a small code example to display numbers on a 7 segment display should be easy to rewrite for your own needs.

Dependencies:   mbed

Fork of 7SegmentDisplay by Svend Kaffke

Committer:
captaintim
Date:
Sat Sep 03 17:31:45 2016 +0000
Revision:
1:8a3c7884316e
Parent:
0:463ff11d33fa
Wrote correction to matrix so it works with pinouts of LDQ-N514R1, a 4 digit, 7-segment display (common cathode)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ShingyoujiPai 0:463ff11d33fa 1 #include "mbed.h"
ShingyoujiPai 0:463ff11d33fa 2
captaintim 1:8a3c7884316e 3 /*test program to learn how to write code for a 4 digit, 7-segment LED display LDQ-N524R1
captaintim 1:8a3c7884316e 4 The schematic for this (COMMON CATHODE) display shows the following connections
captaintim 1:8a3c7884316e 5 schematic located at http://www.lumex.com/ldq-n514ri (open Specs PDF for drawing)
captaintim 1:8a3c7884316e 6 The Common Cathode means that to turn on the segments of the 7-segment (including decimal point)
captaintim 1:8a3c7884316e 7 you write a one to that segment.
captaintim 1:8a3c7884316e 8 For this 4 digit display (LDQ-N524R1), each digit works backward--like its wired Common Anode so
captaintim 1:8a3c7884316e 9 You write a ZERO to turn on the selected digit AND a ONE to turn off the digit.
captaintim 1:8a3c7884316e 10
captaintim 1:8a3c7884316e 11 Pin Out wiring guide:(connect the display pin # to XX mbed pin)
ShingyoujiPai 0:463ff11d33fa 12
captaintim 1:8a3c7884316e 13 CONTROL DISPLAY Pin# MBED Pin#
captaintim 1:8a3c7884316e 14 ----------------------------------
captaintim 1:8a3c7884316e 15 Digit1 12 14
captaintim 1:8a3c7884316e 16 Digit2 9 13
captaintim 1:8a3c7884316e 17 Digit3 8 12
captaintim 1:8a3c7884316e 18 Digit4 6 11
captaintim 1:8a3c7884316e 19 DP 3 10
captaintim 1:8a3c7884316e 20 A 11 21
captaintim 1:8a3c7884316e 21 B 7 22
captaintim 1:8a3c7884316e 22 C 4 23
captaintim 1:8a3c7884316e 23 D 2 24
captaintim 1:8a3c7884316e 24 E 1 25
captaintim 1:8a3c7884316e 25 F 5 26
captaintim 1:8a3c7884316e 26 G 5 27
captaintim 1:8a3c7884316e 27
captaintim 1:8a3c7884316e 28 There is no blanking on this display,
ShingyoujiPai 0:463ff11d33fa 29
captaintim 1:8a3c7884316e 30 Program demonstrates writing to one 7-segment display of 4 digit display LDQ-N514R1
captaintim 1:8a3c7884316e 31 Author: Cap'n Tim Johnson PE
captaintim 1:8a3c7884316e 32 Retired Professor
captaintim 1:8a3c7884316e 33 Wentworth Institude of Technology
captaintim 1:8a3c7884316e 34 Dept. Electrical Engineering and Technology
captaintim 1:8a3c7884316e 35 Boston, MA
captaintim 1:8a3c7884316e 36 */
captaintim 1:8a3c7884316e 37
captaintim 1:8a3c7884316e 38 //Setup:
captaintim 1:8a3c7884316e 39 DigitalOut Digit1(p14); //construct to control digits
captaintim 1:8a3c7884316e 40 DigitalOut Digit2(p13);
captaintim 1:8a3c7884316e 41 DigitalOut Digit3(p12);
captaintim 1:8a3c7884316e 42 DigitalOut Digit4(p11);
captaintim 1:8a3c7884316e 43
captaintim 1:8a3c7884316e 44 //these are the pins associated with writing to the "led"
captaintim 1:8a3c7884316e 45 DigitalOut led[8]={p21, p22, p23, p24, p25, p26, p27, p10};
captaintim 1:8a3c7884316e 46
captaintim 1:8a3c7884316e 47 //segments are in alphabetical order a-g, followed by Decimal point in the array below
captaintim 1:8a3c7884316e 48
captaintim 1:8a3c7884316e 49 int matrix[11][8]={
captaintim 1:8a3c7884316e 50 {1,1,1,1,1,1,0,0}, //zero
captaintim 1:8a3c7884316e 51 {0,1,1,0,0,0,0,0}, //one
captaintim 1:8a3c7884316e 52 {1,1,0,1,1,0,1,0}, //two
captaintim 1:8a3c7884316e 53 {1,1,1,1,0,0,1,0}, //three
captaintim 1:8a3c7884316e 54 {0,1,1,0,0,1,1,0}, //four
captaintim 1:8a3c7884316e 55 {1,0,1,1,0,1,1,0}, //five
captaintim 1:8a3c7884316e 56 {1,0,1,1,1,1,1,0}, //six
captaintim 1:8a3c7884316e 57 {1,1,1,0,0,0,0,0}, //seven
ShingyoujiPai 0:463ff11d33fa 58 {1,1,1,1,1,1,1,0}, //eight
captaintim 1:8a3c7884316e 59 {1,1,1,0,0,1,1,0}, //nine
ShingyoujiPai 0:463ff11d33fa 60 {0,0,0,0,0,0,0,1} //dot
ShingyoujiPai 0:463ff11d33fa 61 };
ShingyoujiPai 0:463ff11d33fa 62
ShingyoujiPai 0:463ff11d33fa 63
ShingyoujiPai 0:463ff11d33fa 64 int main() {
captaintim 1:8a3c7884316e 65 Digit1 = 1; //turn all digit1 in case they've been turned on...in another program
captaintim 1:8a3c7884316e 66 Digit2 = 1; //turn off digit2
captaintim 1:8a3c7884316e 67 Digit3 = 1; //turn off digit3
captaintim 1:8a3c7884316e 68 Digit4 = 1; //turn off digit4
captaintim 1:8a3c7884316e 69
captaintim 1:8a3c7884316e 70 Digit1 = 0; //Turn on digit#1, Most Significant Digit
ShingyoujiPai 0:463ff11d33fa 71 while (1) {
ShingyoujiPai 0:463ff11d33fa 72 //all led's off
ShingyoujiPai 0:463ff11d33fa 73 for(int i = 0; i<8;i++){led[i] = 0;}
ShingyoujiPai 0:463ff11d33fa 74
ShingyoujiPai 0:463ff11d33fa 75 //display shows the number in this case 6
captaintim 1:8a3c7884316e 76 for (int i=0; i<8; i++){led[i] = matrix[6][i];} //holds row of "number" and assign column value from matrix
captaintim 1:8a3c7884316e 77 wait(0.5);
ShingyoujiPai 0:463ff11d33fa 78
ShingyoujiPai 0:463ff11d33fa 79 }
captaintim 1:8a3c7884316e 80 }