DOGS-102 Graphic LCD module Example. Many circles are drawn and it further rebounds.
Dependencies: DOG-S_GraphicLCD mbed
main.cpp
00001 //#define DEBUG 00002 00003 #include "mbed.h" 00004 00005 //DOGS102 Library 00006 #include "DogLCD.h" 00007 #include "Graphics.h" 00008 00009 #if defined(TARGET_LPC1768) 00010 SPI spi(p11, NC, p13); 00011 DogLCD dog(spi, p18, p20, p19); // spi, cs, a0, reset 00012 #elif defined(TARGET_LPC1114) 00013 SPI spi(dp2, NC, dp6); 00014 DogLCD dog(spi, dp9, dp11, dp10); // spi, cs, a0, reset 00015 #endif 00016 00017 Graphics g(&dog); 00018 00019 int main() 00020 { 00021 dog.init(); 00022 dog.clear_screen(); 00023 00024 int i; 00025 int px[5] = {5,10,20,30,60}, py[5] = {10,40,30,20,5}, cr[5] = {7,9,11,13,15}; 00026 int ax[5] = {1,1,1,-1,-1}, ay[5] = {1,1,-1,-1,1}; 00027 00028 #ifdef DEBUG 00029 Timer timer; 00030 timer.start(); 00031 int frameno = 0; 00032 const int pollcount = 100; 00033 #endif 00034 00035 while(1) 00036 { 00037 // lock update 00038 dog.beginupdate(); 00039 dog.clear_screen(); 00040 00041 g.line(0, 0, dog.width()-1, 0, 0xFFFFFF); 00042 g.line(dog.width()-1, 0, dog.width()-1, dog.height()-1, 0xFFFFFF); 00043 g.line(dog.width()-1, dog.height()-1, 0, dog.height()-1, 0xFFFFFF); 00044 g.line(0, dog.height()-1, 0, 0, 0xFFFFFF); 00045 00046 for(i = 0; i < 5; i++) 00047 { 00048 g.circle(px[i]+cr[i], py[i]+cr[i], cr[i], 0xFFFFFF); 00049 00050 px[i] += ax[i]; 00051 py[i] += ay[i]; 00052 00053 if(px[i] <= 0 || px[i] >= dog.width() -cr[i]*2-1) ax[i] *= -1; 00054 if(py[i] <= 0 || py[i] >= dog.height()-cr[i]*2-1) ay[i] *= -1; 00055 } 00056 00057 // unlock update (and draw framebuffer) 00058 dog.endupdate(); 00059 00060 #ifdef DEBUG 00061 if ( ++frameno == pollcount ) 00062 { 00063 // output fps to serial 00064 int end = timer.read_ms(); 00065 float fps = pollcount*1000.0/end; 00066 printf("%d frames, %d ms, FPS: %f\n", pollcount, end, fps); 00067 frameno = 0; 00068 timer.reset(); 00069 } 00070 #endif 00071 00072 wait_ms(40); 00073 } 00074 }
Generated on Fri Jul 15 2022 02:16:19 by 1.7.2