A few classes to interface one or more ShiftBrite module to the FRDM KL25Z.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
JoKer
Date:
Thu Aug 21 04:04:49 2014 +0000
Parent:
4:d2f8ddb423e2
Child:
6:75801b7a36a3
Commit message:
Improved shift method functions for shiftBrightDisplay class. Allows shifting in a colour.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
sbDriver.cpp Show annotated file Show diff for this revision Revisions of this file
sbDriver.h Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed Aug 20 09:26:42 2014 +0000
+++ b/main.cpp	Thu Aug 21 04:04:49 2014 +0000
@@ -1,7 +1,7 @@
 #include "mbed.h"
 #include "sbDriver.h"
 #include "movie.h"
-
+# define M_PI           3.14159265358979323846
 
 /* VARIOUS EXAMPLES OF HOW TO USE the shiftBriteDisplay class and the movie class follows below.
 Please note, this is all 'beerware' code but I would appreciate a mention in your code headers
@@ -14,19 +14,20 @@
 //6 leds example. Format it suitably for easy reading
 unsigned short int aMovie[] = {
     /* LED1      LED2      LED3      LED4      LED5      LED6 */
-    1023,0,0,    0,0,0,    0,0,0,    0,0,0,    0,0,0,    0,0,0, /*Frame 0*/
-       0,0,0, 1023,0,0,    0,0,0,    0,0,0,    0,0,0,    0,0,0, /*Frame 1*/
-       0,0,0,    0,0,0,    1023,0,0, 0,0,0,    0,0,0,    0,0,0, /*Frame 2*/
-       0,0,0,    0,0,0,    0,0,0,    1023,0,0, 0,0,0,    0,0,0, /*Frame 3*/
-       0,0,0,    0,0,0,    0,0,0,    0,0,0,    1023,0,0, 0,0,0, /*Frame 4*/
+    10,0,0,    0,0,0,    0,0,0,    0,0,0,    0,0,0,    0,0,0, /*Frame 0*/
+       0,0,0, 100,0,0,    0,0,0,    0,0,0,    0,0,0,    0,0,0, /*Frame 1*/
+       0,0,0,    0,0,0,    500,0,0, 0,0,0,    0,0,0,    0,0,0, /*Frame 2*/
+       0,0,0,    0,0,0,    0,0,0,    750,0,0, 0,0,0,    0,0,0, /*Frame 3*/
+       0,0,0,    0,0,0,    0,0,0,    0,0,0,    900,0,0, 0,0,0, /*Frame 4*/
        0,0,0,    0,0,0,    0,0,0,    0,0,0,    0,0,0,    1023,0,0, /*Frame 5*/
-       0,0,0,    0,0,0,    0,0,0,    0,0,0,    1023,0,0, 0,0,0, /*Frame 6*/
-       0,0,0,    0,0,0,    0,0,0,    1023,0,0, 0,0,0,    0,0,0, /*Frame 7*/
-       0,0,0,    0,0,0,    1023,0,0, 0,0,0,    0,0,0,    0,0,0, /*Frame 8*/
-       0,0,0, 1023,0,0,    0,0,0,    0,0,0,    0,0,0,    0,0,0  /*Frame 9*/
+       0,0,0,    0,0,0,    0,0,0,    0,0,0,    900,0,0, 0,0,0, /*Frame 6*/
+       0,0,0,    0,0,0,    0,0,0,    750,0,0, 0,0,0,    0,0,0, /*Frame 7*/
+       0,0,0,    0,0,0,    500,0,0, 0,0,0,    0,0,0,    0,0,0, /*Frame 8*/
+       0,0,0, 100,0,0,    0,0,0,    0,0,0,    0,0,0,    0,0,0  /*Frame 9*/
    /*A simple 'cylon' scanner 'movie'*/    
 };
 
+
 Serial PC(PTA2, PTA1);//So I can use Serial as output to terminal and input
 
 //================== HARDWARE CONNECTIONS =========================================
@@ -40,6 +41,7 @@
 //=================== END OF HARDWARE CONNECTIONS =================================
 
 int main() {
+  
     
 //Instanciate a ticker object to handle framerate updates for the SB display    
 Ticker t;
@@ -47,6 +49,9 @@
 //Instanciate a string of 5 sb modules and tell the driver object where the control/data pins are
 shiftBriteDisplay sbDisplay(latch, enable, reset, spi,6);
 
+
+/*
+
 //Example calls to method f() of shiftBriteDisplay class
 //in this case, 6 of these statements wold be required to build one frame
 //HOW TO BUILD A FRAME IF YOU ARE NOT USING THE MOVIE CLASS
@@ -121,18 +126,33 @@
 //or t.attach(&sbDisplay,&shiftBriteDisplay::displayFrame,0.5);// or only every 0.5s for testing
    
     
-/*
-EXPANDING THE FUNCTIONALITY OF shiftBriteDisplay class; USING THE MOVIE CLASS
-I know, i know, 'MOVIE' is a HUGE stretch but it sounds good right?!?!   :) 
-*/
+//
+//EXPANDING THE FUNCTIONALITY OF shiftBriteDisplay class; USING THE MOVIE CLASS
+//I know, i know, 'MOVIE' is a HUGE stretch but it sounds good right?!?!   :) 
+//
 //Note, it uses the previously declared sbDisplay object. It is passed as a reference.
     movie myMovie(aMovie,sbDisplay,sizeof(aMovie));
     myMovie.setRepeat(1);
+
     t.attach(&myMovie,&movie::play,0.05);//Beware, if you go too fast here the FRDM will crash
-
+*/
 
-
+double p;
+unsigned int j;
+    for (j=0; j != sbDisplay.getModuleCount(); j++){
+        sbDisplay.setLed(j,0,0,0);//set all led to black
+    }
+    sbDisplay.displayFrame();//get it on the leds
+    sbDisplay.setCurrentCorr(0,0,0);//Dim down to 30%
    while(1){ // Nothing going on in the main loop as Ticker calls the appropriate member function
+//Test modified shiftRight - simple colour chaser
+        for(p=0; p <= (2.0*M_PI); p+=M_PI/((double)sbDisplay.getModuleCount()*2.0)){
+            //cycle through 0-pi
+            //sbDisplay.shiftRight((unsigned short int)(5000.0*(1+sin(p+0))),(unsigned short int)(5000.0*(1+sin(p+(2.0*M_PI)/3.0))),(unsigned short int)(5000.0*(1+sin(p+2.0*((2.0*M_PI)/3.0)))));
+            sbDisplay.shiftRight((unsigned short int)(500.0*(1+sin(p))),(unsigned short int)(500.0*(1+sin(p+(120.0*(M_PI/180.0))))),(unsigned short int)(500.0*(1+sin(p+(240.0*(M_PI/180.0))))));
+            sbDisplay.displayFrame();
+            wait(1.0/((double)sbDisplay.getModuleCount()/2.0));
+        }
     }
 }
 
--- a/sbDriver.cpp	Wed Aug 20 09:26:42 2014 +0000
+++ b/sbDriver.cpp	Thu Aug 21 04:04:49 2014 +0000
@@ -266,12 +266,15 @@
         setLed(moduleCount-1,temp.getRed(),temp.getGreen(),temp.getBlue());   
 }
 
-void shiftBriteDisplay::shiftLeft(){;//info shifted out is lost, 
+void shiftBriteDisplay::shiftLeft(unsigned short int inR,unsigned short int inG,unsigned short int inB){;//info shifted out is lost, 
     unsigned int i;
         for(i=0; i != moduleCount-1; i++){
             setLed(i,module_p[i+1].getRed(),module_p[i+1].getGreen(),module_p[i+1].getBlue());
         }
-        setLed(moduleCount-1,0,0,0);   
+        if(inR==0 && inG==0 && inB==0)
+        setLed(moduleCount-1,0,0,0);
+        else
+        setLed(moduleCount-1,inR,inG,inB);        
 }
 
 void shiftBriteDisplay::rotateRight(){;
@@ -283,12 +286,15 @@
         }
         setLed(0,temp.getRed(),temp.getGreen(),temp.getBlue());   
 }
-void shiftBriteDisplay::shiftRight(){;//info shifted out is lost
+void shiftBriteDisplay::shiftRight(unsigned short int inR,unsigned short int inG,unsigned short int inB){;//info shifted out is lost
     unsigned int i;
         for(i=moduleCount; i != 0; i--){
             setLed(i-1,module_p[i-2].getRed(),module_p[i-2].getGreen(),module_p[i-2].getBlue());
         }
-        setLed(0,0,0,0);   
+        if(inR==0 && inG==0 && inB==0)
+        setLed(0,0,0,0);
+        else
+        setLed(0,inR,inG,inB);   
 }
 void shiftBriteDisplay::turnOn(){;
     priv_SBEnable();
--- a/sbDriver.h	Wed Aug 20 09:26:42 2014 +0000
+++ b/sbDriver.h	Thu Aug 21 04:04:49 2014 +0000
@@ -218,16 +218,16 @@
     
 /**shiftLeft()
 * is used to shift the whole display colours one step left.
-* A blank dot is shifted in.
+* A blank dot is shifted in unless a colour is given in the argument.
 * @code
 for(loop=0; loop !=NumOfLeds; loop++){
-    sbDisplay.shiftLeft();
+    sbDisplay.shiftLeft();//or, to shift in a colour .shiftLeft(1000,200,0);
     sbDisplay.displayFrame();
     wait(0.2);
 }
 * @endcode
 */
-    void shiftLeft();//info shifted out is lost
+    void shiftLeft(unsigned short int inR=0,unsigned short int inG=0,unsigned short int inB=0);//info shifted out is lost
 
 /**rotateRight()
 * is used to shift the whole display colours one step right.
@@ -245,16 +245,16 @@
 
 /**shiftRight()
 * is used to shift the whole display colours one step right.
-* A blank dot is shifted in.
+* A blank dot is shifted in unless a colour is given as an argument.
 * @code
 for(loop=0; loop !=NumOfLeds; loop++){
-    sbDisplay.shiftRight();
+    sbDisplay.shiftRight(); // or, to feed in a colour sbDisplay.shiftRight(0,0XF0,0x30);
     sbDisplay.displayFrame();
     wait(0.2);
 }
 * @endcode
 */
-    void shiftRight();//info shifted out is lost
+    void shiftRight(unsigned short int inR=0,unsigned short int inG=0,unsigned short int inB=0);//info shifted out is lost
     
 /**Display output is turned enabled.
 */