Tim Johnson
/
Controlling_GPIO_pinouts
How to control an output pin...and how to find out what the compiler name for the pin is.
Diff: main.cpp
- Revision:
- 2:afd0cb53867f
- Parent:
- 1:0e26c8d5e834
diff -r 0e26c8d5e834 -r afd0cb53867f main.cpp --- a/main.cpp Tue Aug 16 20:25:31 2016 +0000 +++ b/main.cpp Fri Sep 02 19:45:41 2016 +0000 @@ -9,8 +9,12 @@ /*test program to learn how to write code for a 4 digit, 7-segment LED display LDQ-N524R1 The schematic for this (COMMON CATHODE) display shows the following connections schematic located at http://www.lumex.com/ldq-n514ri (open Specs PDF for drawing) +The Common Cathode means that to turn on the segments of the 7-segment (including decimal point) +you write a one to that segment. +For this 4 digit display (LDQ-N524R1), each digit works backward--like its wired Common Anode so +You write a ZERO to turn on the selected digit AND a ONE to turn off the digit. -Pin Out wiring guide:(connect these mbed pins to display) +Pin Out wiring guide:(connect the display pin # to XX mbed pin) CONTROL DISPLAY Pin# MBED Pin# ---------------------------------- @@ -28,8 +32,8 @@ G 5 27 There is no blanking on this display, -you have to write a ONE to Gnd pin for specific digit to turn it off -Program demonstrates use of DigitalOut to control segments of 7 segment display for 4 digit display LDQ-N514R1 + +Program demonstrates use of DigitalOut to control segments of 7-segment display for 4 digit display LDQ-N514R1 Author: Cap'n Tim Johnson PE Retired Professor Wentworth Institude of Technology @@ -37,17 +41,19 @@ Boston, MA */ - -DigitalOut myled(LED1); //used to signal where in the program "thou art". +DigitalOut myled1(LED1); //used as signal light to indicate where "thou art". +DigitalOut myled2(LED2); +DigitalOut myled3(LED3); +DigitalOut myled4(LED4); int main() { -//int on = 1; -//int off = 0; -int i = 2; //wait time interval + +int i = 1; //wait time interval //test of LED 7-segment diodes on 4 digit display -//while(1){ - DigitalOut (p14, 0); //Turn on digit1, Most Significant Digit +while(1){ + myled1 = 1; //turns on signal light for digit 1 + DigitalOut (p14, 0); //Turn on digit#1, Most Significant Digit DigitalOut (p21, 1); DigitalOut (p22, 1); DigitalOut (p23, 1); @@ -57,7 +63,9 @@ DigitalOut (p27, 1); DigitalOut (p10, 1); //decimal point wait (i); + myled1=0; //turns off signal light for digit 1 + myled2=1; DigitalOut (p14, 1); //turn off digit1 DigitalOut (p13, 0); //turn on digit2 DigitalOut (p21, 1); @@ -69,7 +77,9 @@ DigitalOut (p27, 1); DigitalOut (p10, 1); //decimal point wait (i); + myled2=0; //turns off signal light for digit 2 + myled3=1; DigitalOut (p13, 1); //turn off digit2 DigitalOut (p12, 0); //turn on digit3 DigitalOut (p21, 1); @@ -81,7 +91,9 @@ DigitalOut (p27, 1); DigitalOut (p10, 1); //decimal point wait (i); + myled3=0; //turns off signal light for digit 3 + myled4=1; DigitalOut (p12, 1); //turn off digit3 DigitalOut (p11, 0); //turn on digit4, Least Significant Digit DigitalOut (p21, 1); @@ -93,11 +105,16 @@ DigitalOut (p27, 1); DigitalOut (p10, 1); //decimal point wait (i); + myled4=0; //turns off signal light for digit 4 DigitalOut (p11, 1); //Turn off digit4 + //they are all off wait (1); - myled=1; //Signals all are about to turn on + myled1=1; //Signal all are about to turn on + myled2=1; + myled3=1; + myled4=1; //Signals all are about to turn on wait (1); DigitalOut (p14, 0); //Turn them all on @@ -141,6 +158,9 @@ DigitalOut (p11, 1); wait (1); - myled=0; //end of program signal - -} \ No newline at end of file + myled1=0; //end of program signal + myled2=0; //end of program signal + myled3=0; //end of program signal + myled4=0; //end of program signal + } +}