SMARTGPU bounce ball demo

Dependencies:   SMARTGPU mbed

Committer:
emmanuelchio
Date:
Wed Sep 14 05:31:16 2011 +0000
Revision:
0:d36fc6fb6704
Rev 1.0

Who changed what in which revision?

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