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

Dependencies:   mbed

Committer:
JoKer
Date:
Tue Aug 19 07:09:20 2014 +0000
Revision:
0:f76850de7b57
Child:
2:3935d2ed40cd
Working version of shiftBrite classes. V1.0 - 19/8/2014

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JoKer 0:f76850de7b57 1 #include "mbed.h"
JoKer 0:f76850de7b57 2 #include "sbDriver.h"
JoKer 0:f76850de7b57 3 /*MUST TRY THIS!!!!
JoKer 0:f76850de7b57 4 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.
JoKer 0:f76850de7b57 5 from https://mbed.org/questions/1029/pcprintf-a-method/
JoKer 0:f76850de7b57 6
JoKer 0:f76850de7b57 7 */
JoKer 0:f76850de7b57 8
JoKer 0:f76850de7b57 9 Serial PC(PTA2, PTA1);//So I can use Bluetooth/Serial as output to terminal and input
JoKer 0:f76850de7b57 10
JoKer 0:f76850de7b57 11
JoKer 0:f76850de7b57 12 DigitalOut myled(LED1);
JoKer 0:f76850de7b57 13
JoKer 0:f76850de7b57 14 //Instanced of DigitalOut for control SB signals
JoKer 0:f76850de7b57 15 DigitalOut latch(PTC16);//010=latch
JoKer 0:f76850de7b57 16 DigitalOut enable(PTA13);//0= enabled
JoKer 0:f76850de7b57 17 DigitalOut reset(PTC12);
JoKer 0:f76850de7b57 18 //Instance of the SPI contoller for SB data
JoKer 0:f76850de7b57 19 SPI spi(PTD2,NC,PTD1);//PDT2 = MOSI=DATA. PDT1=CLK
JoKer 0:f76850de7b57 20
JoKer 0:f76850de7b57 21
JoKer 0:f76850de7b57 22 int main() {
JoKer 0:f76850de7b57 23
JoKer 0:f76850de7b57 24 //Instanciate a ticker object to handle framerate updates for the SB display
JoKer 0:f76850de7b57 25 Ticker t;
JoKer 0:f76850de7b57 26
JoKer 0:f76850de7b57 27 //Instanciate a string of 5 sb modules and tell the driver object where the control/data pins are
JoKer 0:f76850de7b57 28 shiftBriteDisplay sbDisplay(&PC,latch, enable, reset, spi,6);
JoKer 0:f76850de7b57 29
JoKer 0:f76850de7b57 30 //Example calls to method f() of shiftBriteDisplay class
JoKer 0:f76850de7b57 31 //sbDisplay.setLed(0,0X550000);
JoKer 0:f76850de7b57 32 //sbDisplay.setLed(4,0XFF,0X00,0X55);
JoKer 0:f76850de7b57 33 //in this case, 6 of these statements wold be required to build one frame
JoKer 0:f76850de7b57 34 //BUILD A FRAME
JoKer 0:f76850de7b57 35 /*sbDisplay.setLed(0,0XFF0000);//Red
JoKer 0:f76850de7b57 36 sbDisplay.setLed(1,0X00FF00);//Green
JoKer 0:f76850de7b57 37 sbDisplay.setLed(2,0X0000FF);//Blue
JoKer 0:f76850de7b57 38 sbDisplay.setLed(3,0XFFFF00);//Yellow
JoKer 0:f76850de7b57 39 sbDisplay.setLed(4,0X00FFFF); //Cyan?
JoKer 0:f76850de7b57 40 sbDisplay.setLed(5,0XFF00FF); // Purple*/
JoKer 0:f76850de7b57 41
JoKer 0:f76850de7b57 42 sbDisplay.setLed(0,0XFFFFFF);//White
JoKer 0:f76850de7b57 43 sbDisplay.setLed(1,0XFFFFFF);//
JoKer 0:f76850de7b57 44 sbDisplay.setLed(2,0XFFFFFF);//
JoKer 0:f76850de7b57 45 sbDisplay.setLed(3,0XFFFFFF);//
JoKer 0:f76850de7b57 46 sbDisplay.setLed(4,0XFFFFFF); //
JoKer 0:f76850de7b57 47 sbDisplay.setLed(5,0XFFFFFF); //
JoKer 0:f76850de7b57 48 sbDisplay.setCurrentCorr(0,0,0);//suggested default value cor current control regs. Values g&b=100, r=120
JoKer 0:f76850de7b57 49 sbDisplay.displayFrame();//force an update
JoKer 0:f76850de7b57 50 wait(2);
JoKer 0:f76850de7b57 51 sbDisplay.setCurrentCorr(127,127,127);//This should be MAX
JoKer 0:f76850de7b57 52 wait(2);
JoKer 0:f76850de7b57 53 sbDisplay.setCurrentCorr(0x78,0x64,0x64);//sb suggested default
JoKer 0:f76850de7b57 54 wait(2);
JoKer 0:f76850de7b57 55
JoKer 0:f76850de7b57 56 PC.printf("Hallo (size=%d)\r\n", sizeof(unsigned long int));
JoKer 0:f76850de7b57 57
JoKer 0:f76850de7b57 58
JoKer 0:f76850de7b57 59 //Setup the framerate and update the display
JoKer 0:f76850de7b57 60 //I chose standard 24fps
JoKer 0:f76850de7b57 61 t.attach_us(&sbDisplay,&shiftBriteDisplay::displayFrame,41666);//call updateFrame 24 times per second (every 41666uS)
JoKer 0:f76850de7b57 62 //t.attach(&sbDisplay,&shiftBriteDisplay::displayFrame,0.5);//Only every 0.5s for testing
JoKer 0:f76850de7b57 63
JoKer 0:f76850de7b57 64
JoKer 0:f76850de7b57 65 while(1){
JoKer 0:f76850de7b57 66 /*TEST THE CURRENT ADJUSMENT FUNCTIONALITY
JoKer 0:f76850de7b57 67 sbDisplay.setCurrentCorr(0,0,0);
JoKer 0:f76850de7b57 68 wait(0.5);
JoKer 0:f76850de7b57 69 sbDisplay.setCurrentCorr(30,30,30);
JoKer 0:f76850de7b57 70 wait(0.5);
JoKer 0:f76850de7b57 71 sbDisplay.setCurrentCorr(60,60,60);
JoKer 0:f76850de7b57 72 wait(0.5);
JoKer 0:f76850de7b57 73 sbDisplay.setCurrentCorr(90,90,30);
JoKer 0:f76850de7b57 74 wait(0.5);
JoKer 0:f76850de7b57 75 sbDisplay.setCurrentCorr(120,120,30);
JoKer 0:f76850de7b57 76 wait(0.5);
JoKer 0:f76850de7b57 77 */
JoKer 0:f76850de7b57 78 sbDisplay.setLed(0,0XFF0000);//Red
JoKer 0:f76850de7b57 79 sbDisplay.setLed(1,0X00FF00);//Green
JoKer 0:f76850de7b57 80 sbDisplay.setLed(2,0X0000FF);//Blue
JoKer 0:f76850de7b57 81 sbDisplay.setLed(3,0XFFFF00);//Yellow
JoKer 0:f76850de7b57 82 sbDisplay.setLed(4,0X00FFFF); //Cyan?
JoKer 0:f76850de7b57 83 sbDisplay.setLed(5,0XFF00FF); // Purple
JoKer 0:f76850de7b57 84 wait(0.5);
JoKer 0:f76850de7b57 85 sbDisplay.setLed(5,0XFF0000);//Red
JoKer 0:f76850de7b57 86 sbDisplay.setLed(4,0X00FF00);//Green
JoKer 0:f76850de7b57 87 sbDisplay.setLed(3,0X0000FF);//Blue
JoKer 0:f76850de7b57 88 sbDisplay.setLed(2,0XFFFF00);//Yellow
JoKer 0:f76850de7b57 89 sbDisplay.setLed(1,0X00FFFF); //Cyan?
JoKer 0:f76850de7b57 90 sbDisplay.setLed(0,0XFF00FF); // Purple
JoKer 0:f76850de7b57 91 wait(0.5);
JoKer 0:f76850de7b57 92 }
JoKer 0:f76850de7b57 93 }