How to control an output pin...and how to find out what the compiler name for the pin is.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
captaintim
Date:
Sat Sep 03 02:04:38 2016 +0000
Parent:
1:0e26c8d5e834
Commit message:
Basic commands and instructions for exploring BusOut command for 4 digit, 7segment LED Display

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Aug 16 20:25:31 2016 +0000
+++ b/main.cpp	Sat Sep 03 02:04:38 2016 +0000
@@ -1,16 +1,12 @@
-#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 these mbed pins to display)
+Pin Out wiring guide:(connect the display pin # to XX mbed pin)
 
 CONTROL   DISPLAY Pin#  MBED Pin#
 ----------------------------------
@@ -28,8 +24,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 BusOut 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,110 +33,68 @@
 Boston, MA
 */
 
+#include "mbed.h"
 
-DigitalOut myled(LED1);  //used to signal where in the program "thou art".
+BusOut myleds(LED1, LED2, LED3, LED4);  //adding a common cathode bus to contrast with Digits bus
+//LED1 is next to pin 20
+BusOut Segments(p21,p22,p23,p24,p25,p26,p27,p10);  //8-bit bus MSB is pin 21--the "a" segment
+BusOut Digits(p14, p13, p12, p11);  //4 bit digit control bus with digit 1 (pin 14) on left then in decreasing order
+//But to turn on MSD, write a zero to bit 0 of the bus...0x1110 or 14 decimal 
+//the bit order is reversed from the written order for Digits bus as with the Segment bus
 
+//writing decimal to Digits bus:
+//binary 1111, decimal 15 turns off the digits 
+//binary 1110, decimal 14 turns on digit 1 (MSD)
+//binary 1101, decimal 13 turns on digit 2 (2nd from left)
+//binary 1100, decimal 12 turns on the 2 MSD
+//binary 1011, decimal 11 turns on digit 3  (3rd from left)
+//binary 0111, decimal 7  turns on digit 4 (LSD)
+
+int i = 1;  //used to set wait time
 int main() {
-//int on = 1;
-//int off = 0;
-int i = 2;  //wait time interval
-  
-//test of LED 7-segment diodes on 4 digit display
-//while(1){
- DigitalOut (p14, 0); //Turn on digit1, 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);
- 
- 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);
- 
- 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);
+  //  while (1){  //used to turn off loop  
+
+            wait (i);
+            myleds = 15;     //turns on all the signal LEDs 
+            Segments = 255; //decimal #255 write ones to every bit in Segment bus--turn on all 7-segments + DP
+            Digits = 0;    //turn on all digits (digit wired common anode--opposite of segments bus
+            wait (i);
+            myleds = 0;     //turning of the signal LEDs
+            Digits = 15;   //turn off the digits
+            wait (i);
+            myleds = 1;     //turns on LED1 
+            Digits = 14;    //turn on just one digit, MSD, left-most digit
+            wait (i);
+            myleds = 3;     //turning on 2 signal LEDs
+            Digits = 12;    //turn on two digits
+            wait (i);
+            myleds = 7;     //turning on 3 signal LEDs
+            Digits = 8;     //turn on 3 digits
+            wait (i);
+            myleds = 15;    //turning on all for digits
+            Digits = 0;    //turn on 4 digits
+            wait (i);
+            myleds = 0;    //turning off all for signal LEDs and ending this comparison of REVERSE LOGIC
+            Digits = 15;   //turn off all 4 digits
+            wait (i);   
+            Segments = (7); //turn on the number 7 for all four
+            Digits = 0;     //turn on all 4 digits
+            wait (i);
+            Digits =15;     //turn off all 4 digits
+            wait (i);
+            Segments = (63);  //turn them on as zeros
+            Digits =0;        //turn on the 4 digits
+            wait (i);  
+            Digits = 15;     //turn off the 4 digits
+            Segments=0;      //turn off the segments
+            wait (i);        //wait with everything dead
+            Segments = 128;  //Turn on the decimal points 
+            Digits = 0;      //turn on the digits
+            wait (i);
+            Digits = 0;
  
- 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);
- DigitalOut (p11, 1); //Turn off digit4
- //they are all off
- wait (1);
-
- myled=1;   //Signals all are about to turn on
- wait (1);
+//        }  //remove leading slashes to enable looping
+ //  */ 
+}
 
- 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);
- 
- myled=0;      //end of program signal
- 
-}   
\ No newline at end of file
+  
\ No newline at end of file