SMARTGPU simple clock application demo

Dependencies:   SMARTGPU mbed

Committer:
emmanuelchio
Date:
Wed Sep 14 05:37:02 2011 +0000
Revision:
0:4064cd132bad
Rev 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emmanuelchio 0:4064cd132bad 1 /**************************************************************************************/
emmanuelchio 0:4064cd132bad 2 /*SMARTGPU intelligent embedded graphics processor unit
emmanuelchio 0:4064cd132bad 3 those examples are for use the SMARTGPU with the mbed microcontoller, just connect tx,rx,and reset
emmanuelchio 0:4064cd132bad 4 Board:
emmanuelchio 0:4064cd132bad 5 http://www.vizictechnologies.com/#/desarrollo/4554296549
emmanuelchio 0:4064cd132bad 6
emmanuelchio 0:4064cd132bad 7 This example requires pre-loaded content to the micro SD card, images and text files!
emmanuelchio 0:4064cd132bad 8
emmanuelchio 0:4064cd132bad 9 www.vizictechnologies.com
emmanuelchio 0:4064cd132bad 10 Vizic Technologies copyright 2011 */
emmanuelchio 0:4064cd132bad 11 /**************************************************************************************/
emmanuelchio 0:4064cd132bad 12 /**************************************************************************************/
emmanuelchio 0:4064cd132bad 13
emmanuelchio 0:4064cd132bad 14 #include "mbed.h"
emmanuelchio 0:4064cd132bad 15 #include "SMARTGPU.h"
emmanuelchio 0:4064cd132bad 16
emmanuelchio 0:4064cd132bad 17 //Clock definitions
emmanuelchio 0:4064cd132bad 18 #define clockBodyCol BLACK //colour for the body clock
emmanuelchio 0:4064cd132bad 19 #define clockEdgeCol GREEN //colour for the edge of the clock
emmanuelchio 0:4064cd132bad 20 #define secCol YELLOW //seconds hand colour
emmanuelchio 0:4064cd132bad 21 #define minCol MAGENTA //minutes hand colour
emmanuelchio 0:4064cd132bad 22 #define hourCol RED //hours hand colour
emmanuelchio 0:4064cd132bad 23 #define halfx 160 //this point represent the x center of the clock where math is done
emmanuelchio 0:4064cd132bad 24 #define halfy 120 //this point represent the y center of the clock where math is done
emmanuelchio 0:4064cd132bad 25
emmanuelchio 0:4064cd132bad 26
emmanuelchio 0:4064cd132bad 27 SMARTGPU lcd(p13,p14,p15); //(TX,RX,Reset);
emmanuelchio 0:4064cd132bad 28
emmanuelchio 0:4064cd132bad 29
emmanuelchio 0:4064cd132bad 30 int main() {
emmanuelchio 0:4064cd132bad 31 lcd.reset(); //physically reset SMARTGPU
emmanuelchio 0:4064cd132bad 32 lcd.start(); //initialize the SMARTGPU processor
emmanuelchio 0:4064cd132bad 33
emmanuelchio 0:4064cd132bad 34 int secs=15;
emmanuelchio 0:4064cd132bad 35 int mins=48;
emmanuelchio 0:4064cd132bad 36 int hours=2;
emmanuelchio 0:4064cd132bad 37 int xs,ys,xm,ym,xh,yh;
emmanuelchio 0:4064cd132bad 38 int angleH,angleM,angleS;
emmanuelchio 0:4064cd132bad 39 int handHour=75;//hand size
emmanuelchio 0:4064cd132bad 40 int handMin=85;//hand size
emmanuelchio 0:4064cd132bad 41 int handSec=95;//hand size
emmanuelchio 0:4064cd132bad 42
emmanuelchio 0:4064cd132bad 43 lcd.baudChange(1000000); //set high baud for fast drawing
emmanuelchio 0:4064cd132bad 44 lcd.drawCircle(160,120,110,clockBodyCol,FILL); //draw clock body
emmanuelchio 0:4064cd132bad 45 lcd.drawCircle(160,120,110,clockEdgeCol,UNFILL); //draw clock edge
emmanuelchio 0:4064cd132bad 46
emmanuelchio 0:4064cd132bad 47 while(1){
emmanuelchio 0:4064cd132bad 48 //Do some Math to get the second point of the clock hands. (first point is always the center of the clock)
emmanuelchio 0:4064cd132bad 49 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:4064cd132bad 50 xs=(sin((angleS*3.14)/180)) * handSec; //get X component of the second's hand
emmanuelchio 0:4064cd132bad 51 ys=(cos((angleS*3.14)/180)) * handSec; //get Y component of the second's hand
emmanuelchio 0:4064cd132bad 52 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:4064cd132bad 53 xm=(sin((angleM*3.14)/180)) * handMin; //get X component of the minutes's hand
emmanuelchio 0:4064cd132bad 54 ym=(cos((angleM*3.14)/180)) * handMin; //get Y component of the minutes's hand
emmanuelchio 0:4064cd132bad 55 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:4064cd132bad 56 xh=(sin((angleH*3.14)/180)) * handHour; //get X component of the hours's hand
emmanuelchio 0:4064cd132bad 57 yh=(cos((angleH*3.14)/180)) * handHour; //get Y component of the hours's hand
emmanuelchio 0:4064cd132bad 58
emmanuelchio 0:4064cd132bad 59 lcd.putLetter(146,22,clockEdgeCol,FONT5,TRANS,'1'); //Draw the 1
emmanuelchio 0:4064cd132bad 60 lcd.putLetter(162,22,clockEdgeCol,FONT5,TRANS,'2'); //Draw the 2
emmanuelchio 0:4064cd132bad 61
emmanuelchio 0:4064cd132bad 62 //Draw current time hands
emmanuelchio 0:4064cd132bad 63 lcd.drawLine(halfx,halfy,halfx+xm,halfy-ym,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:4064cd132bad 64 lcd.drawLine(halfx,halfy,halfx+xh,halfy-yh,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:4064cd132bad 65 lcd.drawLine(halfx,halfy,halfx+xs,halfy-ys,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:4064cd132bad 66 lcd.drawCircle(halfx,halfy,5,secCol,FILL); // Draw the center of the second's hand
emmanuelchio 0:4064cd132bad 67
emmanuelchio 0:4064cd132bad 68 wait_ms(1000); // wait for one second (we dont need to explain why we're waiting one second, right?)
emmanuelchio 0:4064cd132bad 69
emmanuelchio 0:4064cd132bad 70 secs++; // increase seconds
emmanuelchio 0:4064cd132bad 71 if(secs==60){ // if we reach 60 seconds
emmanuelchio 0:4064cd132bad 72 mins++; // increase the minutes
emmanuelchio 0:4064cd132bad 73 if(mins==60){ // if we reach 60 minutes
emmanuelchio 0:4064cd132bad 74 hours++; // increase the minutes
emmanuelchio 0:4064cd132bad 75 if(hours==12){ // if we reach 12 hours
emmanuelchio 0:4064cd132bad 76 hours=0; // clear hours
emmanuelchio 0:4064cd132bad 77 }
emmanuelchio 0:4064cd132bad 78 mins=0; // clear minutes
emmanuelchio 0:4064cd132bad 79 }
emmanuelchio 0:4064cd132bad 80 secs=0; // clear seconds
emmanuelchio 0:4064cd132bad 81 }
emmanuelchio 0:4064cd132bad 82
emmanuelchio 0:4064cd132bad 83 //Erase all hands
emmanuelchio 0:4064cd132bad 84 lcd.drawLine(halfx,halfy,halfx+xs,halfy-ys,clockBodyCol); // Erase Second's hand
emmanuelchio 0:4064cd132bad 85 lcd.drawLine(halfx,halfy,halfx+xm,halfy-ym,clockBodyCol); // Erase Minute's hand
emmanuelchio 0:4064cd132bad 86 lcd.drawLine(halfx,halfy,halfx+xh,halfy-yh,clockBodyCol); // Erase Hour's hand
emmanuelchio 0:4064cd132bad 87 }
emmanuelchio 0:4064cd132bad 88 }