Contains the main execution of the clock uses headers to import functions
Dependencies: RTC-DS1307 SPI_TFT_ILI9341 TFT_fonts mbed tsi_sensor
Fork of TFT_Mikroelectronika_IL9341_sketchpad by
pong.h
- Committer:
- Owenmatthewmcgowan
- Date:
- 2017-05-26
- Revision:
- 49:243b5e826228
- Parent:
- 48:76ac309a2bd9
File content as of revision 49:243b5e826228:
void pong(){ int p_height = 40,p_width = 5,b_r =5; int p_y,p_yl,b_x,b_xl,b_y,b_yl = 0; int vX =5 ,vY = 5; int multiplier = 30; float tsi_current, tsi_last = 0; TFT.cls(); TFT.line(p_width,0,320,0,White); TFT.line(320,0,320,240,White); TFT.line(p_width,240,320,240,White); b_x = 160; b_y = 120; while (true){ readX(); if (touching == 1){ //f_state = 1; //break; } tsi_current = tsi.readPercentage(); float change = 0; if (tsi_current != 0 && tsi_last != 0) {change = tsi_current - tsi_last;} else {change = 0;} tsi_last = tsi_current; int delta = change * multiplier; int newval = p_y + delta ; if (newval > 0 && newval < (240 - p_height)) p_y = newval; if (b_y < 10 || b_y > 230){ vY *= -1; } if (b_x > 310 || (b_x < p_width)){ vX *= -1; if (!(b_y > p_y && b_y < (p_y + p_height) &&(b_x < p_width))) {f_state = 1; break;} } b_x += vX; b_y += vY; if (p_y != p_yl){ TFT.fillrect(0,p_yl,p_width,p_yl + p_height,Black); TFT.fillrect(0,p_y, p_width, p_y + p_height, White); } if (b_y != b_yl || b_x != b_xl){ TFT.fillcircle(b_xl,b_yl,b_r,Black); TFT.fillcircle(b_x,b_y,b_r,White); b_yl = b_y; b_xl = b_x; } wait(0.5); } }