SMARTGPU simple clock application demo

Dependencies:   SMARTGPU mbed

main.cpp

Committer:
emmanuelchio
Date:
2011-09-14
Revision:
0:4064cd132bad

File content as of revision 0:4064cd132bad:

/**************************************************************************************/
/*SMARTGPU intelligent embedded graphics processor unit
 those examples are for use the SMARTGPU with the mbed microcontoller, just connect tx,rx,and reset
 Board:
 http://www.vizictechnologies.com/#/desarrollo/4554296549
 
 This example requires pre-loaded content to the micro SD card, images and text files!
 
 www.vizictechnologies.com 
 Vizic Technologies copyright 2011 */
/**************************************************************************************/
/**************************************************************************************/
 
#include "mbed.h"
#include "SMARTGPU.h"

//Clock definitions
#define clockBodyCol  BLACK    //colour for the body clock
#define clockEdgeCol  GREEN    //colour for the edge of the clock
#define secCol        YELLOW   //seconds hand colour
#define minCol        MAGENTA  //minutes hand colour
#define hourCol       RED      //hours hand colour
#define halfx         160      //this point represent the x center of the clock where math is done
#define halfy         120      //this point represent the y center of the clock where math is done


SMARTGPU lcd(p13,p14,p15);        //(TX,RX,Reset);


int main() { 
  lcd.reset();                    //physically reset SMARTGPU
  lcd.start();                    //initialize the SMARTGPU processor
 
  int secs=15;
  int mins=48;
  int hours=2;
  int xs,ys,xm,ym,xh,yh;
  int angleH,angleM,angleS;
  int handHour=75;//hand size
  int handMin=85;//hand size
  int handSec=95;//hand size  
  
  lcd.baudChange(1000000);                          //set high baud for fast drawing
  lcd.drawCircle(160,120,110,clockBodyCol,FILL);    //draw clock body
  lcd.drawCircle(160,120,110,clockEdgeCol,UNFILL);  //draw clock edge
  
 while(1){
  //Do some Math to get the second point of the clock hands. (first point is always the center of the clock)
  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
  xs=(sin((angleS*3.14)/180)) * handSec;   //get X component of the second's hand
  ys=(cos((angleS*3.14)/180)) * handSec;   //get Y component of the second's hand
  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
  xm=(sin((angleM*3.14)/180)) * handMin;   //get X component of the minutes's hand
  ym=(cos((angleM*3.14)/180)) * handMin;   //get Y component of the minutes's hand 
  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
  xh=(sin((angleH*3.14)/180)) * handHour;  //get X component of the hours's hand
  yh=(cos((angleH*3.14)/180)) * handHour;  //get Y component of the hours's hand
    
  lcd.putLetter(146,22,clockEdgeCol,FONT5,TRANS,'1');  //Draw the 1                                 
  lcd.putLetter(162,22,clockEdgeCol,FONT5,TRANS,'2');  //Draw the 2  
  
  //Draw current time hands  
  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
  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
  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
  lcd.drawCircle(halfx,halfy,5,secCol,FILL);           // Draw the center of the second's hand
  
  wait_ms(1000);                                  // wait for one second (we dont need to explain why we're waiting one second, right?)

  secs++;                                         // increase seconds
  if(secs==60){                                   // if we reach 60 seconds
    mins++;                                       // increase the minutes
    if(mins==60){                                 // if we reach 60 minutes
      hours++;                                    // increase the minutes
      if(hours==12){                              // if we reach 12 hours
        hours=0;                                  // clear hours
      } 
      mins=0;                                     // clear minutes
    }            
    secs=0;                                       // clear seconds
  }                      
 
  //Erase all hands         
  lcd.drawLine(halfx,halfy,halfx+xs,halfy-ys,clockBodyCol); // Erase Second's hand
  lcd.drawLine(halfx,halfy,halfx+xm,halfy-ym,clockBodyCol); // Erase Minute's hand
  lcd.drawLine(halfx,halfy,halfx+xh,halfy-yh,clockBodyCol); // Erase Hour's hand            
 }
}