A demo program for DOGL-128 LCD module. Based on Mike Sheldon's 3D Tie Fighter demo.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "Graphics.h"
00003 #include "Cuboid.h"
00004 #include "TrimeshObject.h"
00005 #include "TieFighter.h"
00006 #include "DogLCD.h"
00007 #include "hellombed.h"
00008 
00009 SPI spi(p5, NC, p7);
00010 DogLCD dog(spi, p17, p18, p20, p19); //  spi, power, cs, a0, reset
00011 Graphics g(&dog);
00012 TrimeshObject tf(tie_fighter_vertices, tie_fighter_faces, TIE_FIGHTER_NUM_FACES);
00013 Cuboid cube;
00014 
00015 int main()
00016 {
00017     dog.init();
00018     // draw "hello mbed"
00019     dog.send_pic(pic_hellombed);
00020     wait(5);
00021     // draw rectangle around the screen
00022     g.line(0, 0, dog.width()-1, 0, 0xFFFFFF);
00023     wait(2);
00024     g.line(dog.width()-1, 0, dog.width()-1, dog.height()-1, 0xFFFFFF);
00025     wait(2);
00026     g.line(dog.width()-1, dog.height()-1, 0, dog.height()-1, 0xFFFFFF);
00027     wait(2);
00028     g.line(0, dog.height()-1, 0, 0, 0xFFFFFF);
00029     wait(5);
00030     
00031     dog.clear_screen();
00032     float rotx = 0, roty = 0, rotz = 0;
00033     
00034     Timer timer;
00035     timer.start();
00036     int frameno = 0;
00037     const int pollcount = 10;
00038     // shift 1/4th of screen to the left
00039     tf.position(-dog.width() / 4, 0, 0);
00040     tf.colour(0xffffff);
00041     // shift 1/4th of screen to the right
00042     cube.position(+dog.width() / 4, 0, 0);
00043     cube.colour(0xffffff);
00044     while (1)
00045     {
00046         rotx += 0.1;
00047         roty += 0.08;
00048         rotz += 0.05;
00049         
00050         // set rotation angles
00051         tf.rotate(rotx, roty, rotz);
00052         cube.rotate(rotx, roty, rotz);
00053         // lock update
00054         dog.beginupdate();
00055             dog.clear_screen();
00056             // render TieFighter
00057             tf.render(g);
00058             // and the cube
00059             cube.render(g);
00060         // unlock update (and draw framebuffer)    
00061         dog.endupdate();
00062         if ( ++frameno == pollcount )
00063         {
00064             // output fps to serial
00065             int end = timer.read_ms();
00066             float fps = pollcount*1000.0/end;
00067             printf("\r%d frames, %d ms, FPS: %f", pollcount, end, fps);
00068             frameno = 0;
00069             timer.reset();
00070         }
00071         //dog.fill(40, 40, 52, 52, 0x000000);
00072     }
00073 }