SMARTGPU Ipod like demo! Be sure to load images to micro SD card first!

Dependencies:   SMARTGPU mbed

Committer:
emmanuelchio
Date:
Wed Sep 14 05:32:37 2011 +0000
Revision:
0:26a6123c8cd4
Rev 1.0

Who changed what in which revision?

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