SMARTGPU windows like application demo with touch Be sure to load images to the micro SD card first!

Dependencies:   SMARTGPU mbed

Committer:
emmanuelchio
Date:
Wed Sep 14 05:37:48 2011 +0000
Revision:
0:cfce61ec00c6
Rev 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emmanuelchio 0:cfce61ec00c6 1 /**************************************************************************************/
emmanuelchio 0:cfce61ec00c6 2 /*SMARTGPU intelligent embedded graphics processor unit
emmanuelchio 0:cfce61ec00c6 3 those examples are for use the SMARTGPU with the mbed microcontoller, just connect tx,rx,and reset
emmanuelchio 0:cfce61ec00c6 4 Board:
emmanuelchio 0:cfce61ec00c6 5 http://www.vizictechnologies.com/#/desarrollo/4554296549
emmanuelchio 0:cfce61ec00c6 6
emmanuelchio 0:cfce61ec00c6 7 This example requires pre-loaded content to the micro SD card, images!
emmanuelchio 0:cfce61ec00c6 8
emmanuelchio 0:cfce61ec00c6 9 www.vizictechnologies.com
emmanuelchio 0:cfce61ec00c6 10 Vizic Technologies copyright 2011 */
emmanuelchio 0:cfce61ec00c6 11 /**************************************************************************************/
emmanuelchio 0:cfce61ec00c6 12 /**************************************************************************************/
emmanuelchio 0:cfce61ec00c6 13
emmanuelchio 0:cfce61ec00c6 14 #include "mbed.h"
emmanuelchio 0:cfce61ec00c6 15 #include "SMARTGPU.h"
emmanuelchio 0:cfce61ec00c6 16
emmanuelchio 0:cfce61ec00c6 17 SMARTGPU lcd(p13,p14,p15); //(TX,RX,Reset);
emmanuelchio 0:cfce61ec00c6 18
emmanuelchio 0:cfce61ec00c6 19 //Each time we use the touchscreen we must define a int array that stores the X and Y readed or touched coordinates.
emmanuelchio 0:cfce61ec00c6 20 int touch[2];
emmanuelchio 0:cfce61ec00c6 21 //Each time we use the touchicon we must define a char array that stores the name of the touched icon.
emmanuelchio 0:cfce61ec00c6 22 char icon[3];
emmanuelchio 0:cfce61ec00c6 23
emmanuelchio 0:cfce61ec00c6 24 char pixelArray[3]; //Array to store the RGB888 pixel obtained with memoryRead()
emmanuelchio 0:cfce61ec00c6 25
emmanuelchio 0:cfce61ec00c6 26
emmanuelchio 0:cfce61ec00c6 27 /**************************************************/
emmanuelchio 0:cfce61ec00c6 28 //Funcion to convert a 3 byte array to an int RGB565
emmanuelchio 0:cfce61ec00c6 29 int RGB888ToRGB565(char pixBuffer[]){ //get an array of 3 bytes( red, green, blue), and convert them to RGB565 returned in an int
emmanuelchio 0:cfce61ec00c6 30 unsigned char R,G,B;
emmanuelchio 0:cfce61ec00c6 31 unsigned int col;
emmanuelchio 0:cfce61ec00c6 32 unsigned long colour;
emmanuelchio 0:cfce61ec00c6 33
emmanuelchio 0:cfce61ec00c6 34 R=pixBuffer[0];
emmanuelchio 0:cfce61ec00c6 35 G=pixBuffer[1];
emmanuelchio 0:cfce61ec00c6 36 B=pixBuffer[2];
emmanuelchio 0:cfce61ec00c6 37 ((unsigned char *) &colour)[1]=(R & 0xF8);
emmanuelchio 0:cfce61ec00c6 38 R=G;
emmanuelchio 0:cfce61ec00c6 39 G=G>>5;
emmanuelchio 0:cfce61ec00c6 40 ((unsigned char *) &colour)[1]|=G;
emmanuelchio 0:cfce61ec00c6 41 G=(R<<3)& 0xE0;
emmanuelchio 0:cfce61ec00c6 42 ((unsigned char *) &colour)[0]=B;
emmanuelchio 0:cfce61ec00c6 43 ((unsigned char *) &colour)[0]=((unsigned char *) &colour)[0]>>3;
emmanuelchio 0:cfce61ec00c6 44 ((unsigned char *) &colour)[0]|=G;
emmanuelchio 0:cfce61ec00c6 45 col=colour;
emmanuelchio 0:cfce61ec00c6 46 return col;
emmanuelchio 0:cfce61ec00c6 47 }
emmanuelchio 0:cfce61ec00c6 48
emmanuelchio 0:cfce61ec00c6 49 //Main applications, the next applications are called by the main loop menu
emmanuelchio 0:cfce61ec00c6 50 /**************************************************/
emmanuelchio 0:cfce61ec00c6 51 /**************************************************/
emmanuelchio 0:cfce61ec00c6 52 /**************************************************/
emmanuelchio 0:cfce61ec00c6 53 //clock application
emmanuelchio 0:cfce61ec00c6 54 char clocks(){
emmanuelchio 0:cfce61ec00c6 55 int hours=4,mins=48,secs=0;
emmanuelchio 0:cfce61ec00c6 56 int halfx=160 ,halfy=129;
emmanuelchio 0:cfce61ec00c6 57 int xs,ys,xm,ym,xh,yh,n;
emmanuelchio 0:cfce61ec00c6 58 int angleH,angleM,angleS;
emmanuelchio 0:cfce61ec00c6 59 int handHour=45;//hand size
emmanuelchio 0:cfce61ec00c6 60 int handMin=57;//hand size
emmanuelchio 0:cfce61ec00c6 61 int handSec=62;//hand size
emmanuelchio 0:cfce61ec00c6 62 int colBackClk,colHour=WHITE,colMin=WHITE,colSec=WHITE;
emmanuelchio 0:cfce61ec00c6 63 char carClk=1,clockNextFlag;
emmanuelchio 0:cfce61ec00c6 64
emmanuelchio 0:cfce61ec00c6 65 while(1){ //we loop between clocks until a touch on icons
emmanuelchio 0:cfce61ec00c6 66 switch(carClk){
emmanuelchio 0:cfce61ec00c6 67 case 1:
emmanuelchio 0:cfce61ec00c6 68 lcd.imageSD(0,0,"oldclk"); //load the clock face
emmanuelchio 0:cfce61ec00c6 69 colHour=BLACK; //change the colour of the clock hands
emmanuelchio 0:cfce61ec00c6 70 colMin=BLACK;
emmanuelchio 0:cfce61ec00c6 71 colSec=RED;
emmanuelchio 0:cfce61ec00c6 72 handHour=45; //hands size
emmanuelchio 0:cfce61ec00c6 73 handMin=57;
emmanuelchio 0:cfce61ec00c6 74 handSec=62;
emmanuelchio 0:cfce61ec00c6 75 break;
emmanuelchio 0:cfce61ec00c6 76 case 2:
emmanuelchio 0:cfce61ec00c6 77 lcd.imageSD(0,0,"colclk"); //load the clock face
emmanuelchio 0:cfce61ec00c6 78 colHour=RED; //change the colour of the clock hands
emmanuelchio 0:cfce61ec00c6 79 colMin=BLUE;
emmanuelchio 0:cfce61ec00c6 80 colSec=YELLOW;
emmanuelchio 0:cfce61ec00c6 81 handHour=58; //hands size
emmanuelchio 0:cfce61ec00c6 82 handMin=65;
emmanuelchio 0:cfce61ec00c6 83 handSec=70;
emmanuelchio 0:cfce61ec00c6 84 break;
emmanuelchio 0:cfce61ec00c6 85 case 3:
emmanuelchio 0:cfce61ec00c6 86 lcd.imageSD(0,0,"purclk"); //load the clock face
emmanuelchio 0:cfce61ec00c6 87 colHour=WHITE; //change the colour of the clock hands
emmanuelchio 0:cfce61ec00c6 88 colMin=WHITE;
emmanuelchio 0:cfce61ec00c6 89 colSec=WHITE;
emmanuelchio 0:cfce61ec00c6 90 handHour=47; //hands size
emmanuelchio 0:cfce61ec00c6 91 handMin=55;
emmanuelchio 0:cfce61ec00c6 92 handSec=64;
emmanuelchio 0:cfce61ec00c6 93 break;
emmanuelchio 0:cfce61ec00c6 94 default:
emmanuelchio 0:cfce61ec00c6 95 break;
emmanuelchio 0:cfce61ec00c6 96 }
emmanuelchio 0:cfce61ec00c6 97 lcd.imageSD(0,0,"WinHead"); //draw header
emmanuelchio 0:cfce61ec00c6 98 lcd.memoryRead(halfx,halfy,halfx,halfy,pixelArray); //This function return a 24 bit pixel array,
emmanuelchio 0:cfce61ec00c6 99 colBackClk=RGB888ToRGB565(pixelArray); //we get the back colour of the clock to erase the hands with the same colour
emmanuelchio 0:cfce61ec00c6 100 clockNextFlag=0; //turn off next clock flag
emmanuelchio 0:cfce61ec00c6 101 while(clockNextFlag==0){
emmanuelchio 0:cfce61ec00c6 102 //Do some Math to get the second point of the clock hands. (first point is always the center of the clock)
emmanuelchio 0:cfce61ec00c6 103 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:cfce61ec00c6 104 xs=(sin((angleS*3.14)/180)) * handSec; //get X component of the second's hand
emmanuelchio 0:cfce61ec00c6 105 ys=(cos((angleS*3.14)/180)) * handSec; //get Y component of the second's hand
emmanuelchio 0:cfce61ec00c6 106 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:cfce61ec00c6 107 xm=(sin((angleM*3.14)/180)) * handMin; //get X component of the minutes's hand
emmanuelchio 0:cfce61ec00c6 108 ym=(cos((angleM*3.14)/180)) * handMin; //get Y component of the minutes's hand
emmanuelchio 0:cfce61ec00c6 109 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:cfce61ec00c6 110 xh=(sin((angleH*3.14)/180)) * handHour; //get X component of the hours's hand
emmanuelchio 0:cfce61ec00c6 111 yh=(cos((angleH*3.14)/180)) * handHour; //get Y component of the hours's hand
emmanuelchio 0:cfce61ec00c6 112
emmanuelchio 0:cfce61ec00c6 113 //Draw current time hands
emmanuelchio 0:cfce61ec00c6 114 lcd.drawLine(halfx,halfy,halfx+xm,halfy-ym,colMin); // Draw the minutes hand, first point is the center of the clock, and the second is the point obtained by doing math
emmanuelchio 0:cfce61ec00c6 115 lcd.drawLine(halfx,halfy,halfx+xh,halfy-yh,colHour); // Draw the hours hand, first point is the center of the clock, and the second is the point obtained by doing math
emmanuelchio 0:cfce61ec00c6 116 lcd.drawLine(halfx,halfy,halfx+xs,halfy-ys,colSec); // Draw the seconds hand, first point is the center of the clock, and the second is the point obtained by doing math
emmanuelchio 0:cfce61ec00c6 117 lcd.drawCircle(halfx,halfy,3,colSec,FILL); // Draw the center of the second's hand
emmanuelchio 0:cfce61ec00c6 118
emmanuelchio 0:cfce61ec00c6 119 for(n=0;n<210;n++){ // loop for about one second delay (we dont need to explain why we're waiting one second, right?)
emmanuelchio 0:cfce61ec00c6 120 if(lcd.touchScreen(touch)){
emmanuelchio 0:cfce61ec00c6 121 carClk++; // increase clock Counter to select and load next clock
emmanuelchio 0:cfce61ec00c6 122 if(carClk==4){
emmanuelchio 0:cfce61ec00c6 123 carClk=1;
emmanuelchio 0:cfce61ec00c6 124 }
emmanuelchio 0:cfce61ec00c6 125 clockNextFlag=1; // turn on flag to change clock
emmanuelchio 0:cfce61ec00c6 126 break;
emmanuelchio 0:cfce61ec00c6 127 }
emmanuelchio 0:cfce61ec00c6 128 if(lcd.touchIcon(icon)){ // if we receive a touch on icons we exit
emmanuelchio 0:cfce61ec00c6 129 return 0; // exit
emmanuelchio 0:cfce61ec00c6 130 }
emmanuelchio 0:cfce61ec00c6 131 }
emmanuelchio 0:cfce61ec00c6 132
emmanuelchio 0:cfce61ec00c6 133 //time managing
emmanuelchio 0:cfce61ec00c6 134 secs++; // increase seconds
emmanuelchio 0:cfce61ec00c6 135 if(secs==60){ // if we reach 60 seconds
emmanuelchio 0:cfce61ec00c6 136 mins++; // increase the minutes
emmanuelchio 0:cfce61ec00c6 137 if(mins==60){ // if we reach 60 minutes
emmanuelchio 0:cfce61ec00c6 138 hours++; // increase the minutes
emmanuelchio 0:cfce61ec00c6 139 if(hours==12){ // if we reach 12 hours
emmanuelchio 0:cfce61ec00c6 140 hours=0; // clear hours
emmanuelchio 0:cfce61ec00c6 141 }
emmanuelchio 0:cfce61ec00c6 142 mins=0; // clear minutes
emmanuelchio 0:cfce61ec00c6 143 }
emmanuelchio 0:cfce61ec00c6 144 secs=0; // clear seconds
emmanuelchio 0:cfce61ec00c6 145 }
emmanuelchio 0:cfce61ec00c6 146
emmanuelchio 0:cfce61ec00c6 147 //Erase all hands
emmanuelchio 0:cfce61ec00c6 148 lcd.drawLine(halfx,halfy,halfx+xs,halfy-ys,colBackClk); // Erase Second's hand
emmanuelchio 0:cfce61ec00c6 149 lcd.drawLine(halfx,halfy,halfx+xm,halfy-ym,colBackClk); // Erase Minute's hand
emmanuelchio 0:cfce61ec00c6 150 lcd.drawLine(halfx,halfy,halfx+xh,halfy-yh,colBackClk); // Erase Hour's hand
emmanuelchio 0:cfce61ec00c6 151 }
emmanuelchio 0:cfce61ec00c6 152 }
emmanuelchio 0:cfce61ec00c6 153 }
emmanuelchio 0:cfce61ec00c6 154
emmanuelchio 0:cfce61ec00c6 155 /**************************************************/
emmanuelchio 0:cfce61ec00c6 156 /**************************************************/
emmanuelchio 0:cfce61ec00c6 157 //calc application
emmanuelchio 0:cfce61ec00c6 158 void calculator(){
emmanuelchio 0:cfce61ec00c6 159 unsigned char auxCalc=0;
emmanuelchio 0:cfce61ec00c6 160 char number=0;
emmanuelchio 0:cfce61ec00c6 161 int sums=0;
emmanuelchio 0:cfce61ec00c6 162 char num1[2]={0};
emmanuelchio 0:cfce61ec00c6 163 char num2[2]={0};
emmanuelchio 0:cfce61ec00c6 164 char result[4]={0};
emmanuelchio 0:cfce61ec00c6 165 char operation[2]={0};
emmanuelchio 0:cfce61ec00c6 166
emmanuelchio 0:cfce61ec00c6 167 lcd.imageSD(0,0,"Calc"); //load calc design
emmanuelchio 0:cfce61ec00c6 168 lcd.imageSD(0,0,"WinHead"); //draw header
emmanuelchio 0:cfce61ec00c6 169 lcd.string(224,34,255,65,BLACK,FONT7,TRANS,"0"); //draw numbers
emmanuelchio 0:cfce61ec00c6 170 lcd.string(80,36,100,55,BLACK,FONT0,TRANS,"0");
emmanuelchio 0:cfce61ec00c6 171
emmanuelchio 0:cfce61ec00c6 172 //Start application
emmanuelchio 0:cfce61ec00c6 173 while(1){ //while touch on icons
emmanuelchio 0:cfce61ec00c6 174 while(lcd.touchScreen(touch)==0 & lcd.touchIcon(icon)==0); //wait for a touch to do something
emmanuelchio 0:cfce61ec00c6 175 if(lcd.touchIcon(icon)==1){ //if the received touch was on any icon we go to main menu
emmanuelchio 0:cfce61ec00c6 176 break;
emmanuelchio 0:cfce61ec00c6 177 }
emmanuelchio 0:cfce61ec00c6 178 if(touch[YCOORD]>73 & touch[YCOORD]<101){ //first row
emmanuelchio 0:cfce61ec00c6 179 if(touch[XCOORD]>74 & touch[XCOORD]<117){
emmanuelchio 0:cfce61ec00c6 180 auxCalc='E';
emmanuelchio 0:cfce61ec00c6 181 }else if(touch[XCOORD]>116 & touch[XCOORD]<161){
emmanuelchio 0:cfce61ec00c6 182 auxCalc='I';
emmanuelchio 0:cfce61ec00c6 183 }else if(touch[XCOORD]>161 & touch[XCOORD]<205){
emmanuelchio 0:cfce61ec00c6 184 auxCalc='/';
emmanuelchio 0:cfce61ec00c6 185 }else if(touch[XCOORD]>204 & touch[XCOORD]<249){
emmanuelchio 0:cfce61ec00c6 186 auxCalc='X';
emmanuelchio 0:cfce61ec00c6 187 }
emmanuelchio 0:cfce61ec00c6 188 }else if(touch[YCOORD]>100 & touch[YCOORD]<130){ //second row
emmanuelchio 0:cfce61ec00c6 189 if(touch[XCOORD]>74 & touch[XCOORD]<117){
emmanuelchio 0:cfce61ec00c6 190 auxCalc=7;
emmanuelchio 0:cfce61ec00c6 191 }else if(touch[XCOORD]>116 & touch[XCOORD]<161){
emmanuelchio 0:cfce61ec00c6 192 auxCalc=8;
emmanuelchio 0:cfce61ec00c6 193 }else if(touch[XCOORD]>161 & touch[XCOORD]<205){
emmanuelchio 0:cfce61ec00c6 194 auxCalc=9;
emmanuelchio 0:cfce61ec00c6 195 }else if(touch[XCOORD]>204 & touch[XCOORD]<249){
emmanuelchio 0:cfce61ec00c6 196 auxCalc='-';
emmanuelchio 0:cfce61ec00c6 197 }
emmanuelchio 0:cfce61ec00c6 198 }else if(touch[YCOORD]>129 & touch[YCOORD]<159){ //third row
emmanuelchio 0:cfce61ec00c6 199 if(touch[XCOORD]>74 & touch[XCOORD]<117){
emmanuelchio 0:cfce61ec00c6 200 auxCalc=4;
emmanuelchio 0:cfce61ec00c6 201 }else if(touch[XCOORD]>116 & touch[XCOORD]<161){
emmanuelchio 0:cfce61ec00c6 202 auxCalc=5;
emmanuelchio 0:cfce61ec00c6 203 }else if(touch[XCOORD]>161 & touch[XCOORD]<205){
emmanuelchio 0:cfce61ec00c6 204 auxCalc=6;
emmanuelchio 0:cfce61ec00c6 205 }else if(touch[XCOORD]>204 & touch[XCOORD]<249){
emmanuelchio 0:cfce61ec00c6 206 auxCalc='+';
emmanuelchio 0:cfce61ec00c6 207 }
emmanuelchio 0:cfce61ec00c6 208 }else if(touch[YCOORD]>158 & touch[YCOORD]<188){ //fourth row
emmanuelchio 0:cfce61ec00c6 209 if(touch[XCOORD]>74 & touch[XCOORD]<117){
emmanuelchio 0:cfce61ec00c6 210 auxCalc=1;
emmanuelchio 0:cfce61ec00c6 211 }else if(touch[XCOORD]>116 & touch[XCOORD]<161){
emmanuelchio 0:cfce61ec00c6 212 auxCalc=2;
emmanuelchio 0:cfce61ec00c6 213 }else if(touch[XCOORD]>161 & touch[XCOORD]<205){
emmanuelchio 0:cfce61ec00c6 214 auxCalc=3;
emmanuelchio 0:cfce61ec00c6 215 }else if(touch[XCOORD]>204 & touch[XCOORD]<249){
emmanuelchio 0:cfce61ec00c6 216 auxCalc='R';
emmanuelchio 0:cfce61ec00c6 217 }
emmanuelchio 0:cfce61ec00c6 218 }else if(touch[YCOORD]>187 & touch[YCOORD]<215){ //fifth row
emmanuelchio 0:cfce61ec00c6 219 if(touch[XCOORD]>74 & touch[XCOORD]<117){
emmanuelchio 0:cfce61ec00c6 220 auxCalc=0;
emmanuelchio 0:cfce61ec00c6 221 }else if(touch[XCOORD]>116 & touch[XCOORD]<161){
emmanuelchio 0:cfce61ec00c6 222 auxCalc=0;
emmanuelchio 0:cfce61ec00c6 223 }else if(touch[XCOORD]>204 & touch[XCOORD]<249){
emmanuelchio 0:cfce61ec00c6 224 auxCalc='R';
emmanuelchio 0:cfce61ec00c6 225 }
emmanuelchio 0:cfce61ec00c6 226 }else{
emmanuelchio 0:cfce61ec00c6 227 auxCalc='N';
emmanuelchio 0:cfce61ec00c6 228 }
emmanuelchio 0:cfce61ec00c6 229 if(number==0){ //get first number
emmanuelchio 0:cfce61ec00c6 230 if(auxCalc<10){
emmanuelchio 0:cfce61ec00c6 231 num1[0]=auxCalc+0x30;
emmanuelchio 0:cfce61ec00c6 232 }else{
emmanuelchio 0:cfce61ec00c6 233 if(auxCalc=='E'){
emmanuelchio 0:cfce61ec00c6 234 num1[0]=0x30;
emmanuelchio 0:cfce61ec00c6 235 }else{
emmanuelchio 0:cfce61ec00c6 236 operation[0]=auxCalc;
emmanuelchio 0:cfce61ec00c6 237 if(operation[0]!='R' & operation[0]!='N' & operation[0]!='I'){
emmanuelchio 0:cfce61ec00c6 238 number++;
emmanuelchio 0:cfce61ec00c6 239 lcd.drawRectangle(224,34,248,58,0xD6B6,FILL);
emmanuelchio 0:cfce61ec00c6 240 wait_ms(200);
emmanuelchio 0:cfce61ec00c6 241 lcd.string(90,36,100,55,BLACK,FONT0,TRANS,operation);
emmanuelchio 0:cfce61ec00c6 242 }
emmanuelchio 0:cfce61ec00c6 243 }
emmanuelchio 0:cfce61ec00c6 244 }
emmanuelchio 0:cfce61ec00c6 245 lcd.drawRectangle(80,36,87,46,0xD6B6,FILL);
emmanuelchio 0:cfce61ec00c6 246 lcd.drawRectangle(224,34,248,58,0xD6B6,FILL);
emmanuelchio 0:cfce61ec00c6 247 lcd.string(224,34,255,65,BLACK,FONT7,TRANS,num1);
emmanuelchio 0:cfce61ec00c6 248 lcd.string(80,36,100,55,BLACK,FONT0,TRANS,num1);
emmanuelchio 0:cfce61ec00c6 249 num2[0]=0;
emmanuelchio 0:cfce61ec00c6 250 }else if (number==1){ //get second number
emmanuelchio 0:cfce61ec00c6 251 if(auxCalc<10){
emmanuelchio 0:cfce61ec00c6 252 num2[0]=auxCalc+0x30;
emmanuelchio 0:cfce61ec00c6 253 }else{
emmanuelchio 0:cfce61ec00c6 254 if(auxCalc=='E'){
emmanuelchio 0:cfce61ec00c6 255 num2[0]=0x30;
emmanuelchio 0:cfce61ec00c6 256 }else{
emmanuelchio 0:cfce61ec00c6 257 if(auxCalc=='R'){
emmanuelchio 0:cfce61ec00c6 258 switch(operation[0]){
emmanuelchio 0:cfce61ec00c6 259 case '+':
emmanuelchio 0:cfce61ec00c6 260 sums=(num1[0]-0x30);
emmanuelchio 0:cfce61ec00c6 261 sums+=(num2[0]-0x30);
emmanuelchio 0:cfce61ec00c6 262 break;
emmanuelchio 0:cfce61ec00c6 263 case '-':
emmanuelchio 0:cfce61ec00c6 264 sums=(num1[0]-0x30);
emmanuelchio 0:cfce61ec00c6 265 sums-=(num2[0]-0x30);
emmanuelchio 0:cfce61ec00c6 266 break;
emmanuelchio 0:cfce61ec00c6 267 case 'X':
emmanuelchio 0:cfce61ec00c6 268 sums=(num1[0]-0x30);
emmanuelchio 0:cfce61ec00c6 269 sums*=(num2[0]-0x30);
emmanuelchio 0:cfce61ec00c6 270 break;
emmanuelchio 0:cfce61ec00c6 271 case '/':
emmanuelchio 0:cfce61ec00c6 272 sums=(num1[0]-0x30);
emmanuelchio 0:cfce61ec00c6 273 sums/=(num2[0]-0x30);
emmanuelchio 0:cfce61ec00c6 274 break;
emmanuelchio 0:cfce61ec00c6 275 default:
emmanuelchio 0:cfce61ec00c6 276 sums=(num1[0]-0x30);
emmanuelchio 0:cfce61ec00c6 277 sums+=(num2[0]-0x30);
emmanuelchio 0:cfce61ec00c6 278 break;
emmanuelchio 0:cfce61ec00c6 279 }
emmanuelchio 0:cfce61ec00c6 280 if(sums<0){
emmanuelchio 0:cfce61ec00c6 281 result[0]='-';
emmanuelchio 0:cfce61ec00c6 282 result[1]=(-1*(sums/10))+0x30;
emmanuelchio 0:cfce61ec00c6 283 result[2]=(-1*(sums%10))+0x30;
emmanuelchio 0:cfce61ec00c6 284 }else{
emmanuelchio 0:cfce61ec00c6 285 result[0]=' ';
emmanuelchio 0:cfce61ec00c6 286 result[1]=(sums/10)+0x30;
emmanuelchio 0:cfce61ec00c6 287 result[2]=(sums%10)+0x30;
emmanuelchio 0:cfce61ec00c6 288 }
emmanuelchio 0:cfce61ec00c6 289 lcd.string(100,36,110,55,BLACK,FONT0,TRANS,num2);
emmanuelchio 0:cfce61ec00c6 290 lcd.string(110,36,120,55,BLACK,FONT0,TRANS,"=\0");
emmanuelchio 0:cfce61ec00c6 291 lcd.drawRectangle(224,34,248,58,0xD6B6,FILL);
emmanuelchio 0:cfce61ec00c6 292 lcd.string(192,34,255,65,BLACK,FONT7,TRANS,result);
emmanuelchio 0:cfce61ec00c6 293 number++;
emmanuelchio 0:cfce61ec00c6 294 wait_ms(200);
emmanuelchio 0:cfce61ec00c6 295 }
emmanuelchio 0:cfce61ec00c6 296 }
emmanuelchio 0:cfce61ec00c6 297 }
emmanuelchio 0:cfce61ec00c6 298 if(number<2){
emmanuelchio 0:cfce61ec00c6 299 lcd.drawRectangle(100,36,107,46,0xD6B6,FILL);
emmanuelchio 0:cfce61ec00c6 300 lcd.drawRectangle(224,34,248,58,0xD6B6,FILL);
emmanuelchio 0:cfce61ec00c6 301 lcd.string(224,34,255,65,BLACK,FONT7,TRANS,num2);
emmanuelchio 0:cfce61ec00c6 302 lcd.string(100,36,110,55,BLACK,FONT0,TRANS,num2);
emmanuelchio 0:cfce61ec00c6 303 }
emmanuelchio 0:cfce61ec00c6 304 }else{
emmanuelchio 0:cfce61ec00c6 305 lcd.drawRectangle(75,34,248,58,0xD6B6,FILL);
emmanuelchio 0:cfce61ec00c6 306 number=0;
emmanuelchio 0:cfce61ec00c6 307 }
emmanuelchio 0:cfce61ec00c6 308 }
emmanuelchio 0:cfce61ec00c6 309 }
emmanuelchio 0:cfce61ec00c6 310
emmanuelchio 0:cfce61ec00c6 311 /**************************************************/
emmanuelchio 0:cfce61ec00c6 312 /**************************************************/
emmanuelchio 0:cfce61ec00c6 313 //notes application
emmanuelchio 0:cfce61ec00c6 314 void notes(){
emmanuelchio 0:cfce61ec00c6 315 lcd.imageSD(0,0,"notes"); //load notes design
emmanuelchio 0:cfce61ec00c6 316 lcd.imageSD(0,0,"WinHead"); //draw header
emmanuelchio 0:cfce61ec00c6 317 while(1){
emmanuelchio 0:cfce61ec00c6 318 while(lcd.touchScreen(touch)==0 & lcd.touchIcon(icon)==0); //wait for a touch to do something
emmanuelchio 0:cfce61ec00c6 319 if(lcd.touchIcon(icon)==1){ //if the received touch was on any icon we exit go to main menu
emmanuelchio 0:cfce61ec00c6 320 break;
emmanuelchio 0:cfce61ec00c6 321 }
emmanuelchio 0:cfce61ec00c6 322 if(touch[YCOORD]>10){
emmanuelchio 0:cfce61ec00c6 323 lcd.drawCircle(touch[XCOORD],touch[YCOORD],2,BLACK,FILL);
emmanuelchio 0:cfce61ec00c6 324 }else{
emmanuelchio 0:cfce61ec00c6 325 if(touch[XCOORD]>300){ //close
emmanuelchio 0:cfce61ec00c6 326 break;
emmanuelchio 0:cfce61ec00c6 327 }else{ //reload all
emmanuelchio 0:cfce61ec00c6 328 lcd.imageSD(0,0,"notes");
emmanuelchio 0:cfce61ec00c6 329 lcd.imageSD(0,0,"WinHead"); //draw header
emmanuelchio 0:cfce61ec00c6 330 }
emmanuelchio 0:cfce61ec00c6 331 }
emmanuelchio 0:cfce61ec00c6 332 }
emmanuelchio 0:cfce61ec00c6 333 }
emmanuelchio 0:cfce61ec00c6 334
emmanuelchio 0:cfce61ec00c6 335 /**************************************************/
emmanuelchio 0:cfce61ec00c6 336 /**************************************************/
emmanuelchio 0:cfce61ec00c6 337 //pong application
emmanuelchio 0:cfce61ec00c6 338 void pong(){
emmanuelchio 0:cfce61ec00c6 339
emmanuelchio 0:cfce61ec00c6 340 char radiusBall2=8;
emmanuelchio 0:cfce61ec00c6 341 char radiusBall1=10;
emmanuelchio 0:cfce61ec00c6 342 int speedBall1=2; //ball1 moving speed - amount of pixels that ball move each time
emmanuelchio 0:cfce61ec00c6 343 int speedBall2=3; //ball2 moving speed - amount of pixels that ball move each time
emmanuelchio 0:cfce61ec00c6 344 int dirx1=-1; //xball1 initial negative direction
emmanuelchio 0:cfce61ec00c6 345 int diry1=1; //yball1 initial positive direction
emmanuelchio 0:cfce61ec00c6 346 int xBall1=200; //x initial position of ball1
emmanuelchio 0:cfce61ec00c6 347 int yBall1; //y position of ball1
emmanuelchio 0:cfce61ec00c6 348 int dirx2=1; //xball2 initial positive direction
emmanuelchio 0:cfce61ec00c6 349 int diry2=-1; //yball2 initial negative direction
emmanuelchio 0:cfce61ec00c6 350 int xBall2=50; //x initial position of ball2
emmanuelchio 0:cfce61ec00c6 351 int yBall2; //y position of ball2
emmanuelchio 0:cfce61ec00c6 352
emmanuelchio 0:cfce61ec00c6 353 //variables used by Pong data
emmanuelchio 0:cfce61ec00c6 354 char score[7]={0,0,' ','P','T','S',0x00}; //array to save score
emmanuelchio 0:cfce61ec00c6 355 char points=0;
emmanuelchio 0:cfce61ec00c6 356 char gameOver=0; //game over flag
emmanuelchio 0:cfce61ec00c6 357 int speedCounter=0; //Counter that saves the speed
emmanuelchio 0:cfce61ec00c6 358 char ball1Active=1; //acrive ball flag
emmanuelchio 0:cfce61ec00c6 359 char ball2Active=1; //active ball flag
emmanuelchio 0:cfce61ec00c6 360 int barSize = 60; //size of bar in pixels
emmanuelchio 0:cfce61ec00c6 361 int bar=50; //initial x position of the bar
emmanuelchio 0:cfce61ec00c6 362 int barCenter = (barSize/2)+bar; //we need to know the center of the bar
emmanuelchio 0:cfce61ec00c6 363 int pongBack=0x6350; //pong background colour
emmanuelchio 0:cfce61ec00c6 364
emmanuelchio 0:cfce61ec00c6 365 //define bouncing corners
emmanuelchio 0:cfce61ec00c6 366 int bottomx1= (25+radiusBall1);
emmanuelchio 0:cfce61ec00c6 367 int topx1 = (319-25-radiusBall1-1);
emmanuelchio 0:cfce61ec00c6 368 int bottomy1= (25+radiusBall1);
emmanuelchio 0:cfce61ec00c6 369 int topy1 = (239-30-radiusBall1-1);
emmanuelchio 0:cfce61ec00c6 370 int bottomx2= (25+radiusBall2);
emmanuelchio 0:cfce61ec00c6 371 int topx2 = (319-25-radiusBall2-1);
emmanuelchio 0:cfce61ec00c6 372 int bottomy2= (25+radiusBall2);
emmanuelchio 0:cfce61ec00c6 373 int topy2 = (239-30-radiusBall2-1);
emmanuelchio 0:cfce61ec00c6 374
emmanuelchio 0:cfce61ec00c6 375 unsigned char i;
emmanuelchio 0:cfce61ec00c6 376 char buffer[3];
emmanuelchio 0:cfce61ec00c6 377
emmanuelchio 0:cfce61ec00c6 378 yBall1=40+radiusBall1; //y initial position of ball1
emmanuelchio 0:cfce61ec00c6 379 yBall2=160+radiusBall2; //y initial position of ball2
emmanuelchio 0:cfce61ec00c6 380
emmanuelchio 0:cfce61ec00c6 381 lcd.imageSD(0,0,"pong"); //load pong design
emmanuelchio 0:cfce61ec00c6 382 lcd.imageSD(0,0,"WinHead"); //draw header
emmanuelchio 0:cfce61ec00c6 383 lcd.string(110,100,250,120,GREEN,FONT0,COLOUR,"Touch to Begin"); //draw instructions
emmanuelchio 0:cfce61ec00c6 384 while(lcd.touchScreen(touch)==0); //wait a touch to begin
emmanuelchio 0:cfce61ec00c6 385 lcd.drawRectangle(25,25,294,214,pongBack,FILL); //draw arena
emmanuelchio 0:cfce61ec00c6 386 lcd.drawRectangle(24,24,295,215,GREEN,UNFILL); //corners
emmanuelchio 0:cfce61ec00c6 387 lcd.drawLine(bar,209,bar+barSize,209,WHITE); //draw Bar
emmanuelchio 0:cfce61ec00c6 388
emmanuelchio 0:cfce61ec00c6 389 while(gameOver==0){ //while game over flag is zero
emmanuelchio 0:cfce61ec00c6 390 buffer[0]=(points/10)+0x30, buffer[1]=(points%10)+0x30, buffer[2]=0; //fill buffer that counts
emmanuelchio 0:cfce61ec00c6 391 lcd.string(2,16,30,35,RED,FONT3,COLOUR,buffer); //display current points
emmanuelchio 0:cfce61ec00c6 392 for(i=0;i<5;i++){ //check 5 times if the player touches the screen
emmanuelchio 0:cfce61ec00c6 393 if(lcd.touchScreen(touch)){ //if we receive a touch then we move the bar to touched side
emmanuelchio 0:cfce61ec00c6 394 lcd.drawLine(bar,209,bar+barSize,209,pongBack); //erase previous Bar
emmanuelchio 0:cfce61ec00c6 395 if(touch[XCOORD]>barCenter){ //if we need to move the bar to the right
emmanuelchio 0:cfce61ec00c6 396 bar+=8; //move the bar to the right 8 pixels
emmanuelchio 0:cfce61ec00c6 397 if((bar+barSize)>293){ //if the bar reach the right corner
emmanuelchio 0:cfce61ec00c6 398 bar=293-barSize;
emmanuelchio 0:cfce61ec00c6 399 }
emmanuelchio 0:cfce61ec00c6 400 barCenter=bar+(barSize/2); //set new center position of the bar
emmanuelchio 0:cfce61ec00c6 401 }else{ //move the bar to the left
emmanuelchio 0:cfce61ec00c6 402 bar-=8; //move the bar to the left 8 pixels
emmanuelchio 0:cfce61ec00c6 403 if(bar<25){ //if the bar reach the left corner
emmanuelchio 0:cfce61ec00c6 404 bar=25;
emmanuelchio 0:cfce61ec00c6 405 }
emmanuelchio 0:cfce61ec00c6 406 barCenter=bar+(barSize/2); //set new center position of the bar
emmanuelchio 0:cfce61ec00c6 407 }
emmanuelchio 0:cfce61ec00c6 408 lcd.drawLine(bar,209,bar+barSize,209,WHITE); //draw the new bar at the new position
emmanuelchio 0:cfce61ec00c6 409 }
emmanuelchio 0:cfce61ec00c6 410 }
emmanuelchio 0:cfce61ec00c6 411 //we update the balls
emmanuelchio 0:cfce61ec00c6 412 if(ball1Active){ //if we haven't lost the ball1
emmanuelchio 0:cfce61ec00c6 413 /***************************************************/
emmanuelchio 0:cfce61ec00c6 414 //This its similar as moveBall1() function of pong example
emmanuelchio 0:cfce61ec00c6 415 //update the actual position of the ball1
emmanuelchio 0:cfce61ec00c6 416 lcd.drawCircle(xBall1,yBall1,radiusBall1,pongBack,UNFILL); // Erase previous ball position
emmanuelchio 0:cfce61ec00c6 417 xBall1+=(dirx1*speedBall1); // Calculate new x coordinate for ball1
emmanuelchio 0:cfce61ec00c6 418 yBall1+=(diry1*speedBall1); // Calculate new y coordinate for ball1
emmanuelchio 0:cfce61ec00c6 419 lcd.drawCircle(xBall1,yBall1,radiusBall1,GREEN,UNFILL); // Draw new ball position
emmanuelchio 0:cfce61ec00c6 420 if((xBall1+speedBall1)>topx1 | (xBall1-speedBall1)<=bottomx1){ // if ball reaches the left or right corner, we invert moving direction
emmanuelchio 0:cfce61ec00c6 421 dirx1= dirx1*(-1);
emmanuelchio 0:cfce61ec00c6 422 }
emmanuelchio 0:cfce61ec00c6 423 if((yBall1+speedBall1)>topy1 | (yBall1-speedBall1)<=bottomy1){ // if ball reaches the top or bottom corner, we invert moving direction
emmanuelchio 0:cfce61ec00c6 424 if((yBall1-speedBall1)<=bottomy1){ // Bounce on top, only invert moving direction
emmanuelchio 0:cfce61ec00c6 425 diry1= diry1*(-1); // We invert the moving direction by multiplying by -1
emmanuelchio 0:cfce61ec00c6 426 }else{ // Bounce on bottom, check if inside the bar
emmanuelchio 0:cfce61ec00c6 427 if((xBall1+speedBall1)>bar & (xBall1-speedBall1)<(bar+barSize)){ //if bounce inside the bar
emmanuelchio 0:cfce61ec00c6 428 diry1= diry1*(-1); // We invert the moving direction by multiplying by -1
emmanuelchio 0:cfce61ec00c6 429 points++; // Increase player current points
emmanuelchio 0:cfce61ec00c6 430 speedCounter++; // Increase the speed counter
emmanuelchio 0:cfce61ec00c6 431 if(speedCounter>9){ // If we reach 10 counts we increase the ball1 bouncing speed
emmanuelchio 0:cfce61ec00c6 432 speedBall1++;
emmanuelchio 0:cfce61ec00c6 433 speedCounter=0; // Reset the counter
emmanuelchio 0:cfce61ec00c6 434 }
emmanuelchio 0:cfce61ec00c6 435 }else{ // Bounce outside the bar
emmanuelchio 0:cfce61ec00c6 436 ball1Active=0; // Clear ball1 active flag
emmanuelchio 0:cfce61ec00c6 437 lcd.drawCircle(xBall1,yBall1,radiusBall1,pongBack,UNFILL);// Delete this ball because bounce outside of the bar
emmanuelchio 0:cfce61ec00c6 438 if(ball1Active==0 & ball2Active==0){ // if we have lost both balls
emmanuelchio 0:cfce61ec00c6 439 gameOver=1; // Set game over flag
emmanuelchio 0:cfce61ec00c6 440 }
emmanuelchio 0:cfce61ec00c6 441 }
emmanuelchio 0:cfce61ec00c6 442 }
emmanuelchio 0:cfce61ec00c6 443 }
emmanuelchio 0:cfce61ec00c6 444 }
emmanuelchio 0:cfce61ec00c6 445 if(ball2Active){ //if we haven't lost the ball2
emmanuelchio 0:cfce61ec00c6 446 /***************************************************/
emmanuelchio 0:cfce61ec00c6 447 //This its similar as moveBall2() function of pong example
emmanuelchio 0:cfce61ec00c6 448 //update the actual position of the ball2
emmanuelchio 0:cfce61ec00c6 449 lcd.drawCircle(xBall2,yBall2,radiusBall2,pongBack,FILL); // Erase previous ball position
emmanuelchio 0:cfce61ec00c6 450 xBall2+=(dirx2*speedBall2); // Calculate new x coordinate for ball2
emmanuelchio 0:cfce61ec00c6 451 yBall2+=(diry2*speedBall2); // Calculate new y coordinate for ball2
emmanuelchio 0:cfce61ec00c6 452 lcd.drawCircle(xBall2,yBall2,radiusBall2,MAGENTA,FILL); // Draw new ball position
emmanuelchio 0:cfce61ec00c6 453 if((xBall2+speedBall2)>topx2 | (xBall2-speedBall2)<=bottomx2){ // if ball reaches the left or right corner, we invert moving direction
emmanuelchio 0:cfce61ec00c6 454 dirx2= dirx2*(-1);
emmanuelchio 0:cfce61ec00c6 455 }
emmanuelchio 0:cfce61ec00c6 456 if((yBall2+speedBall2)>topy2 | (yBall2-speedBall2)<=bottomy2){ // if ball reaches the top or bottom corner, we invert moving direction
emmanuelchio 0:cfce61ec00c6 457 if((yBall2-speedBall2)<=bottomy2){ // Bounce on top, only invert moving direction
emmanuelchio 0:cfce61ec00c6 458 diry2= diry2*(-1);
emmanuelchio 0:cfce61ec00c6 459 }else{ // Bounce on bottom, check if inside the bar
emmanuelchio 0:cfce61ec00c6 460 if((xBall2+radiusBall2)>bar & (xBall2-radiusBall2)<(bar+barSize)){ //if bounce inside the bar
emmanuelchio 0:cfce61ec00c6 461 diry2= diry2*(-1); // We invert the moving direction by multiplying by -1
emmanuelchio 0:cfce61ec00c6 462 points++; // Increase player current points
emmanuelchio 0:cfce61ec00c6 463 speedCounter++; // Increase the speed counter
emmanuelchio 0:cfce61ec00c6 464 if(speedCounter>9){ // If we reach 10 counts we increase the ball1 bouncing speed
emmanuelchio 0:cfce61ec00c6 465 speedBall2++;
emmanuelchio 0:cfce61ec00c6 466 speedCounter=0; // Reset the counter
emmanuelchio 0:cfce61ec00c6 467 }
emmanuelchio 0:cfce61ec00c6 468 }else{ // Bounce outside the bar
emmanuelchio 0:cfce61ec00c6 469 ball2Active=0; // Clear ball1 active flag
emmanuelchio 0:cfce61ec00c6 470 lcd.drawCircle(xBall2,yBall2,radiusBall2,pongBack,FILL); // Delete this ball because bounce outside of the bar
emmanuelchio 0:cfce61ec00c6 471 if(ball1Active==0 & ball2Active==0){ // if we have lost both balls
emmanuelchio 0:cfce61ec00c6 472 gameOver=1; // Set game over flag
emmanuelchio 0:cfce61ec00c6 473 }
emmanuelchio 0:cfce61ec00c6 474 }
emmanuelchio 0:cfce61ec00c6 475 }
emmanuelchio 0:cfce61ec00c6 476 }
emmanuelchio 0:cfce61ec00c6 477 }
emmanuelchio 0:cfce61ec00c6 478 }
emmanuelchio 0:cfce61ec00c6 479 //game over - proceed to show final score
emmanuelchio 0:cfce61ec00c6 480 lcd.string(80,80,272,140,RED,FONT5,TRANS,"Game Over");
emmanuelchio 0:cfce61ec00c6 481 score[0]=(points/10)+0x30; //convert points to ascii format and store them on the score buffer
emmanuelchio 0:cfce61ec00c6 482 score[1]=(points%10)+0x30; //convert points to ascii format and store them on the score buffer
emmanuelchio 0:cfce61ec00c6 483 lcd.string(105,110,272,140,YELLOW,FONT5,TRANS,score);
emmanuelchio 0:cfce61ec00c6 484 lcd.string(100,135,250,180,GREEN,FONT3,TRANS,"Touch to Exit");
emmanuelchio 0:cfce61ec00c6 485 wait_ms(1000);
emmanuelchio 0:cfce61ec00c6 486 while(lcd.touchScreen(touch)==0); //wait for a touch to exit
emmanuelchio 0:cfce61ec00c6 487 }
emmanuelchio 0:cfce61ec00c6 488
emmanuelchio 0:cfce61ec00c6 489 /**************************************************/
emmanuelchio 0:cfce61ec00c6 490 /**************************************************/
emmanuelchio 0:cfce61ec00c6 491 //slide show application
emmanuelchio 0:cfce61ec00c6 492 void slideShow(){
emmanuelchio 0:cfce61ec00c6 493 char imagesOnSDCard[8][9]={"Peng320","Koala320","Hydra320","Lig320","Sea320","Tul320","Des320","Flow320"}; //array containing the names of the different called images
emmanuelchio 0:cfce61ec00c6 494 int pic=0;
emmanuelchio 0:cfce61ec00c6 495
emmanuelchio 0:cfce61ec00c6 496 while(1){ //Loop forever in the slide show!
emmanuelchio 0:cfce61ec00c6 497 lcd.imageSD(0,0,imagesOnSDCard[pic]); //Load image from SD card, all images are 320x240(full screen) so we load them from top left corner X:0,Y:0
emmanuelchio 0:cfce61ec00c6 498 lcd.imageSD(3,219,"prev"); //Load the prev icon
emmanuelchio 0:cfce61ec00c6 499 lcd.imageSD(300,219,"next"); //Load the next icon
emmanuelchio 0:cfce61ec00c6 500 lcd.imageSD(0,0,"WinHead"); //draw header
emmanuelchio 0:cfce61ec00c6 501
emmanuelchio 0:cfce61ec00c6 502 while(lcd.touchScreen(touch)==0 & lcd.touchIcon(icon)==0); //wait for a touch to do something
emmanuelchio 0:cfce61ec00c6 503 if(lcd.touchIcon(icon)==1){ //if the received touch was on any icon we exit go to main menu
emmanuelchio 0:cfce61ec00c6 504 break;
emmanuelchio 0:cfce61ec00c6 505 }
emmanuelchio 0:cfce61ec00c6 506
emmanuelchio 0:cfce61ec00c6 507 //check if we go to the next image, or to the previous one
emmanuelchio 0:cfce61ec00c6 508 if(touch[XCOORD]>160){ //if the received touch was on the right middle of the screen we advance the image, else we decrease and go to previous image
emmanuelchio 0:cfce61ec00c6 509 pic++; //decrease image selector
emmanuelchio 0:cfce61ec00c6 510 if(pic>7){ //if we reach the position of the last image, we restart to image 0
emmanuelchio 0:cfce61ec00c6 511 pic=0;
emmanuelchio 0:cfce61ec00c6 512 }
emmanuelchio 0:cfce61ec00c6 513 }else{
emmanuelchio 0:cfce61ec00c6 514 pic--;
emmanuelchio 0:cfce61ec00c6 515 if(pic<0){ //if we reach the position of the first image, we move to image 7
emmanuelchio 0:cfce61ec00c6 516 pic=7;
emmanuelchio 0:cfce61ec00c6 517 }
emmanuelchio 0:cfce61ec00c6 518 }
emmanuelchio 0:cfce61ec00c6 519 }
emmanuelchio 0:cfce61ec00c6 520 }
emmanuelchio 0:cfce61ec00c6 521
emmanuelchio 0:cfce61ec00c6 522 /**************************************************/
emmanuelchio 0:cfce61ec00c6 523 /**************************************************/
emmanuelchio 0:cfce61ec00c6 524 //settings application, brightness adjust
emmanuelchio 0:cfce61ec00c6 525 void settings(){
emmanuelchio 0:cfce61ec00c6 526 static int bright=127; //Maximum bright is set by default 133 min 14
emmanuelchio 0:cfce61ec00c6 527 static int buttonCen=271; //button center, static variables to avoid losing the parameters even if we go to main menu
emmanuelchio 0:cfce61ec00c6 528
emmanuelchio 0:cfce61ec00c6 529 lcd.imageSD(0,0,"Bright"); //Load image from SD card, image is 320x240(full screen) so we load it from top left corner X:0,Y:0
emmanuelchio 0:cfce61ec00c6 530 lcd.imageSD(0,0,"WinHead"); //draw header
emmanuelchio 0:cfce61ec00c6 531
emmanuelchio 0:cfce61ec00c6 532 while(1){ //Loop forever in the settings!
emmanuelchio 0:cfce61ec00c6 533 lcd.drawRectangle(40,64,(bright*2)+12,66,0x4C7C,FILL); //draw brightness bar 266 max 40 min
emmanuelchio 0:cfce61ec00c6 534 lcd.drawRectangle((bright*2)+12,64,266,66,WHITE,FILL); //fill the rest of the bar with white
emmanuelchio 0:cfce61ec00c6 535 lcd.imageSD((bright*2)+12,57,"button"); //Load the button icon 266 max pos X, 40 min X pos
emmanuelchio 0:cfce61ec00c6 536 wait_ms(100); //delay to avoid fast change and flickering
emmanuelchio 0:cfce61ec00c6 537
emmanuelchio 0:cfce61ec00c6 538 while(lcd.touchScreen(touch)==0 & lcd.touchIcon(icon)==0); //wait for a touch to do something
emmanuelchio 0:cfce61ec00c6 539 if(lcd.touchIcon(icon)==1){ //if the received touch was on any icon we exit go to main menu
emmanuelchio 0:cfce61ec00c6 540 break;
emmanuelchio 0:cfce61ec00c6 541 }
emmanuelchio 0:cfce61ec00c6 542
emmanuelchio 0:cfce61ec00c6 543 //touch on Screen, change brightness and draw button icon
emmanuelchio 0:cfce61ec00c6 544 if(touch[YCOORD]>55 & touch[YCOORD]<85 ){ //if the previous touch was on active area
emmanuelchio 0:cfce61ec00c6 545 lcd.imageSD((bright*2)+12,57,"clrBar"); //clear the button icon
emmanuelchio 0:cfce61ec00c6 546
emmanuelchio 0:cfce61ec00c6 547 //check where to move left or right
emmanuelchio 0:cfce61ec00c6 548 if(touch[XCOORD]>buttonCen){ //if we need to move the bar to the right
emmanuelchio 0:cfce61ec00c6 549 bright+=10; //increase the brightness
emmanuelchio 0:cfce61ec00c6 550 buttonCen+=22; //increase the center of the button
emmanuelchio 0:cfce61ec00c6 551 if(bright>127){ //if the button reach the right corner
emmanuelchio 0:cfce61ec00c6 552 bright=127; //set maximum bright
emmanuelchio 0:cfce61ec00c6 553 buttonCen=271; //set maximum button center
emmanuelchio 0:cfce61ec00c6 554 }
emmanuelchio 0:cfce61ec00c6 555 }else{ //move the bar to the left
emmanuelchio 0:cfce61ec00c6 556 bright-=10; //decrease the brightness
emmanuelchio 0:cfce61ec00c6 557 buttonCen-=22; //decrease the center of the button
emmanuelchio 0:cfce61ec00c6 558 if(bright<14){ //if the button reach the left corner
emmanuelchio 0:cfce61ec00c6 559 bright=14; //set minimum bright
emmanuelchio 0:cfce61ec00c6 560 buttonCen=40; //set minimum button center
emmanuelchio 0:cfce61ec00c6 561 }
emmanuelchio 0:cfce61ec00c6 562 }
emmanuelchio 0:cfce61ec00c6 563 lcd.bright(bright); //set new brightness value to SMART GPU
emmanuelchio 0:cfce61ec00c6 564 }
emmanuelchio 0:cfce61ec00c6 565 }
emmanuelchio 0:cfce61ec00c6 566 }
emmanuelchio 0:cfce61ec00c6 567
emmanuelchio 0:cfce61ec00c6 568 /**************************************************/
emmanuelchio 0:cfce61ec00c6 569 /**************************************************/
emmanuelchio 0:cfce61ec00c6 570 //google maps application
emmanuelchio 0:cfce61ec00c6 571 void googleMaps(){
emmanuelchio 0:cfce61ec00c6 572 char mapsOnSDCard[10][9]={"map0","map1","map2","map3","map4","map5","map6","map7","map8","map9"}; //array containing the names of the different called maps
emmanuelchio 0:cfce61ec00c6 573 char maps=0,nothing=1;
emmanuelchio 0:cfce61ec00c6 574
emmanuelchio 0:cfce61ec00c6 575 while(1){ //Loop forever in the slide show!
emmanuelchio 0:cfce61ec00c6 576 if(nothing!=0){ //do something
emmanuelchio 0:cfce61ec00c6 577 lcd.imageSD(0,0,mapsOnSDCard[maps]); //Load image from SD card, all images are 320x240(full screen) so we load them from top left corner X:0,Y:0
emmanuelchio 0:cfce61ec00c6 578 lcd.imageSD(0,0,"WinHead"); //draw header
emmanuelchio 0:cfce61ec00c6 579 lcd.imageSD(5,25,"barmap"); //draw zoom bar
emmanuelchio 0:cfce61ec00c6 580 }
emmanuelchio 0:cfce61ec00c6 581 while(lcd.touchScreen(touch)==0 & lcd.touchIcon(icon)==0); //wait for a touch to do something
emmanuelchio 0:cfce61ec00c6 582 if(lcd.touchIcon(icon)==1){ //if the received touch was on any icon we exit go to main menu
emmanuelchio 0:cfce61ec00c6 583 break;
emmanuelchio 0:cfce61ec00c6 584 }
emmanuelchio 0:cfce61ec00c6 585
emmanuelchio 0:cfce61ec00c6 586 if(touch[XCOORD]<25){ //touch on bar
emmanuelchio 0:cfce61ec00c6 587 if(touch[YCOORD]<120){ //touch on upper side of zoom bar
emmanuelchio 0:cfce61ec00c6 588 maps++;
emmanuelchio 0:cfce61ec00c6 589 if(maps>10){
emmanuelchio 0:cfce61ec00c6 590 maps=10;
emmanuelchio 0:cfce61ec00c6 591 }
emmanuelchio 0:cfce61ec00c6 592 }else{ //touch on lower side of zoom bar
emmanuelchio 0:cfce61ec00c6 593 maps--;
emmanuelchio 0:cfce61ec00c6 594 if(maps<1){
emmanuelchio 0:cfce61ec00c6 595 maps=1;
emmanuelchio 0:cfce61ec00c6 596 }
emmanuelchio 0:cfce61ec00c6 597 }
emmanuelchio 0:cfce61ec00c6 598 nothing=1; //prepare to do new image loading
emmanuelchio 0:cfce61ec00c6 599 }else{ //touch on inactive area
emmanuelchio 0:cfce61ec00c6 600 nothing=0; //do nothing and get another touch
emmanuelchio 0:cfce61ec00c6 601 }
emmanuelchio 0:cfce61ec00c6 602 }
emmanuelchio 0:cfce61ec00c6 603 }
emmanuelchio 0:cfce61ec00c6 604
emmanuelchio 0:cfce61ec00c6 605 /**************************************************/
emmanuelchio 0:cfce61ec00c6 606 /**************************************************/
emmanuelchio 0:cfce61ec00c6 607 //paint application
emmanuelchio 0:cfce61ec00c6 608 void paint(){
emmanuelchio 0:cfce61ec00c6 609 unsigned char penSize=1;
emmanuelchio 0:cfce61ec00c6 610 int colPaint=BLACK;
emmanuelchio 0:cfce61ec00c6 611 char pen[4]={'x','0','1',0x00}; //Array that show the current penSize
emmanuelchio 0:cfce61ec00c6 612
emmanuelchio 0:cfce61ec00c6 613 //Load paint design
emmanuelchio 0:cfce61ec00c6 614 lcd.imageSD(0,0,"paint"); //load paint image
emmanuelchio 0:cfce61ec00c6 615 lcd.string(7,54,48,65,GREEN,FONT1,FILL,"Erase"); //draw Erase word
emmanuelchio 0:cfce61ec00c6 616 lcd.string(77,54,110,65,GREEN,FONT1,FILL,pen); //draw penSize
emmanuelchio 0:cfce61ec00c6 617 lcd.imageSD(0,0,"WinHead"); //draw header
emmanuelchio 0:cfce61ec00c6 618
emmanuelchio 0:cfce61ec00c6 619 while(1){ //Start the Paint application
emmanuelchio 0:cfce61ec00c6 620 while(lcd.touchScreen(touch)==0 & lcd.touchIcon(icon)==0); //wait for a touch to do something
emmanuelchio 0:cfce61ec00c6 621 if(lcd.touchIcon(icon)==1){ //if the received touch was on any icon we exit go to main menu
emmanuelchio 0:cfce61ec00c6 622 break;
emmanuelchio 0:cfce61ec00c6 623 }
emmanuelchio 0:cfce61ec00c6 624
emmanuelchio 0:cfce61ec00c6 625 if(touch[YCOORD]<67){ //the touch was on the menu
emmanuelchio 0:cfce61ec00c6 626 if(touch[XCOORD]<45){ //touch on erase circle
emmanuelchio 0:cfce61ec00c6 627 lcd.drawRectangle(0,67,319,239,WHITE,1); //Draw a white rectangle on drawing area
emmanuelchio 0:cfce61ec00c6 628 }else if(touch[XCOORD]<75){ //touch to select the eraser
emmanuelchio 0:cfce61ec00c6 629 colPaint=WHITE;
emmanuelchio 0:cfce61ec00c6 630 lcd.drawCircle(25,34,14,colPaint,FILL); //draw WHITE colour circle on top left corner
emmanuelchio 0:cfce61ec00c6 631 }else if(touch[XCOORD]<108){ //touch to change pen Size
emmanuelchio 0:cfce61ec00c6 632 penSize=penSize*2; //double the penSize
emmanuelchio 0:cfce61ec00c6 633 if(penSize==16){ //maximum pen size = 8, if we reach 16 we set to 1.
emmanuelchio 0:cfce61ec00c6 634 penSize=1;
emmanuelchio 0:cfce61ec00c6 635 }
emmanuelchio 0:cfce61ec00c6 636 pen[1]=(penSize/10)+0x30; //get the tens of penSize and convert them to ascii
emmanuelchio 0:cfce61ec00c6 637 pen[2]=(penSize%10)+0x30; //get the ones of penSize and convert them to ascii
emmanuelchio 0:cfce61ec00c6 638 lcd.string(77,54,110,65,GREEN,FONT1,FILL,pen);//draw penSize
emmanuelchio 0:cfce61ec00c6 639 wait_ms(500); //delay to avoid fast penSize changing
emmanuelchio 0:cfce61ec00c6 640 }else if(touch[XCOORD]<312 & touch[YCOORD]>20 & touch[YCOORD]<59){ //touch on the colours bar
emmanuelchio 0:cfce61ec00c6 641 lcd.memoryRead(touch[XCOORD],touch[YCOORD],touch[XCOORD],touch[YCOORD],pixelArray); //assign new colour based on touch coordinates and memory read, this function return a 24 bit pixel array,
emmanuelchio 0:cfce61ec00c6 642 colPaint=RGB888ToRGB565(pixelArray);
emmanuelchio 0:cfce61ec00c6 643 lcd.drawCircle(25,34,14,colPaint,FILL); //draw new selected colour on top left corner
emmanuelchio 0:cfce61ec00c6 644 }
emmanuelchio 0:cfce61ec00c6 645 }else{ //Touch on drawing area
emmanuelchio 0:cfce61ec00c6 646 if((touch[YCOORD]-penSize)<67){ // If the touch was very close to the menu, we compensate the radius
emmanuelchio 0:cfce61ec00c6 647 touch[YCOORD]=touch[YCOORD]+penSize;
emmanuelchio 0:cfce61ec00c6 648 }
emmanuelchio 0:cfce61ec00c6 649 lcd.drawCircle(touch[XCOORD],touch[YCOORD],penSize,colPaint,FILL); //Draw
emmanuelchio 0:cfce61ec00c6 650 }
emmanuelchio 0:cfce61ec00c6 651 }
emmanuelchio 0:cfce61ec00c6 652 }
emmanuelchio 0:cfce61ec00c6 653 //End of applications
emmanuelchio 0:cfce61ec00c6 654 /**************************************************/
emmanuelchio 0:cfce61ec00c6 655
emmanuelchio 0:cfce61ec00c6 656
emmanuelchio 0:cfce61ec00c6 657 /**************************************************/
emmanuelchio 0:cfce61ec00c6 658 /****************** MAIN LOOP *********************/
emmanuelchio 0:cfce61ec00c6 659 /**************************************************/
emmanuelchio 0:cfce61ec00c6 660 /**************************************************/
emmanuelchio 0:cfce61ec00c6 661 /***************************************************/
emmanuelchio 0:cfce61ec00c6 662 int main() {
emmanuelchio 0:cfce61ec00c6 663 lcd.reset(); //physically reset SMARTGPU
emmanuelchio 0:cfce61ec00c6 664 lcd.start(); //initialize the SMARTGPU processor
emmanuelchio 0:cfce61ec00c6 665
emmanuelchio 0:cfce61ec00c6 666 unsigned char ic;
emmanuelchio 0:cfce61ec00c6 667
emmanuelchio 0:cfce61ec00c6 668 lcd.baudChange(2000000); //set high baud for advanced applications
emmanuelchio 0:cfce61ec00c6 669
emmanuelchio 0:cfce61ec00c6 670 while(1){
emmanuelchio 0:cfce61ec00c6 671 //load Desktop
emmanuelchio 0:cfce61ec00c6 672 lcd.imageSD(0,0,"WinDesk");
emmanuelchio 0:cfce61ec00c6 673 ic=0;
emmanuelchio 0:cfce61ec00c6 674
emmanuelchio 0:cfce61ec00c6 675 while(ic==0){ //loop until we get a click on one application
emmanuelchio 0:cfce61ec00c6 676 do{
emmanuelchio 0:cfce61ec00c6 677 while(lcd.touchScreen(touch)==0); //Wait for touch
emmanuelchio 0:cfce61ec00c6 678 }while(touch[XCOORD]>20 | touch[YCOORD]<220); //Wait for touch on Start Menu
emmanuelchio 0:cfce61ec00c6 679 //pop up start menu
emmanuelchio 0:cfce61ec00c6 680 lcd.imageSD(0,8,"WinMenu");
emmanuelchio 0:cfce61ec00c6 681 while(lcd.touchScreen(touch)==0); //Wait for touch
emmanuelchio 0:cfce61ec00c6 682 if(touch[XCOORD]<70 & touch[YCOORD]> 8 & touch[YCOORD]< 230){ //If touch on menu
emmanuelchio 0:cfce61ec00c6 683 ic=((touch[YCOORD]-8)/27)+1; //divide (222pixels/8)=27 and add 1, to get the icon number
emmanuelchio 0:cfce61ec00c6 684 } //else go back
emmanuelchio 0:cfce61ec00c6 685 lcd.imageSD(0,0,"MenClose"); //close menu
emmanuelchio 0:cfce61ec00c6 686 }
emmanuelchio 0:cfce61ec00c6 687
emmanuelchio 0:cfce61ec00c6 688 //begin application based on icon number
emmanuelchio 0:cfce61ec00c6 689 switch(ic){ //now that we know a touch was made on a specified icon:
emmanuelchio 0:cfce61ec00c6 690 case 1: //case 1 (clock)
emmanuelchio 0:cfce61ec00c6 691 clocks();
emmanuelchio 0:cfce61ec00c6 692 break; //end of case 1
emmanuelchio 0:cfce61ec00c6 693
emmanuelchio 0:cfce61ec00c6 694 case 2: //case 2 (notes)
emmanuelchio 0:cfce61ec00c6 695 notes();
emmanuelchio 0:cfce61ec00c6 696 break; //end of case 2
emmanuelchio 0:cfce61ec00c6 697
emmanuelchio 0:cfce61ec00c6 698 case 3: //case 3 (calculator)
emmanuelchio 0:cfce61ec00c6 699 calculator();
emmanuelchio 0:cfce61ec00c6 700 break; //end of case 3
emmanuelchio 0:cfce61ec00c6 701
emmanuelchio 0:cfce61ec00c6 702 case 4: //case 4 (pong)
emmanuelchio 0:cfce61ec00c6 703 pong();
emmanuelchio 0:cfce61ec00c6 704 break; //end of case 4
emmanuelchio 0:cfce61ec00c6 705
emmanuelchio 0:cfce61ec00c6 706 case 5: //case 5 (slide show)
emmanuelchio 0:cfce61ec00c6 707 slideShow();
emmanuelchio 0:cfce61ec00c6 708 break; //end case 5
emmanuelchio 0:cfce61ec00c6 709
emmanuelchio 0:cfce61ec00c6 710 case 6: //case 6 (settings)
emmanuelchio 0:cfce61ec00c6 711 settings();
emmanuelchio 0:cfce61ec00c6 712 break; //end case 6
emmanuelchio 0:cfce61ec00c6 713
emmanuelchio 0:cfce61ec00c6 714 case 7: //case 7 (paintPro)
emmanuelchio 0:cfce61ec00c6 715 paint();
emmanuelchio 0:cfce61ec00c6 716 break; //end of case 7
emmanuelchio 0:cfce61ec00c6 717
emmanuelchio 0:cfce61ec00c6 718 case 8: //case 8 (googleMaps)
emmanuelchio 0:cfce61ec00c6 719 googleMaps();
emmanuelchio 0:cfce61ec00c6 720 break; //end of case 8
emmanuelchio 0:cfce61ec00c6 721
emmanuelchio 0:cfce61ec00c6 722 default: //default for any other case
emmanuelchio 0:cfce61ec00c6 723 break; //do nothing
emmanuelchio 0:cfce61ec00c6 724 }
emmanuelchio 0:cfce61ec00c6 725 }
emmanuelchio 0:cfce61ec00c6 726 }