updated 7seg controls for new 7 seg boards

Dependencies:   PixelArray WS2812 mbed

Fork of frdm_pong_table_controller by Demo Team

Files at this revision

API Documentation at this revision

Comitter:
DanGibbons
Date:
Tue Jul 11 08:51:23 2017 +0000
Parent:
7:dc6f1f105c52
Child:
9:f3f194982bb3
Commit message:
Buttons debounced; Idle state reanimated (180 degreesa out of phase)

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Jul 10 16:06:14 2017 +0000
+++ b/main.cpp	Tue Jul 11 08:51:23 2017 +0000
@@ -21,8 +21,6 @@
             }
             
             CircleAnimation(true,true,true,true,1);
-            
-            idleButton.enable_irq();
 
             wait(0.02);
             
@@ -37,8 +35,6 @@
                 idle_button_pressed = 0;
                 
                 IdleToPlayTransition();
-                
-                idleButton.enable_irq();
 
             }
             
@@ -75,12 +71,12 @@
     // Turn on green LED
     led_green = 0;
     
+    // enable the internal pull-down resistor on idleButton
+    idleButton.mode(PullDown);
+    
     // attach idle button isr to rising edge of button press
     idleButton.rise(&idleButtonISR);
 
-    // enable the internal pull-down resistor on idleButton
-    idleButton.mode(PullDown);
-
     // Set brightness of the 4 LED strips
     robotScoreLED.setII(0xB0);
     robotScoreLED.useII(WS2812::GLOBAL);
@@ -106,27 +102,37 @@
     
     memset(mainArray, 0, sizeof mainArray);
     
-    for (int i = 0; i < 104; i++) {
+    for (int i = 9; i < 115; i++) { // loop to set LEDs around the circle from start of segment A to end of Segment F
 
-        mainArray[0][i] = 1;
+        if (i < 104) {
+            mainArray[0][i] = 1;
+        }
+        if (i > 103) {
+            mainArray[0][i-104] = 1;
+        }
+        if (i < 19) {
+            mainArray[1][18-i] = 1;
+        }
+        if (i > 18) {
+            mainArray[1][122-i] = 1;
+        }
 
         wait_ms(10);
 
-        WritePxAnimation(playerScore,false,true);
+        WritePxAnimation(0,false,true);
         playerScoreLED.write(playerScorePx.getBuf());
-        
-        WritePxAnimation(robotScore,true,true);
+        WritePxAnimation(1,true,true);
         robotScoreLED.write(robotScorePx.getBuf());
-    
+
     }
     
-    SetNumberPatterns();
-    
     DrainAnimation(true,true,robotScore,true,true,playerScore);
     
     wait(1);
     
-    WriteAnimation();
+    WriteScores();
+    
+    idleButton.enable_irq();
     
 }
 
@@ -136,6 +142,10 @@
     playerScore = 0;
     memset(mainArray, 0, sizeof mainArray);
     
+    wait(1);
+    
+    idleButton.enable_irq();
+    
 }
 
 
@@ -333,8 +343,9 @@
 }
 
 // Update both Score LEDs with the current score
-void WriteAnimation()
+void WriteScores()
 {
+    SetNumberPatterns();
     WritePxAnimation(playerScore,false,false);
     playerScoreLED.write(playerScorePx.getBuf());
     wait(0.01);
@@ -567,17 +578,37 @@
 
         for (int i = 9; i < 115; i++) { // loop to set LEDs around the circle from start of segment A to end of Segment F
             
-            if ( i < 104) {
+            if (i < 104) {
                 mainArray[0][i] = 1;
-                for (int j = 0; j < i-10; j++) { // Loop to clear previously set LEDs so that the chain that animates round the display is 9 LEDs long
+                for (int j = 0; j < i-10; j++) { // Loop to clear previously set LEDs so that the chain that animates round the display is 10 LEDs long
+                    mainArray[0][j] = 0;
+                }
+            }
+            if (i > 103) {
+                mainArray[0][i-104] = 1;
+                for (int j = 90; j < i-10; j++) { // Loop to clear previously set LEDs so that the chain that animates round the display is 10 LEDs long
                     mainArray[0][j] = 0;
                 }
             }
-            
-            if (i > 103) {
-                mainArray[0][i-104] = 1;
-                for (int j = 90; j < i-10; j++) { // Loop to clear previously set LEDs so that the chain that animates round the display is 9 LEDs long
-                    mainArray[0][j] = 0;
+            if (i < 19) {
+                mainArray[1][18-i] = 1;
+                for (int j = 17; j > 25-i; j--) { // Loop to clear previously set LEDs so that the chain that animates round the display is 10 LEDs long
+                    mainArray[1][j] = 0;
+                }
+            }
+            if (i > 18) {
+                
+                mainArray[1][122-i] = 1;
+                
+                if (i < 29) {
+                    for (int j = 9; j > 27-i; j--) { // Loop to clear previously set LEDs so that the chain that animates round the display is 10 LEDs long
+                        mainArray[1][j] = 0;
+                    }
+                }
+                if (i > 28) {
+                    for (int j = 103; j > 131-i; j--) { // Loop to clear previously set LEDs so that the chain that animates round the display is 10 LEDs long
+                        mainArray[1][j] = 0;
+                    }                        
                 }
             }
             
@@ -588,20 +619,21 @@
                 playerScoreLED.write(playerScorePx.getBuf());
             }
             if (robot == true) {
-                WritePxAnimation(0,true,robotColour);
+                WritePxAnimation(1,true,robotColour);
                 robotScoreLED.write(robotScorePx.getBuf());
             }
+            
         }
-
+        
     }
     
 }  
 
-
-
 // animation that drains the display from the top segment A to the bottom segment D
 void DrainAnimation(bool robot, bool robotColour, int robotScore, bool player, bool playerColour, int playerScore)
 {
+    SetNumberPatterns();
+    
     for (int i = 0; i < 10; i++) { // A
         mainArray[robotScore][9+i] = 0;
         mainArray[robotScore][9-i] = 0;
@@ -693,7 +725,7 @@
     }
     
 
-    SetNumberPatterns();
+    memset(mainArray, 0, sizeof mainArray);
 
 } 
 
--- a/main.h	Mon Jul 10 16:06:14 2017 +0000
+++ b/main.h	Tue Jul 11 08:51:23 2017 +0000
@@ -71,7 +71,7 @@
 void Setup(); // initial pattern
 void SetNumberPatterns(); // sets segment patterns for numbers
 void SetLEDArray(int x); // sets segment patterns in mainArray
-void WriteAnimation(); // writes scores to the LEDs
+void WriteScores(); // writes scores to the LEDs
 void WritePxAnimation(int line_num,bool isRobot,bool colour); // writes mainArray to either LED buffer in blue or random colours
 
 void HandleGoal(bool hasRobotScored);