Johan Kritzinger
/
FRDMKL25Z-ShiftBrite
A few classes to interface one or more ShiftBrite module to the FRDM KL25Z.
Revision 6:75801b7a36a3, committed 2014-08-21
- Comitter:
- JoKer
- Date:
- Thu Aug 21 05:39:33 2014 +0000
- Parent:
- 5:aa0424f31fa1
- Child:
- 7:a0f62fc80de0
- Commit message:
- Improved main routine for demonstrating generating an special effect.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Aug 21 04:04:49 2014 +0000 +++ b/main.cpp Thu Aug 21 05:39:33 2014 +0000 @@ -2,6 +2,8 @@ #include "sbDriver.h" #include "movie.h" # define M_PI 3.14159265358979323846 +#define FACTOR 1.0 +#define USI unsigned short int /* 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 @@ -50,7 +52,7 @@ shiftBriteDisplay sbDisplay(latch, enable, reset, spi,6); -/* +/* MAIN PROGRAM ONE to display various features including movie class //Example calls to method f() of shiftBriteDisplay class //in this case, 6 of these statements wold be required to build one frame @@ -135,24 +137,59 @@ myMovie.setRepeat(1); t.attach(&myMovie,&movie::play,0.05);//Beware, if you go too fast here the FRDM will crash + while(1){;} //nothing in main loop as Ticker calls the relevan member function */ -double p; + +//MAIN PROGRAM TWO - to show some special effects WITHOUT using the movie class +//Play around by adjusting phases, frequencies etc. Each will give different results +//Below is an example using 3 sin waves, one for each colour, but 120 deg out of phase +//and slowly scanning frequencies from 0.5 to 5 and back again. Each freq is active for 5 seconds. + 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 + +double tim,max_t; // 'real' time and time limit for a simulation +double w1,w2,w3; // 2*pi*f +double phase1,phase2,phase3;//Phase offset +double f1,f2,f3;//Frequencies +double factor = 250;//250 steps or values over max_t time + +unsigned char f_dir = 1; //used for up and down functionality + +f1 = f2 = f3 = 1.0; //frequency in herz - set all to the same +//but make a 120 degree pahse shift between the 3 waves +phase1 = 0.0; +phase2 = 120.0*(M_PI/180.0); +phase3 = 240.0*(M_PI/180.0); + +max_t=5.0; //i.e. time to iterate over - i.e. 5 second + + while(1){ // generate special effects without using a movie and discretely calc values + for(tim=0; tim <= max_t; tim+=max_t/factor) { //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.shiftRight((USI)511.0*(1.0+sin(w1*tim+phase1)), + (USI)511.0*(1.0+sin(w2*tim+phase2)), + (USI)511.0*(1.0+sin(w3*tim+phase3)) + ); sbDisplay.displayFrame(); - wait(1.0/((double)sbDisplay.getModuleCount()/2.0)); + wait( (max_t/factor)); } + w1 = 2.0*M_PI*f1; + w2 = 2.0*M_PI*f2; + w3 = 2.0*M_PI*f3; + if(f_dir){ + f1 = f2 = f3 = f3+0.5; + if (f1>=5.0)f_dir = 0; + } else { + f1 = f2 = f3 = f3-0.5; + if (f1<=0.5) f_dir = 1; + } + } }