Vizic Technologies
/
BounceBall_SG2
Bounce Ball Demo- MBED + SmartGPU2 board
main.cpp
- Committer:
- emmanuelchio
- Date:
- 2014-04-17
- Revision:
- 1:507c7564ece2
- Parent:
- 0:4c26cabd36d5
File content as of revision 1:507c7564ece2:
/**************************************************************************************/ /*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://www.vizictechnologies.com/#!smartgpu-2/c1rc2 www.vizictechnologies.com Vizic Technologies copyright 2014 */ /**************************************************************************************/ /**************************************************************************************/ #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(BAUD6); //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 } }