Simple Clock Demo - MBED + SmartGPU2 board

Dependencies:   SMARTGPU2 mbed

Committer:
emmanuelchio
Date:
Wed Jul 10 03:40:50 2013 +0000
Revision:
0:795e0e8e9cdc
Child:
1:4803259f24d3
Simple Clock Demo - MBED + SmartGPU2 board

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emmanuelchio 0:795e0e8e9cdc 1 /**************************************************************************************/
emmanuelchio 0:795e0e8e9cdc 2 /*SMARTGPU2 intelligent embedded graphics processor unit
emmanuelchio 0:795e0e8e9cdc 3 those examples are for use the SMARTGPU2 with the mbed microcontoller, just connect tx,rx,and reset
emmanuelchio 0:795e0e8e9cdc 4 Board:
emmanuelchio 0:795e0e8e9cdc 5 http://vizictechnologies.com/#/smart-gpu-2/4577779046
emmanuelchio 0:795e0e8e9cdc 6
emmanuelchio 0:795e0e8e9cdc 7 www.vizictechnologies.com
emmanuelchio 0:795e0e8e9cdc 8 Vizic Technologies copyright 2013 */
emmanuelchio 0:795e0e8e9cdc 9 /**************************************************************************************/
emmanuelchio 0:795e0e8e9cdc 10 /**************************************************************************************/
emmanuelchio 0:795e0e8e9cdc 11
emmanuelchio 0:795e0e8e9cdc 12 #include "mbed.h"
emmanuelchio 0:795e0e8e9cdc 13 #include "SMARTGPU2.h"
emmanuelchio 0:795e0e8e9cdc 14
emmanuelchio 0:795e0e8e9cdc 15 //we define a new structure of INT instead of UNSIGNED INT
emmanuelchio 0:795e0e8e9cdc 16 typedef struct {
emmanuelchio 0:795e0e8e9cdc 17 int x; //X axis
emmanuelchio 0:795e0e8e9cdc 18 int y; //Y axis
emmanuelchio 0:795e0e8e9cdc 19 } POINTINT; //to create a point with point.x and point.y variable
emmanuelchio 0:795e0e8e9cdc 20
emmanuelchio 0:795e0e8e9cdc 21 #define CLOCKBODYCOLOUR BLACK //colour for the body clock
emmanuelchio 0:795e0e8e9cdc 22 #define CLOCKEDGECOLOUR GREEN //colour for the edge of the clock
emmanuelchio 0:795e0e8e9cdc 23 #define SECCOL YELLOW //seconds hand colour
emmanuelchio 0:795e0e8e9cdc 24 #define MINCOL MAGENTA //minutes hand colour
emmanuelchio 0:795e0e8e9cdc 25 #define HOURCOL RED //hours hand colour
emmanuelchio 0:795e0e8e9cdc 26 #define HALFX LCD_WIDTH/2 //this point represent the x center of the clock where math is done
emmanuelchio 0:795e0e8e9cdc 27 #define HALFY LCD_HEIGHT/2 //this point represent the y center of the clock where math is done
emmanuelchio 0:795e0e8e9cdc 28
emmanuelchio 0:795e0e8e9cdc 29 SMARTGPU2 lcd(TXPIN,RXPIN,RESETPIN); //create our object called "lcd"
emmanuelchio 0:795e0e8e9cdc 30
emmanuelchio 0:795e0e8e9cdc 31 /***************************************************/
emmanuelchio 0:795e0e8e9cdc 32 /***************************************************/
emmanuelchio 0:795e0e8e9cdc 33 void initializeSmartGPU2(void){ //Initialize SMARTGPU2 Board
emmanuelchio 0:795e0e8e9cdc 34 lcd.reset(); //physically reset SMARTGPU2
emmanuelchio 0:795e0e8e9cdc 35 lcd.start(); //initialize the SMARTGPU2 processor
emmanuelchio 0:795e0e8e9cdc 36 }
emmanuelchio 0:795e0e8e9cdc 37
emmanuelchio 0:795e0e8e9cdc 38 /***************************************************/
emmanuelchio 0:795e0e8e9cdc 39 /***************************************************/
emmanuelchio 0:795e0e8e9cdc 40 /***************************************************/
emmanuelchio 0:795e0e8e9cdc 41 /***************************************************/
emmanuelchio 0:795e0e8e9cdc 42 int main() {
emmanuelchio 0:795e0e8e9cdc 43 POINTINT secP,minsP,hourP;
emmanuelchio 0:795e0e8e9cdc 44 AXIS updatedXPosition;
emmanuelchio 0:795e0e8e9cdc 45 int secs=15;
emmanuelchio 0:795e0e8e9cdc 46 int mins=45;
emmanuelchio 0:795e0e8e9cdc 47 int hours=2;
emmanuelchio 0:795e0e8e9cdc 48 int angleH,angleM,angleS;
emmanuelchio 0:795e0e8e9cdc 49 int handHour=75;//hand size
emmanuelchio 0:795e0e8e9cdc 50 int handMin=85;//hand size
emmanuelchio 0:795e0e8e9cdc 51 int handSec=95;//hand size
emmanuelchio 0:795e0e8e9cdc 52
emmanuelchio 0:795e0e8e9cdc 53 initializeSmartGPU2(); //Init communication with SmartGPU2 board
emmanuelchio 0:795e0e8e9cdc 54
emmanuelchio 0:795e0e8e9cdc 55 lcd.baudChange(BAUD7); //set a fast baud! for fast drawing
emmanuelchio 0:795e0e8e9cdc 56 lcd.drawCircle(160,120,110,CLOCKBODYCOLOUR,FILL); //draw clock body
emmanuelchio 0:795e0e8e9cdc 57 lcd.drawCircle(160,120,110,CLOCKEDGECOLOUR,UNFILL); //draw clock edge
emmanuelchio 0:795e0e8e9cdc 58
emmanuelchio 0:795e0e8e9cdc 59 //config strings
emmanuelchio 0:795e0e8e9cdc 60 lcd.setTextColour(CLOCKEDGECOLOUR);
emmanuelchio 0:795e0e8e9cdc 61 lcd.setTextSize(FONT5);
emmanuelchio 0:795e0e8e9cdc 62 lcd.setTextBackFill(TRANS);
emmanuelchio 0:795e0e8e9cdc 63
emmanuelchio 0:795e0e8e9cdc 64 while(1){
emmanuelchio 0:795e0e8e9cdc 65 //Do some Math to get the second point of the clock hands. (first point is always the center of the clock)
emmanuelchio 0:795e0e8e9cdc 66 angleS=secs*6; //get the current seconds in angle form, a circle have 360 degrees divided by 60 seconds = 6, then we multiply the 6 by the current seconds to get current angle
emmanuelchio 0:795e0e8e9cdc 67 secP.x=((sin((angleS*3.14)/180)) * handSec); //get X component of the second's hand
emmanuelchio 0:795e0e8e9cdc 68 secP.y=((cos((angleS*3.14)/180)) * handSec); //get Y component of the second's hand
emmanuelchio 0:795e0e8e9cdc 69 angleM=mins*6; //get the current minutes in angle form, a circle have 360 degrees divided by 60 minutes = 6, then we multiply the 6 by the current minutes to get current angle
emmanuelchio 0:795e0e8e9cdc 70 minsP.x=((sin((angleM*3.14)/180)) * handMin); //get X component of the minutes's hand
emmanuelchio 0:795e0e8e9cdc 71 minsP.y=((cos((angleM*3.14)/180)) * handMin); //get Y component of the minutes's hand
emmanuelchio 0:795e0e8e9cdc 72 angleH=hours*30; //get the current hours in angle form, a circle have 360 degrees divided by 12 hours = 30, then we multiply the 30 by the current hours to get current angle
emmanuelchio 0:795e0e8e9cdc 73 hourP.x=((sin((angleH*3.14)/180)) * handHour); //get X component of the hours's hand
emmanuelchio 0:795e0e8e9cdc 74 hourP.y=((cos((angleH*3.14)/180)) * handHour); //get Y component of the hours's hand
emmanuelchio 0:795e0e8e9cdc 75
emmanuelchio 0:795e0e8e9cdc 76 lcd.putLetter(146,22,'1',&updatedXPosition); //Draw the 1
emmanuelchio 0:795e0e8e9cdc 77 lcd.putLetter(updatedXPosition,22,'2',&updatedXPosition); //Draw the 2
emmanuelchio 0:795e0e8e9cdc 78
emmanuelchio 0:795e0e8e9cdc 79 //Draw current time hands
emmanuelchio 0:795e0e8e9cdc 80 lcd.drawLine(HALFX,HALFY,HALFX+minsP.x,HALFY-minsP.y,MINCOL); // Draw the minutes hand, first point is the center of the clock, and the second is the point obtained by doing math
emmanuelchio 0:795e0e8e9cdc 81 lcd.drawLine(HALFX,HALFY,HALFX+hourP.x,HALFY-hourP.y,HOURCOL); // Draw the hours hand, first point is the center of the clock, and the second is the point obtained by doing math
emmanuelchio 0:795e0e8e9cdc 82 lcd.drawLine(HALFX,HALFY,HALFX+secP.x,HALFY-secP.y,SECCOL); // Draw the seconds hand, first point is the center of the clock, and the second is the point obtained by doing math
emmanuelchio 0:795e0e8e9cdc 83 lcd.drawCircle(HALFX,HALFY,5,SECCOL,FILL); // Draw the center of the second's hand
emmanuelchio 0:795e0e8e9cdc 84
emmanuelchio 0:795e0e8e9cdc 85 wait_ms(1000); // wait for one second delay (we dont need to explain why we're waiting one second, right?)
emmanuelchio 0:795e0e8e9cdc 86
emmanuelchio 0:795e0e8e9cdc 87 secs++; // increase seconds
emmanuelchio 0:795e0e8e9cdc 88 if(secs==60){ // if we reach 60 seconds
emmanuelchio 0:795e0e8e9cdc 89 mins++; // increase the minutes
emmanuelchio 0:795e0e8e9cdc 90 if(mins==60){ // if we reach 60 minutes
emmanuelchio 0:795e0e8e9cdc 91 hours++; // increase the minutes
emmanuelchio 0:795e0e8e9cdc 92 if(hours==12){ // if we reach 12 hours
emmanuelchio 0:795e0e8e9cdc 93 hours=0; // clear hours
emmanuelchio 0:795e0e8e9cdc 94 }
emmanuelchio 0:795e0e8e9cdc 95 mins=0; // clear minutes
emmanuelchio 0:795e0e8e9cdc 96 }
emmanuelchio 0:795e0e8e9cdc 97 secs=0; // clear seconds
emmanuelchio 0:795e0e8e9cdc 98 }
emmanuelchio 0:795e0e8e9cdc 99
emmanuelchio 0:795e0e8e9cdc 100 //Erase all hands
emmanuelchio 0:795e0e8e9cdc 101 lcd.drawLine(HALFX,HALFY,HALFX+secP.x,HALFY-secP.y,CLOCKBODYCOLOUR); // Erase Second's hand
emmanuelchio 0:795e0e8e9cdc 102 lcd.drawLine(HALFX,HALFY,HALFX+minsP.x,HALFY-minsP.y,CLOCKBODYCOLOUR); // Erase Minute's hand
emmanuelchio 0:795e0e8e9cdc 103 lcd.drawLine(HALFX,HALFY,HALFX+hourP.x,HALFY-hourP.y,CLOCKBODYCOLOUR); // Erase Hour's hand
emmanuelchio 0:795e0e8e9cdc 104 }
emmanuelchio 0:795e0e8e9cdc 105 }