![](/media/cache/profiles/266dc8d468ccd5a7def18714b2647e92.jpg.50x50_q85.jpg)
DOGS-102 Graphic LCD module Example. Based on Igor Skochinsky's "DOGLCDDemo" program.
Dependencies: DOG-S_GraphicLCD mbed
Fork of DOGLCDDemo by
main.cpp@0:2a5dccfd318f, 2010-01-14 (annotated)
- Committer:
- igorsk
- Date:
- Thu Jan 14 00:49:39 2010 +0000
- Revision:
- 0:2a5dccfd318f
- Child:
- 1:b7a86d680935
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
igorsk | 0:2a5dccfd318f | 1 | #include "mbed.h" |
igorsk | 0:2a5dccfd318f | 2 | #include "Graphics.h" |
igorsk | 0:2a5dccfd318f | 3 | #include "Cuboid.h" |
igorsk | 0:2a5dccfd318f | 4 | #include "TrimeshObject.h" |
igorsk | 0:2a5dccfd318f | 5 | #include "TieFighter.h" |
igorsk | 0:2a5dccfd318f | 6 | #include "DogLCD.h" |
igorsk | 0:2a5dccfd318f | 7 | #include "hellombed.h" |
igorsk | 0:2a5dccfd318f | 8 | |
igorsk | 0:2a5dccfd318f | 9 | SPI spi(p5, NC, p7); |
igorsk | 0:2a5dccfd318f | 10 | DogLCD dog(spi, p17, p18, p20, p19); // spi, power, cs, a0, reset |
igorsk | 0:2a5dccfd318f | 11 | Graphics g(&dog); |
igorsk | 0:2a5dccfd318f | 12 | TrimeshObject tf(tie_fighter_vertices, tie_fighter_faces, TIE_FIGHTER_NUM_FACES); |
igorsk | 0:2a5dccfd318f | 13 | Cuboid cube; |
igorsk | 0:2a5dccfd318f | 14 | |
igorsk | 0:2a5dccfd318f | 15 | int main() |
igorsk | 0:2a5dccfd318f | 16 | { |
igorsk | 0:2a5dccfd318f | 17 | dog.init(); |
igorsk | 0:2a5dccfd318f | 18 | // draw "hello mbed" |
igorsk | 0:2a5dccfd318f | 19 | dog.send_pic(pic_hellombed); |
igorsk | 0:2a5dccfd318f | 20 | wait(5); |
igorsk | 0:2a5dccfd318f | 21 | // draw rectangle around the screen |
igorsk | 0:2a5dccfd318f | 22 | g.line(0, 0, dog.width()-1, 0, 0xFFFFFF); |
igorsk | 0:2a5dccfd318f | 23 | wait(2); |
igorsk | 0:2a5dccfd318f | 24 | g.line(dog.width()-1, 0, dog.width()-1, dog.height()-1, 0xFFFFFF); |
igorsk | 0:2a5dccfd318f | 25 | wait(2); |
igorsk | 0:2a5dccfd318f | 26 | g.line(dog.width()-1, dog.height()-1, 0, dog.height()-1, 0xFFFFFF); |
igorsk | 0:2a5dccfd318f | 27 | wait(2); |
igorsk | 0:2a5dccfd318f | 28 | g.line(0, dog.height()-1, 0, 0, 0xFFFFFF); |
igorsk | 0:2a5dccfd318f | 29 | wait(5); |
igorsk | 0:2a5dccfd318f | 30 | |
igorsk | 0:2a5dccfd318f | 31 | dog.clear_screen(); |
igorsk | 0:2a5dccfd318f | 32 | float rotx = 0, roty = 0, rotz = 0; |
igorsk | 0:2a5dccfd318f | 33 | |
igorsk | 0:2a5dccfd318f | 34 | Timer timer; |
igorsk | 0:2a5dccfd318f | 35 | timer.start(); |
igorsk | 0:2a5dccfd318f | 36 | int frameno = 0; |
igorsk | 0:2a5dccfd318f | 37 | const int pollcount = 10; |
igorsk | 0:2a5dccfd318f | 38 | // shift 1/4th of screen to the left |
igorsk | 0:2a5dccfd318f | 39 | tf.position(-dog.width() / 4, 0, 0); |
igorsk | 0:2a5dccfd318f | 40 | tf.colour(0xffffff); |
igorsk | 0:2a5dccfd318f | 41 | // shift 1/4th of screen to the right |
igorsk | 0:2a5dccfd318f | 42 | cube.position(+dog.width() / 4, 0, 0); |
igorsk | 0:2a5dccfd318f | 43 | cube.colour(0xffffff); |
igorsk | 0:2a5dccfd318f | 44 | while (1) |
igorsk | 0:2a5dccfd318f | 45 | { |
igorsk | 0:2a5dccfd318f | 46 | rotx += 0.1; |
igorsk | 0:2a5dccfd318f | 47 | roty += 0.08; |
igorsk | 0:2a5dccfd318f | 48 | rotz += 0.05; |
igorsk | 0:2a5dccfd318f | 49 | |
igorsk | 0:2a5dccfd318f | 50 | // set rotation angles |
igorsk | 0:2a5dccfd318f | 51 | tf.rotate(rotx, roty, rotz); |
igorsk | 0:2a5dccfd318f | 52 | cube.rotate(rotx, roty, rotz); |
igorsk | 0:2a5dccfd318f | 53 | // lock update |
igorsk | 0:2a5dccfd318f | 54 | dog.beginupdate(); |
igorsk | 0:2a5dccfd318f | 55 | dog.clear_screen(); |
igorsk | 0:2a5dccfd318f | 56 | // render TieFighter |
igorsk | 0:2a5dccfd318f | 57 | tf.render(g); |
igorsk | 0:2a5dccfd318f | 58 | // and the cube |
igorsk | 0:2a5dccfd318f | 59 | cube.render(g); |
igorsk | 0:2a5dccfd318f | 60 | // unlock update (and draw framebuffer) |
igorsk | 0:2a5dccfd318f | 61 | dog.endupdate(); |
igorsk | 0:2a5dccfd318f | 62 | if ( ++frameno == pollcount ) |
igorsk | 0:2a5dccfd318f | 63 | { |
igorsk | 0:2a5dccfd318f | 64 | // output fps to serial |
igorsk | 0:2a5dccfd318f | 65 | int end = timer.read_ms(); |
igorsk | 0:2a5dccfd318f | 66 | float fps = pollcount*1000.0/end; |
igorsk | 0:2a5dccfd318f | 67 | printf("\r%d frames, %d ms, FPS: %f", pollcount, end, fps); |
igorsk | 0:2a5dccfd318f | 68 | frameno = 0; |
igorsk | 0:2a5dccfd318f | 69 | timer.reset(); |
igorsk | 0:2a5dccfd318f | 70 | } |
igorsk | 0:2a5dccfd318f | 71 | //dog.fill(40, 40, 52, 52, 0x000000); |
igorsk | 0:2a5dccfd318f | 72 | } |
igorsk | 0:2a5dccfd318f | 73 | } |