Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: RTC-DS1307 SPI_TFT_ILI9341 TFT_fonts mbed tsi_sensor
Fork of TFT_Mikroelectronika_IL9341_sketchpad by
pong.h
00001 void pong(){ 00002 int p_height = 40,p_width = 5,b_r =5; 00003 int p_y,p_yl,b_x,b_xl,b_y,b_yl = 0; 00004 int vX =5 ,vY = 5; 00005 int multiplier = 30; 00006 float tsi_current, tsi_last = 0; 00007 TFT.cls(); 00008 TFT.line(p_width,0,320,0,White); 00009 TFT.line(320,0,320,240,White); 00010 TFT.line(p_width,240,320,240,White); 00011 b_x = 160; 00012 b_y = 120; 00013 while (true){ 00014 readX(); 00015 if (touching == 1){ 00016 //f_state = 1; 00017 //break; 00018 } 00019 tsi_current = tsi.readPercentage(); 00020 float change = 0; 00021 if (tsi_current != 0 && tsi_last != 0) {change = tsi_current - tsi_last;} 00022 else {change = 0;} 00023 tsi_last = tsi_current; 00024 int delta = change * multiplier; 00025 int newval = p_y + delta ; 00026 if (newval > 0 && newval < (240 - p_height)) p_y = newval; 00027 if (b_y < 10 || b_y > 230){ 00028 vY *= -1; 00029 } 00030 if (b_x > 310 || (b_x < p_width)){ 00031 vX *= -1; 00032 if (!(b_y > p_y && b_y < (p_y + p_height) &&(b_x < p_width))) {f_state = 1; break;} 00033 } 00034 00035 b_x += vX; 00036 b_y += vY; 00037 if (p_y != p_yl){ 00038 TFT.fillrect(0,p_yl,p_width,p_yl + p_height,Black); 00039 TFT.fillrect(0,p_y, p_width, p_y + p_height, White); 00040 } 00041 if (b_y != b_yl || b_x != b_xl){ 00042 TFT.fillcircle(b_xl,b_yl,b_r,Black); 00043 TFT.fillcircle(b_x,b_y,b_r,White); 00044 b_yl = b_y; 00045 b_xl = b_x; 00046 } 00047 wait(0.5); 00048 } 00049 00050 }
Generated on Thu Jul 14 2022 09:34:11 by
1.7.2
