![](/media/cache/profiles/4a7bbf6d58b20f2c21af46ce4b79598e.jpg.50x50_q85.jpg)
How to control an output pin...and how to find out what the compiler name for the pin is.
main.cpp
- Committer:
- captaintim
- Date:
- 2016-09-02
- Revision:
- 2:afd0cb53867f
- Parent:
- 1:0e26c8d5e834
File content as of revision 2:afd0cb53867f:
#include "mbed.h" /*comments: testing turning on and off of Pins for 7-segment diode using https://developer.mbed.org/users/synvox/notebook/lpc1768-pinout-with-labelled-mbed-pins/ by Nenad Milosevic verification: put the black lead of a multimeter on pin 1 (gnd) and put the red lead on pin 26, voltage varies between +3.28VDC and 0VDC */ /*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 the display pin # to XX mbed pin) CONTROL DISPLAY Pin# MBED Pin# ---------------------------------- Digit1 12 14 Digit2 9 13 Digit3 8 12 Digit4 6 11 DP 3 10 A 11 21 B 7 22 C 4 23 D 2 24 E 1 25 F 5 26 G 5 27 There is no blanking on this display, 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 Dept. Electrical Engineering and Technology Boston, MA */ DigitalOut myled1(LED1); //used as signal light to indicate where "thou art". DigitalOut myled2(LED2); DigitalOut myled3(LED3); DigitalOut myled4(LED4); int main() { int i = 1; //wait time interval //test of LED 7-segment diodes on 4 digit display 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); DigitalOut (p24, 1); DigitalOut (p25, 1); DigitalOut (p26, 1); 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); DigitalOut (p22, 1); DigitalOut (p23, 1); DigitalOut (p24, 1); DigitalOut (p25, 1); DigitalOut (p26, 1); 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); DigitalOut (p22, 1); DigitalOut (p23, 1); DigitalOut (p24, 1); DigitalOut (p25, 1); DigitalOut (p26, 1); 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); DigitalOut (p22, 1); DigitalOut (p23, 1); DigitalOut (p24, 1); DigitalOut (p25, 1); DigitalOut (p26, 1); 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); 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 DigitalOut (p13, 0); DigitalOut (p12, 0); DigitalOut (p11, 0); wait (i); DigitalOut (p14, 1); //Turn them all off DigitalOut (p13, 1); DigitalOut (p12, 1); DigitalOut (p11, 1); wait (1); DigitalOut (p14, 0); //Turn them all on as zeros DigitalOut (p13, 0); DigitalOut (p12, 0); DigitalOut (p11, 0); DigitalOut (p27, 0); wait (i); DigitalOut (p14, 1); //Turn them all off DigitalOut (p13, 1); DigitalOut (p12, 1); DigitalOut (p11, 1); wait (1); DigitalOut (p14, 0); //Turn them all on as sevens DigitalOut (p13, 0); DigitalOut (p12, 0); DigitalOut (p11, 0); DigitalOut (p24, 0); DigitalOut (p25, 0); DigitalOut (p26, 0); DigitalOut (p27, 0); wait (i); DigitalOut (p14, 1); //Turn them all off DigitalOut (p13, 1); DigitalOut (p12, 1); DigitalOut (p11, 1); wait (1); myled1=0; //end of program signal myled2=0; //end of program signal myled3=0; //end of program signal myled4=0; //end of program signal } }