Oxford CWM Team / Mbed 2 deprecated TFT_CJS_ssd01399_portver_prettyfont

Dependencies:   LCDTFT TFT_fonts mbed

main.cpp

Committer:
cstevens
Date:
2015-06-12
Revision:
1:b4ae6047d590
Parent:
0:92feefa9d5ba
Child:
2:1bc1605bffae

File content as of revision 1:b4ae6047d590:

#include "mbed.h"
#include "LCDTFT.h"
#include "Arial12x12.h"
#include "Arial24x23.h"
#include "Arial28x28.h"
#include "font_big.h"

//BusOut MyBus(PTA13,PTD5,PTD4,PTA12,PTA4,PTA5,PTC8,PTC9); // 8 bit bus on these dvices


PortOut MyPort(PortD ,0xFF); // define a port with only the lower 8 bits included - that'llbe PTD0-PTD7 making a single 8 bit port.
LCDTFT     MyLCD(PTB0,PTB1,PTB2,PTB3,PTC2,&MyPort);//LCDTFT(PinName PIN_RD,PinName PIN_WR,PinName PIN_RS,PinName PIN_CS,PinName PIN_RESET, PortOut *PORTLCD);



// ok - a simple sub to put in a character from the fonts defined in TFT_fonts
// c= charactetr to put
// font = pointer to font to use
// x,y locatoin of bottom lh of character, bcol = background color, fcol = foreground color
void prettyputc(char c, const unsigned char *font,short xpos,short ypos,short bcol, short fcol)
{
    // Length,horz,vert,byte/vert
    int length,hor,vert,bpver; // number of bytes per character, horizontal pixels, vertical pixels and bytes per column
    //
    int x,y,i,j,k,ptr;
    short coltowrite;
    char byte,point;
    length=font[0];
    hor=font[1];
    vert=font[2];
    bpver=font[3];
    for(i=0; i<hor; i++) { // loop over columns
        for(j=0; j<vert; j++) {
            x=xpos+i;
            y=ypos+j; // NB assumes colums stored from bottom to top.... ?
            ptr=((c -32) * length+1) + 4+i*bpver+(j/8);  // pointer in font array to start of the character we want
            byte=(char)font[ptr];
            k=j%8; // number of the pixel in this byte
            point=byte & (1<<k); // get the next bit
            if(point>0) {
                coltowrite=fcol;
            } else {
                coltowrite=bcol;
            }

            MyLCD.vLCDTFTPoint(x,y,coltowrite);

        }
    }

}




int main()
{
    int i,j;
    char message[10];
    sprintf(message,"Hello!!");
    while(1) {

        MyLCD.vLCDTFTInit(1);

        MyLCD.vLCDTFTFillScreen(ColorWhite);

        for(i=0; i<200; i++) {
            MyLCD.vLCDTFTPoint(50+i,100,ColorRed);
        }
        for(j=0; j<10; j++) {
            for(i=0; i<10; i++) {
                prettyputc(32+(i+j*10)%90,Arial24x23,24*i,23*j ,ColorWhite, ColorGreen);
                wait(0.03);
            }
        }
        wait(5);
        for(j=0; j<10; j++) {
            for(i=0; i<10; i++) {
                prettyputc(32+(i+j*10)%90,Arial12x12,12*i,12*j ,ColorWhite, ColorBlue);
                wait(0.03);
            }
        }
        wait(5);
        for(j=0; j<10; j++) {
            for(i=0; i<10; i++) {
                prettyputc(32+(i+j*10)%90,Arial28x28,28*i,28*j ,ColorWhite, ColorRed);
                wait(0.03);
            }
        }
        wait(5);

    }// endwhile
} //endmain