Vizic Technologies / Mbed 2 deprecated BounceBallMSG

Dependencies:   MINISMARTGPU mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*********************************************************
00002 VIZIC TECHNOLOGIES. COPYRIGHT 2012.
00003 THE DATASHEETS, SOFTWARE AND LIBRARIES ARE PROVIDED "AS IS." 
00004 VIZIC EXPRESSLY DISCLAIM ANY WARRANTY OF ANY KIND, WHETHER 
00005 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, THE IMPLIED 
00006 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
00007 OR NONINFRINGEMENT. IN NO EVENT SHALL VIZIC BE LIABLE FOR 
00008 ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES, 
00009 LOST PROFITS OR LOST DATA, HARM TO YOUR EQUIPMENT, COST OF 
00010 PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, 
00011 ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO 
00012 ANY DEFENCE THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION,
00013 OR OTHER SIMILAR COSTS.
00014 *********************************************************/
00015 /**************************************************************************************/
00016 /*MINI SMARTGPU intelligent embedded graphics processor unit
00017  those examples are for use the MINI SMARTGPU with the mbed microcontoller, just connect tx,rx,and reset
00018  Board:
00019  http://vizictechnologies.com/#/mini-smart-gpu/4566376187
00020  
00021  www.vizictechnologies.com 
00022  Vizic Technologies copyright 2012*/
00023 /**************************************************************************************/
00024 /**************************************************************************************/
00025  
00026 #include "mbed.h"
00027 #include "MINISMARTGPU.h"
00028 
00029 MINISMARTGPU lcd(p13,p14,p15);        //(TX,RX,Reset); Create Object "lcd"
00030 
00031 // defines for balls
00032 #define radiusBall1 7     //ball1 size
00033 #define colourBall1 RED    //ball1 colour
00034 
00035 //variables used by move ball method
00036 int speedBall1=2; //ball1 moving speed - amount of pixels that ball move each time
00037 int dirx1=1;      //xball1 initial positive direction
00038 int diry1=-1;     //yball1 initial negative direction
00039 int xBall1=80;    //x initial position of ball1
00040 int yBall1=60;    //y initial position of ball1
00041 
00042 /***************************************************/
00043 //Function that updates the current position of the ball1
00044 void moveBall1(){
00045    lcd.drawCircle(xBall1,yBall1,radiusBall1,BLACK,FILL);       // Erase previous ball position
00046    xBall1+=(dirx1*speedBall1);                                 // Calculate new x coordinate for ball1 
00047    yBall1+=(diry1*speedBall1);                                 // Calculate new y coordinate for ball1  
00048    lcd.drawCircle(xBall1,yBall1,radiusBall1,colourBall1,FILL); // Draw new ball position
00049    if((xBall1+speedBall1+radiusBall1)>158 | (xBall1-speedBall1-radiusBall1)<=1){           // if ball reaches the left or right corner, we invert moving direction 
00050     dirx1= dirx1*(-1);                                         // Invert the moving direction by multiplying by -1
00051    }
00052    if((yBall1+speedBall1+radiusBall1)>126 | (yBall1-speedBall1-radiusBall1)<=1){           // if ball reaches the top or bottom corner, we invert moving direction 
00053     diry1= diry1*(-1);                                         // Invert the moving direction by multiplying by -1
00054    }                       
00055 }
00056 
00057 /**********************************************************************************/
00058 /**********************************************************************************/
00059 /**********************************************************************************/
00060 int main() { 
00061   lcd.reset();                    //physically reset MINISMARTGPU
00062   lcd.start();                    //initialize the MINISMARTGPU processor
00063   wait_ms(200);
00064 
00065   lcd.baudChange(1000000); //set a fast baud! for fast drawing
00066   lcd.drawRectangle(0,0,159,127,YELLOW,UNFILL); //draw corners
00067   
00068   while(1){             // Loop forever
00069     moveBall1();        // move ball1
00070     wait_ms(15);          // wait a little
00071   }
00072 }