Introduces arrays by using a lookup table to control a 7-segment display.

Files at this revision

API Documentation at this revision

Comitter:
CSTritt
Date:
Sat Oct 02 21:26:37 2021 +0000
Parent:
109:e6bd85443eee
Commit message:
Updated to 2017 program updated to Mbed v5.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed Sep 22 13:19:31 2021 +0000
+++ b/main.cpp	Sat Oct 02 21:26:37 2021 +0000
@@ -1,31 +1,27 @@
 /*
-    Project: BinaryCount
+    Project: 21_7SegLU_v5
     File: main.cpp
+
+    Counts through the digits 0 to 9 then DP on the 7-segment display.
     
-    Displays 8 bit binary count on bar graph display.
-    
+    See external documentation for pin connections (very important).
+
     Written by: Dr. C. S. Tritt
-    Created: 9/20/21 (v. 1.2)
+    Created: 10/2/21 (v. 1.2)
 */
 #include "mbed.h"
 
-BusOut barGraph(D2, D3, D4, D5, D6, D7, D8, D9);  // Create BusOut object.
+BusOut ssDisplay(D3, D4, D5, D6, D7, D8, D9, D10); // Segments, LSB to MSB.
 
 int main() {
-    // Test the wiring.
-    barGraph = 0;  // All bars off (base 10).
-    ThisThread::sleep_for(400); // For 0.4 seconds.
-    barGraph = 0b01010101;  // Odd bars on (binary).
-    ThisThread::sleep_for(400); // Test even bars for 0.4 seconds. 
-    barGraph = 0b10101010;  // Even bars on (binary).   
-    ThisThread::sleep_for(400); // Test even bars for 0.4 seconds.
-    barGraph = 0xFF;  // All bars on. Hex.
-    ThisThread::sleep_for(400); // For 0.4 seconds.
-    // Enter main loop.   
-    while(true) {
-        for (int i = 0; i < 256; i++) { // Add one to count.
-            barGraph = i;  // Copy the count to the bargraph.
-            ThisThread::sleep_for(100);  // Display the value for 0.1 seconds.
+    // Declare and initialize array in one step.
+    const int Segments[] 
+        {0x81, 0xCF, 0x92, 0x86, 0xCC, 0xA4, 0xA0, 0x8F, 0x80, 0x84, 0x7F};
+
+    while(true) { // Loop forever.
+        for (int i = 0; i <= 10; i++) { // Cycle through digits.
+            ssDisplay = Segments[i]; // Display current digit.
+            ThisThread::sleep_for(1000); // Wait a second, then repeat.
         }
     }
 }
\ No newline at end of file