Bounce Ball Demo- MBED + SmartGPU2 board

Dependencies:   SMARTGPU2 mbed

Committer:
emmanuelchio
Date:
Wed Jul 10 03:25:24 2013 +0000
Revision:
0:4c26cabd36d5
Child:
1:507c7564ece2
Bounce Ball Demo - MBED + SmartGPU2 board

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emmanuelchio 0:4c26cabd36d5 1 /**************************************************************************************/
emmanuelchio 0:4c26cabd36d5 2 /*SMARTGPU2 intelligent embedded graphics processor unit
emmanuelchio 0:4c26cabd36d5 3 those examples are for use the SMARTGPU2 with the mbed microcontoller, just connect tx,rx,and reset
emmanuelchio 0:4c26cabd36d5 4 Board:
emmanuelchio 0:4c26cabd36d5 5 http://vizictechnologies.com/#/smart-gpu-2/4577779046
emmanuelchio 0:4c26cabd36d5 6
emmanuelchio 0:4c26cabd36d5 7 www.vizictechnologies.com
emmanuelchio 0:4c26cabd36d5 8 Vizic Technologies copyright 2013 */
emmanuelchio 0:4c26cabd36d5 9 /**************************************************************************************/
emmanuelchio 0:4c26cabd36d5 10 /**************************************************************************************/
emmanuelchio 0:4c26cabd36d5 11
emmanuelchio 0:4c26cabd36d5 12 #include "mbed.h"
emmanuelchio 0:4c26cabd36d5 13 #include "SMARTGPU2.h"
emmanuelchio 0:4c26cabd36d5 14
emmanuelchio 0:4c26cabd36d5 15 // defines for balls
emmanuelchio 0:4c26cabd36d5 16 #define RADIUSBALL1 15 //ball1 size
emmanuelchio 0:4c26cabd36d5 17 #define COLOURBALL1 RED //ball1 colour
emmanuelchio 0:4c26cabd36d5 18
emmanuelchio 0:4c26cabd36d5 19 //variables used by move ball method
emmanuelchio 0:4c26cabd36d5 20 int speedBall1=3; //ball1 moving speed - amount of pixels that ball move each time
emmanuelchio 0:4c26cabd36d5 21 int dirx1=1; //xball1 initial positive direction
emmanuelchio 0:4c26cabd36d5 22 int diry1=-1; //yball1 initial negative direction
emmanuelchio 0:4c26cabd36d5 23 int xBall1=300; //x initial position of ball1
emmanuelchio 0:4c26cabd36d5 24 int yBall1=100; //y initial position of ball1
emmanuelchio 0:4c26cabd36d5 25
emmanuelchio 0:4c26cabd36d5 26 SMARTGPU2 lcd(TXPIN,RXPIN,RESETPIN); //create our object called "lcd"
emmanuelchio 0:4c26cabd36d5 27
emmanuelchio 0:4c26cabd36d5 28 /***************************************************/
emmanuelchio 0:4c26cabd36d5 29 //Function that updates the current position of the ball1
emmanuelchio 0:4c26cabd36d5 30 void moveBall1(){
emmanuelchio 0:4c26cabd36d5 31 lcd.drawCircle(xBall1,yBall1,RADIUSBALL1,BLACK,FILL); // Erase previous ball position
emmanuelchio 0:4c26cabd36d5 32 xBall1+=(dirx1*speedBall1); // Calculate new x coordinate for ball1
emmanuelchio 0:4c26cabd36d5 33 yBall1+=(diry1*speedBall1); // Calculate new y coordinate for ball1
emmanuelchio 0:4c26cabd36d5 34 lcd.drawCircle(xBall1,yBall1,RADIUSBALL1,COLOURBALL1,FILL); // Draw new ball position
emmanuelchio 0:4c26cabd36d5 35 if((xBall1+speedBall1+RADIUSBALL1)>318 | (xBall1-speedBall1-RADIUSBALL1)<=1){ // if ball reaches the left or right corner, we invert moving direction
emmanuelchio 0:4c26cabd36d5 36 dirx1= dirx1*(-1); // Invert the moving direction by multiplying by -1
emmanuelchio 0:4c26cabd36d5 37 }
emmanuelchio 0:4c26cabd36d5 38 if((yBall1+speedBall1+RADIUSBALL1)>238 | (yBall1-speedBall1-RADIUSBALL1)<=1){ // if ball reaches the top or bottom corner, we invert moving direction
emmanuelchio 0:4c26cabd36d5 39 diry1= diry1*(-1); // Invert the moving direction by multiplying by -1
emmanuelchio 0:4c26cabd36d5 40 }
emmanuelchio 0:4c26cabd36d5 41 }
emmanuelchio 0:4c26cabd36d5 42
emmanuelchio 0:4c26cabd36d5 43 /***************************************************/
emmanuelchio 0:4c26cabd36d5 44 /***************************************************/
emmanuelchio 0:4c26cabd36d5 45 void initializeSmartGPU2(void){ //Initialize SMARTGPU2 Board
emmanuelchio 0:4c26cabd36d5 46 lcd.reset(); //physically reset SMARTGPU2
emmanuelchio 0:4c26cabd36d5 47 lcd.start(); //initialize the SMARTGPU2 processor
emmanuelchio 0:4c26cabd36d5 48 }
emmanuelchio 0:4c26cabd36d5 49
emmanuelchio 0:4c26cabd36d5 50 /***************************************************/
emmanuelchio 0:4c26cabd36d5 51 /***************************************************/
emmanuelchio 0:4c26cabd36d5 52 /***************************************************/
emmanuelchio 0:4c26cabd36d5 53 /***************************************************/
emmanuelchio 0:4c26cabd36d5 54 int main() {
emmanuelchio 0:4c26cabd36d5 55
emmanuelchio 0:4c26cabd36d5 56 initializeSmartGPU2(); //Init communication with SmartGPU2 board
emmanuelchio 0:4c26cabd36d5 57
emmanuelchio 0:4c26cabd36d5 58 lcd.baudChange(BAUD7); //set a fast baud! for fast drawing
emmanuelchio 0:4c26cabd36d5 59 lcd.drawRectangle(0,0,319,239,YELLOW,UNFILL); //draw corners
emmanuelchio 0:4c26cabd36d5 60
emmanuelchio 0:4c26cabd36d5 61 while(1){ // Loop forever
emmanuelchio 0:4c26cabd36d5 62 moveBall1(); // move ball1
emmanuelchio 0:4c26cabd36d5 63 wait_ms(15); // wait a little
emmanuelchio 0:4c26cabd36d5 64 }
emmanuelchio 0:4c26cabd36d5 65 }