![](/media/cache/profiles/266dc8d468ccd5a7def18714b2647e92.jpg.50x50_q85.jpg)
DOGS-102 Graphic LCD module Example. Many circles are drawn and it further rebounds.
Dependencies: DOG-S_GraphicLCD mbed
main.cpp@0:d6cd1606ca86, 2014-05-03 (annotated)
- Committer:
- ban4jp
- Date:
- Sat May 03 18:12:21 2014 +0000
- Revision:
- 0:d6cd1606ca86
first commit of an example code.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ban4jp | 0:d6cd1606ca86 | 1 | //#define DEBUG |
ban4jp | 0:d6cd1606ca86 | 2 | |
ban4jp | 0:d6cd1606ca86 | 3 | #include "mbed.h" |
ban4jp | 0:d6cd1606ca86 | 4 | |
ban4jp | 0:d6cd1606ca86 | 5 | //DOGS102 Library |
ban4jp | 0:d6cd1606ca86 | 6 | #include "DogLCD.h" |
ban4jp | 0:d6cd1606ca86 | 7 | #include "Graphics.h" |
ban4jp | 0:d6cd1606ca86 | 8 | |
ban4jp | 0:d6cd1606ca86 | 9 | #if defined(TARGET_LPC1768) |
ban4jp | 0:d6cd1606ca86 | 10 | SPI spi(p11, NC, p13); |
ban4jp | 0:d6cd1606ca86 | 11 | DogLCD dog(spi, p18, p20, p19); // spi, cs, a0, reset |
ban4jp | 0:d6cd1606ca86 | 12 | #elif defined(TARGET_LPC1114) |
ban4jp | 0:d6cd1606ca86 | 13 | SPI spi(dp2, NC, dp6); |
ban4jp | 0:d6cd1606ca86 | 14 | DogLCD dog(spi, dp9, dp11, dp10); // spi, cs, a0, reset |
ban4jp | 0:d6cd1606ca86 | 15 | #endif |
ban4jp | 0:d6cd1606ca86 | 16 | |
ban4jp | 0:d6cd1606ca86 | 17 | Graphics g(&dog); |
ban4jp | 0:d6cd1606ca86 | 18 | |
ban4jp | 0:d6cd1606ca86 | 19 | int main() |
ban4jp | 0:d6cd1606ca86 | 20 | { |
ban4jp | 0:d6cd1606ca86 | 21 | dog.init(); |
ban4jp | 0:d6cd1606ca86 | 22 | dog.clear_screen(); |
ban4jp | 0:d6cd1606ca86 | 23 | |
ban4jp | 0:d6cd1606ca86 | 24 | int i; |
ban4jp | 0:d6cd1606ca86 | 25 | int px[5] = {5,10,20,30,60}, py[5] = {10,40,30,20,5}, cr[5] = {7,9,11,13,15}; |
ban4jp | 0:d6cd1606ca86 | 26 | int ax[5] = {1,1,1,-1,-1}, ay[5] = {1,1,-1,-1,1}; |
ban4jp | 0:d6cd1606ca86 | 27 | |
ban4jp | 0:d6cd1606ca86 | 28 | #ifdef DEBUG |
ban4jp | 0:d6cd1606ca86 | 29 | Timer timer; |
ban4jp | 0:d6cd1606ca86 | 30 | timer.start(); |
ban4jp | 0:d6cd1606ca86 | 31 | int frameno = 0; |
ban4jp | 0:d6cd1606ca86 | 32 | const int pollcount = 100; |
ban4jp | 0:d6cd1606ca86 | 33 | #endif |
ban4jp | 0:d6cd1606ca86 | 34 | |
ban4jp | 0:d6cd1606ca86 | 35 | while(1) |
ban4jp | 0:d6cd1606ca86 | 36 | { |
ban4jp | 0:d6cd1606ca86 | 37 | // lock update |
ban4jp | 0:d6cd1606ca86 | 38 | dog.beginupdate(); |
ban4jp | 0:d6cd1606ca86 | 39 | dog.clear_screen(); |
ban4jp | 0:d6cd1606ca86 | 40 | |
ban4jp | 0:d6cd1606ca86 | 41 | g.line(0, 0, dog.width()-1, 0, 0xFFFFFF); |
ban4jp | 0:d6cd1606ca86 | 42 | g.line(dog.width()-1, 0, dog.width()-1, dog.height()-1, 0xFFFFFF); |
ban4jp | 0:d6cd1606ca86 | 43 | g.line(dog.width()-1, dog.height()-1, 0, dog.height()-1, 0xFFFFFF); |
ban4jp | 0:d6cd1606ca86 | 44 | g.line(0, dog.height()-1, 0, 0, 0xFFFFFF); |
ban4jp | 0:d6cd1606ca86 | 45 | |
ban4jp | 0:d6cd1606ca86 | 46 | for(i = 0; i < 5; i++) |
ban4jp | 0:d6cd1606ca86 | 47 | { |
ban4jp | 0:d6cd1606ca86 | 48 | g.circle(px[i]+cr[i], py[i]+cr[i], cr[i], 0xFFFFFF); |
ban4jp | 0:d6cd1606ca86 | 49 | |
ban4jp | 0:d6cd1606ca86 | 50 | px[i] += ax[i]; |
ban4jp | 0:d6cd1606ca86 | 51 | py[i] += ay[i]; |
ban4jp | 0:d6cd1606ca86 | 52 | |
ban4jp | 0:d6cd1606ca86 | 53 | if(px[i] <= 0 || px[i] >= dog.width() -cr[i]*2-1) ax[i] *= -1; |
ban4jp | 0:d6cd1606ca86 | 54 | if(py[i] <= 0 || py[i] >= dog.height()-cr[i]*2-1) ay[i] *= -1; |
ban4jp | 0:d6cd1606ca86 | 55 | } |
ban4jp | 0:d6cd1606ca86 | 56 | |
ban4jp | 0:d6cd1606ca86 | 57 | // unlock update (and draw framebuffer) |
ban4jp | 0:d6cd1606ca86 | 58 | dog.endupdate(); |
ban4jp | 0:d6cd1606ca86 | 59 | |
ban4jp | 0:d6cd1606ca86 | 60 | #ifdef DEBUG |
ban4jp | 0:d6cd1606ca86 | 61 | if ( ++frameno == pollcount ) |
ban4jp | 0:d6cd1606ca86 | 62 | { |
ban4jp | 0:d6cd1606ca86 | 63 | // output fps to serial |
ban4jp | 0:d6cd1606ca86 | 64 | int end = timer.read_ms(); |
ban4jp | 0:d6cd1606ca86 | 65 | float fps = pollcount*1000.0/end; |
ban4jp | 0:d6cd1606ca86 | 66 | printf("%d frames, %d ms, FPS: %f\n", pollcount, end, fps); |
ban4jp | 0:d6cd1606ca86 | 67 | frameno = 0; |
ban4jp | 0:d6cd1606ca86 | 68 | timer.reset(); |
ban4jp | 0:d6cd1606ca86 | 69 | } |
ban4jp | 0:d6cd1606ca86 | 70 | #endif |
ban4jp | 0:d6cd1606ca86 | 71 | |
ban4jp | 0:d6cd1606ca86 | 72 | wait_ms(40); |
ban4jp | 0:d6cd1606ca86 | 73 | } |
ban4jp | 0:d6cd1606ca86 | 74 | } |