Johan Kritzinger
/
FRDMKL25Z-ShiftBrite
A few classes to interface one or more ShiftBrite module to the FRDM KL25Z.
Diff: main.cpp
- Revision:
- 4:d2f8ddb423e2
- Parent:
- 3:9376bf1f1bbd
- Child:
- 5:aa0424f31fa1
--- a/main.cpp Wed Aug 20 08:11:28 2014 +0000 +++ b/main.cpp Wed Aug 20 09:26:42 2014 +0000 @@ -1,12 +1,16 @@ #include "mbed.h" #include "sbDriver.h" #include "movie.h" -/*MUST TRY THIS!!!! -Inheritance is one of the great features of object oriented languages like C++. The stream methods are not included in serial to allow you to use them in other classes as well. They are for example also included in the TextLCD class and in my enhanced TextLCD class. All you need to do to make use of the powerful printf features is implement a putc() method in your own new class. -from https://mbed.org/questions/1029/pcprintf-a-method/ + +/* 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 +if you use some/all of my code/classes. My name is Johan Kritzinger and I go by 'JoKer' on MBED. +My C++ is not that hot (I'm an old PLM-51 and C programmer) but the only way to learn is to do. +Any questions, please feel free to ask. */ + //6 leds example. Format it suitably for easy reading unsigned short int aMovie[] = { /* LED1 LED2 LED3 LED4 LED5 LED6 */ @@ -22,19 +26,18 @@ 0,0,0, 1023,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 Bluetooth/Serial as output to terminal and input + +Serial PC(PTA2, PTA1);//So I can use Serial as output to terminal and input - -DigitalOut myled(LED1); - +//================== HARDWARE CONNECTIONS ========================================= +//NB!!! I have only tested this on the FRDM KL25Z and h/w connection as detailed below //Instanced of DigitalOut for control SB signals DigitalOut latch(PTC16);//010=latch DigitalOut enable(PTA13);//0= enabled DigitalOut reset(PTC12); //Instance of the SPI contoller for SB data SPI spi(PTD2,NC,PTD1);//PDT2 = MOSI=DATA. PDT1=CLK - +//=================== END OF HARDWARE CONNECTIONS ================================= int main() { @@ -42,14 +45,10 @@ Ticker t; //Instanciate a string of 5 sb modules and tell the driver object where the control/data pins are -shiftBriteDisplay sbDisplay(&PC,latch, enable, reset, spi,6); +shiftBriteDisplay sbDisplay(latch, enable, reset, spi,6); //Example calls to method f() of shiftBriteDisplay class -//sbDisplay.setLed(0,0X550000); -//sbDisplay.setLed(4,0XFF,0X00,0X55); //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 sbDisplay.setLed(0,0XFF0000);//Red sbDisplay.setLed(1,0X00FF00);//Green @@ -103,10 +102,6 @@ sbDisplay.displayFrame(); wait(0.2); } - -PC.printf("Hallo (size=%d)\r\n", sizeof(unsigned long int)); - - sbDisplay.setLed(0,0X0F0000);//Red @@ -120,17 +115,30 @@ sbDisplay.setCurrentCorr(0,0,0);//Dim sbDisplay.displayFrame(); //get it on the LEDS -//Alternative to calling displayFrame() yourself, setup the framerate and update the display + +//Alternative to calling displayFrame() yourself, setup the framerate and update the display using Ticker e.g. //t.attach_us(&sbDisplay,&shiftBriteDisplay::displayFrame,41666);//call updateFrame 24 times per second (every 41666uS) -//t.attach(&sbDisplay,&shiftBriteDisplay::displayFrame,0.5);// or only every 0.5s for testing +//or t.attach(&sbDisplay,&shiftBriteDisplay::displayFrame,0.5);// or only every 0.5s for testing -//USING THE MOVIE CLASS -//Note, it uses the previously declared sbDisplay object. - // movie myMovie(aMovie,sbDisplay,sizeof(aMovie)); - // myMovie.setRepeat(1); - // t.attach(&myMovie,&movie::play,0.05);//Beware, if you go too fast here the MBED will crash +/* +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 - while(1){ + + + while(1){ // Nothing going on in the main loop as Ticker calls the appropriate member function } } + + +/*TODO - +Inheritance is one of the great features of object oriented languages like C++. The stream methods are not included in serial to allow you to use them in other classes as well. They are for example also included in the TextLCD class and in my enhanced TextLCD class. All you need to do to make use of the powerful printf features is implement a putc() method in your own new class. +from https://mbed.org/questions/1029/pcprintf-a-method/ + +*/