Bounce Ball Demo- MBED + SmartGPU2 board

Dependencies:   SMARTGPU2 mbed

Revision:
0:4c26cabd36d5
Child:
1:507c7564ece2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jul 10 03:25:24 2013 +0000
@@ -0,0 +1,65 @@
+/**************************************************************************************/
+/*SMARTGPU2 intelligent embedded graphics processor unit
+ those examples are for use the SMARTGPU2 with the mbed microcontoller, just connect tx,rx,and reset
+ Board:
+ http://vizictechnologies.com/#/smart-gpu-2/4577779046
+ 
+ www.vizictechnologies.com 
+ Vizic Technologies copyright 2013 */
+/**************************************************************************************/
+/**************************************************************************************/
+
+#include "mbed.h"
+#include "SMARTGPU2.h"
+
+// defines for balls
+#define RADIUSBALL1 15     //ball1 size
+#define COLOURBALL1 RED    //ball1 colour
+
+//variables used by move ball method
+int speedBall1=3; //ball1 moving speed - amount of pixels that ball move each time
+int dirx1=1;      //xball1 initial positive direction
+int diry1=-1;     //yball1 initial negative direction
+int xBall1=300;   //x initial position of ball1
+int yBall1=100;   //y initial position of ball1
+
+SMARTGPU2 lcd(TXPIN,RXPIN,RESETPIN);  //create our object called "lcd"
+
+/***************************************************/
+//Function that updates the current position of the ball1
+void moveBall1(){
+   lcd.drawCircle(xBall1,yBall1,RADIUSBALL1,BLACK,FILL);       // Erase previous ball position
+   xBall1+=(dirx1*speedBall1);                                 // Calculate new x coordinate for ball1 
+   yBall1+=(diry1*speedBall1);                                 // Calculate new y coordinate for ball1  
+   lcd.drawCircle(xBall1,yBall1,RADIUSBALL1,COLOURBALL1,FILL); // Draw new ball position
+   if((xBall1+speedBall1+RADIUSBALL1)>318 | (xBall1-speedBall1-RADIUSBALL1)<=1){           // if ball reaches the left or right corner, we invert moving direction 
+    dirx1= dirx1*(-1);                                         // Invert the moving direction by multiplying by -1
+   }
+   if((yBall1+speedBall1+RADIUSBALL1)>238 | (yBall1-speedBall1-RADIUSBALL1)<=1){           // if ball reaches the top or bottom corner, we invert moving direction 
+    diry1= diry1*(-1);                                         // Invert the moving direction by multiplying by -1
+   }                       
+}
+
+/***************************************************/
+/***************************************************/
+void initializeSmartGPU2(void){      //Initialize SMARTGPU2 Board
+  lcd.reset();                       //physically reset SMARTGPU2
+  lcd.start();                       //initialize the SMARTGPU2 processor
+}
+
+/***************************************************/
+/***************************************************/
+/***************************************************/
+/***************************************************/
+int main() {
+  
+  initializeSmartGPU2();             //Init communication with SmartGPU2 board
+  
+  lcd.baudChange(BAUD7);             //set a fast baud! for fast drawing
+  lcd.drawRectangle(0,0,319,239,YELLOW,UNFILL); //draw corners
+  
+  while(1){             // Loop forever
+    moveBall1();        // move ball1
+    wait_ms(15);        // wait a little
+  }
+}
\ No newline at end of file