![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Simple Clock Demo - MBED + SmartGPU2 board
main.cpp@3:05e0e61ebf24, 2014-04-18 (annotated)
- Committer:
- emmanuelchio
- Date:
- Fri Apr 18 00:41:37 2014 +0000
- Revision:
- 3:05e0e61ebf24
- Parent:
- 2:22fecf4cd6a1
SmartGPU2 SimpleClock_SG2 demo- Please select(uncomment) your smartGPU2 board under SMARTGPU2.h file before compiling!!!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emmanuelchio | 1:4803259f24d3 | 1 | /**************************************************************************************/ |
emmanuelchio | 0:795e0e8e9cdc | 2 | /**************************************************************************************/ |
emmanuelchio | 0:795e0e8e9cdc | 3 | /*SMARTGPU2 intelligent embedded graphics processor unit |
emmanuelchio | 1:4803259f24d3 | 4 | those examples are for using the SMARTGPU2 with the mbed microcontoller, just connect tx,rx,and reset |
emmanuelchio | 0:795e0e8e9cdc | 5 | Board: |
emmanuelchio | 1:4803259f24d3 | 6 | http://www.vizictechnologies.com/ |
emmanuelchio | 0:795e0e8e9cdc | 7 | |
emmanuelchio | 0:795e0e8e9cdc | 8 | www.vizictechnologies.com |
emmanuelchio | 1:4803259f24d3 | 9 | Vizic Technologies copyright 2014 */ |
emmanuelchio | 0:795e0e8e9cdc | 10 | /**************************************************************************************/ |
emmanuelchio | 0:795e0e8e9cdc | 11 | /**************************************************************************************/ |
emmanuelchio | 0:795e0e8e9cdc | 12 | |
emmanuelchio | 0:795e0e8e9cdc | 13 | #include "mbed.h" |
emmanuelchio | 0:795e0e8e9cdc | 14 | #include "SMARTGPU2.h" |
emmanuelchio | 0:795e0e8e9cdc | 15 | |
emmanuelchio | 0:795e0e8e9cdc | 16 | //we define a new structure of INT instead of UNSIGNED INT |
emmanuelchio | 0:795e0e8e9cdc | 17 | typedef struct { |
emmanuelchio | 0:795e0e8e9cdc | 18 | int x; //X axis |
emmanuelchio | 0:795e0e8e9cdc | 19 | int y; //Y axis |
emmanuelchio | 0:795e0e8e9cdc | 20 | } POINTINT; //to create a point with point.x and point.y variable |
emmanuelchio | 0:795e0e8e9cdc | 21 | |
emmanuelchio | 0:795e0e8e9cdc | 22 | #define CLOCKBODYCOLOUR BLACK //colour for the body clock |
emmanuelchio | 0:795e0e8e9cdc | 23 | #define CLOCKEDGECOLOUR GREEN //colour for the edge of the clock |
emmanuelchio | 0:795e0e8e9cdc | 24 | #define SECCOL YELLOW //seconds hand colour |
emmanuelchio | 0:795e0e8e9cdc | 25 | #define MINCOL MAGENTA //minutes hand colour |
emmanuelchio | 0:795e0e8e9cdc | 26 | #define HOURCOL RED //hours hand colour |
emmanuelchio | 0:795e0e8e9cdc | 27 | #define HALFX LCD_WIDTH/2 //this point represent the x center of the clock where math is done |
emmanuelchio | 0:795e0e8e9cdc | 28 | #define HALFY LCD_HEIGHT/2 //this point represent the y center of the clock where math is done |
emmanuelchio | 0:795e0e8e9cdc | 29 | |
emmanuelchio | 0:795e0e8e9cdc | 30 | SMARTGPU2 lcd(TXPIN,RXPIN,RESETPIN); //create our object called "lcd" |
emmanuelchio | 0:795e0e8e9cdc | 31 | |
emmanuelchio | 0:795e0e8e9cdc | 32 | /***************************************************/ |
emmanuelchio | 0:795e0e8e9cdc | 33 | /***************************************************/ |
emmanuelchio | 0:795e0e8e9cdc | 34 | void initializeSmartGPU2(void){ //Initialize SMARTGPU2 Board |
emmanuelchio | 0:795e0e8e9cdc | 35 | lcd.reset(); //physically reset SMARTGPU2 |
emmanuelchio | 0:795e0e8e9cdc | 36 | lcd.start(); //initialize the SMARTGPU2 processor |
emmanuelchio | 0:795e0e8e9cdc | 37 | } |
emmanuelchio | 0:795e0e8e9cdc | 38 | |
emmanuelchio | 0:795e0e8e9cdc | 39 | /***************************************************/ |
emmanuelchio | 0:795e0e8e9cdc | 40 | /***************************************************/ |
emmanuelchio | 0:795e0e8e9cdc | 41 | /***************************************************/ |
emmanuelchio | 0:795e0e8e9cdc | 42 | /***************************************************/ |
emmanuelchio | 0:795e0e8e9cdc | 43 | int main() { |
emmanuelchio | 0:795e0e8e9cdc | 44 | POINTINT secP,minsP,hourP; |
emmanuelchio | 0:795e0e8e9cdc | 45 | AXIS updatedXPosition; |
emmanuelchio | 0:795e0e8e9cdc | 46 | int secs=15; |
emmanuelchio | 0:795e0e8e9cdc | 47 | int mins=45; |
emmanuelchio | 0:795e0e8e9cdc | 48 | int hours=2; |
emmanuelchio | 0:795e0e8e9cdc | 49 | int angleH,angleM,angleS; |
emmanuelchio | 0:795e0e8e9cdc | 50 | int handHour=75;//hand size |
emmanuelchio | 0:795e0e8e9cdc | 51 | int handMin=85;//hand size |
emmanuelchio | 0:795e0e8e9cdc | 52 | int handSec=95;//hand size |
emmanuelchio | 0:795e0e8e9cdc | 53 | |
emmanuelchio | 0:795e0e8e9cdc | 54 | initializeSmartGPU2(); //Init communication with SmartGPU2 board |
emmanuelchio | 0:795e0e8e9cdc | 55 | |
emmanuelchio | 0:795e0e8e9cdc | 56 | lcd.baudChange(BAUD7); //set a fast baud! for fast drawing |
emmanuelchio | 3:05e0e61ebf24 | 57 | lcd.drawCircle(HALFX,HALFY,HALFY-5,CLOCKBODYCOLOUR,FILL); //draw clock body |
emmanuelchio | 3:05e0e61ebf24 | 58 | lcd.drawCircle(HALFX,HALFY,HALFY-5,CLOCKEDGECOLOUR,UNFILL); //draw clock edge |
emmanuelchio | 0:795e0e8e9cdc | 59 | |
emmanuelchio | 0:795e0e8e9cdc | 60 | //config strings |
emmanuelchio | 0:795e0e8e9cdc | 61 | lcd.setTextColour(CLOCKEDGECOLOUR); |
emmanuelchio | 0:795e0e8e9cdc | 62 | lcd.setTextSize(FONT5); |
emmanuelchio | 0:795e0e8e9cdc | 63 | lcd.setTextBackFill(TRANS); |
emmanuelchio | 0:795e0e8e9cdc | 64 | |
emmanuelchio | 0:795e0e8e9cdc | 65 | while(1){ |
emmanuelchio | 0:795e0e8e9cdc | 66 | //Do some Math to get the second point of the clock hands. (first point is always the center of the clock) |
emmanuelchio | 0:795e0e8e9cdc | 67 | 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 | 68 | secP.x=((sin((angleS*3.14)/180)) * handSec); //get X component of the second's hand |
emmanuelchio | 0:795e0e8e9cdc | 69 | secP.y=((cos((angleS*3.14)/180)) * handSec); //get Y component of the second's hand |
emmanuelchio | 0:795e0e8e9cdc | 70 | 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 | 71 | minsP.x=((sin((angleM*3.14)/180)) * handMin); //get X component of the minutes's hand |
emmanuelchio | 0:795e0e8e9cdc | 72 | minsP.y=((cos((angleM*3.14)/180)) * handMin); //get Y component of the minutes's hand |
emmanuelchio | 0:795e0e8e9cdc | 73 | 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 | 74 | hourP.x=((sin((angleH*3.14)/180)) * handHour); //get X component of the hours's hand |
emmanuelchio | 0:795e0e8e9cdc | 75 | hourP.y=((cos((angleH*3.14)/180)) * handHour); //get Y component of the hours's hand |
emmanuelchio | 0:795e0e8e9cdc | 76 | |
emmanuelchio | 2:22fecf4cd6a1 | 77 | lcd.putLetter(HALFX-20,22,'1',&updatedXPosition); //Draw the 1 |
emmanuelchio | 0:795e0e8e9cdc | 78 | lcd.putLetter(updatedXPosition,22,'2',&updatedXPosition); //Draw the 2 |
emmanuelchio | 0:795e0e8e9cdc | 79 | |
emmanuelchio | 0:795e0e8e9cdc | 80 | //Draw current time hands |
emmanuelchio | 0:795e0e8e9cdc | 81 | 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 | 82 | 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 | 83 | 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 | 84 | lcd.drawCircle(HALFX,HALFY,5,SECCOL,FILL); // Draw the center of the second's hand |
emmanuelchio | 0:795e0e8e9cdc | 85 | |
emmanuelchio | 0:795e0e8e9cdc | 86 | wait_ms(1000); // wait for one second delay (we dont need to explain why we're waiting one second, right?) |
emmanuelchio | 0:795e0e8e9cdc | 87 | |
emmanuelchio | 0:795e0e8e9cdc | 88 | secs++; // increase seconds |
emmanuelchio | 0:795e0e8e9cdc | 89 | if(secs==60){ // if we reach 60 seconds |
emmanuelchio | 0:795e0e8e9cdc | 90 | mins++; // increase the minutes |
emmanuelchio | 0:795e0e8e9cdc | 91 | if(mins==60){ // if we reach 60 minutes |
emmanuelchio | 0:795e0e8e9cdc | 92 | hours++; // increase the minutes |
emmanuelchio | 0:795e0e8e9cdc | 93 | if(hours==12){ // if we reach 12 hours |
emmanuelchio | 0:795e0e8e9cdc | 94 | hours=0; // clear hours |
emmanuelchio | 0:795e0e8e9cdc | 95 | } |
emmanuelchio | 0:795e0e8e9cdc | 96 | mins=0; // clear minutes |
emmanuelchio | 0:795e0e8e9cdc | 97 | } |
emmanuelchio | 0:795e0e8e9cdc | 98 | secs=0; // clear seconds |
emmanuelchio | 0:795e0e8e9cdc | 99 | } |
emmanuelchio | 0:795e0e8e9cdc | 100 | |
emmanuelchio | 0:795e0e8e9cdc | 101 | //Erase all hands |
emmanuelchio | 0:795e0e8e9cdc | 102 | lcd.drawLine(HALFX,HALFY,HALFX+secP.x,HALFY-secP.y,CLOCKBODYCOLOUR); // Erase Second's hand |
emmanuelchio | 0:795e0e8e9cdc | 103 | lcd.drawLine(HALFX,HALFY,HALFX+minsP.x,HALFY-minsP.y,CLOCKBODYCOLOUR); // Erase Minute's hand |
emmanuelchio | 0:795e0e8e9cdc | 104 | lcd.drawLine(HALFX,HALFY,HALFX+hourP.x,HALFY-hourP.y,CLOCKBODYCOLOUR); // Erase Hour's hand |
emmanuelchio | 0:795e0e8e9cdc | 105 | } |
emmanuelchio | 0:795e0e8e9cdc | 106 | } |