Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 5:aa0424f31fa1
- Parent:
- 4:d2f8ddb423e2
- Child:
- 6:75801b7a36a3
diff -r d2f8ddb423e2 -r aa0424f31fa1 main.cpp
--- 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));
+ }
}
}