SMARTGPU nice clock! Be sure to load the image to the micro SD card first!

Dependencies:   SMARTGPU mbed

Committer:
emmanuelchio
Date:
Wed Sep 14 05:33:20 2011 +0000
Revision:
0:482b06fffa48
Rev 1.0

Who changed what in which revision?

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