Johan Kritzinger / Mbed 2 deprecated FRDMKL25Z-ShiftBrite

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers movie.cpp Source File

movie.cpp

00001 #include "mbed.h"
00002 #include "movie.h"
00003 #include "sbDriver.h"
00004 
00005 movie::movie(unsigned short int * movie_p, shiftBriteDisplay &display, unsigned int movieSize):r_display(display){
00006     //Constructor - sets up initial condition
00007     //r_display = display;  //setup a reference to the actual display
00008     this->movie_p = movie_p; // pointer to the data. This data is simply and array of short integers but sequenced as frames
00009     //i.e. if the display has 2 leds and the data is {12,13,14,15,16,17,18,19,20,21,22} then the first frame is 12,13,14+15,16,17
00010     //corresponding to rgb_led1 and rgb_led2
00011     currentFrame = 0;
00012     frameSize = r_display.getModuleCount();
00013     this->movieSize = movieSize; // in BYTES. Need to (((movieSize/sizeof(unsigned short int))/frameSize)/3) to get actual frames
00014 }
00015 
00016 /**
00017 * Used to play through a data 'movie' array, one frame each time this member function is called.
00018 */
00019 void movie::play(){
00020 /*Advance therough the movie one frame whenever this member method is called
00021     Display is referenced with r_display
00022 */
00023 
00024     unsigned int dot = 0;
00025     unsigned short int rTemp, gTemp, bTemp;
00026     
00027     //moduleCount is how many LEDS, assume 4, called frameSize
00028     //currentFrame is how many frames we've loaded
00029     //currentDot is which module in the frame, i.e. 0-3 in this example
00030     for(dot = 0; dot != frameSize; dot++){
00031         rTemp = *(movie_p + ((currentFrame*frameSize*3)+(dot*3)+0));
00032         gTemp = *(movie_p + ((currentFrame*frameSize*3)+(dot*3)+1));
00033         bTemp = *(movie_p + ((currentFrame*frameSize*3)+(dot*3)+2));
00034         r_display.setLed(dot,rTemp,gTemp,bTemp);
00035     }
00036     
00037     r_display.displayFrame();//update the display - MAKE IT HAPPEN
00038     
00039     currentFrame++;//Advance to the next frame
00040     //Check bounds
00041     if((currentFrame)>=((movieSize/sizeof(unsigned short int))/frameSize)/3){
00042         if(f_repeat == 1) currentFrame = 0;//start from first frame
00043         else currentFrame--; //force to repeat last frame
00044     }
00045  }