Components and supplies
1
Arduino Mega 2560
Tools and machines
1
3D Printer (generic)
Apps and platforms
1
Arduino IDE
Project description
Code
Retro Arcade Clock
c_cpp
Arduino IDE
1/* Retro Arcade Clock - TechKiwigadgets 2V1 - First Production Release 3*/ 4 5#include <UTFT.h> 6#include <URTouch.h> 7#include <EEPROM.h> 8#include <Time.h> 9#include <Wire.h> 10#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t 11 12// Alarm Variables 13boolean alarmstatus = false; // flag where false is off and true is on 14boolean soundalarm = false; // Flag to indicate the alarm needs to be initiated 15int alarmhour = 0; // hour of alarm setting 16int alarmminute = 0; // Minute of alarm setting 17byte ahour; //Byte variable for hour 18byte amin; //Byte variable for minute 19int actr = 300; // When alarm sounds this is a counter used to reset sound card until screen touched 20int act = 0; 21 22int p = 0; // Animation position E.G Pacman Graphic Flag 0 = Closed, 1 = Medium Open, 2 = Wide Open, 3 = Medium Open 23int m = 0; // Animation position mario 3 postions 24 25// Graphics X,Y coordinates 26 27// myGLCD.drawBitmap (30, 14, 40, 40, rd_ghost); // Closed Ghost 28int ghostX = 15; 29int ghostY = 14; 30int ghostD = 0; // direction d == 0 = right, 1 = down, 2 = left, 3 = up 31 32// myGLCD.drawBitmap (140, 14, 40, 40, MarioR3); // Closed Ghost 33int MarioX = 141; 34int MarioY = 14; 35int MarioD = 0; // direction d == 0 = right, 1 = down, 2 = left, 3 = up 36 37// myGLCD.drawBitmap (240, 14, 40, 40, Monkey2); // Closed Ghost 38int MonkeyX = 261; 39int MonkeyY = 14; 40int MonkeyD = 0; // direction d == 0 = right, 1 = down, 2 = left, 3 = up 41 42 43// myGLCD.drawBitmap (30, 180, 40, 40, pacman); // Closed Ghost 44int pacmanX = 15; 45int pacmanY = 185; 46int pacmanD = 2; // direction d == 0 = right, 1 = down, 2 = left, 3 = up 47 48 49// myGLCD.drawBitmap (140, 180, 40, 40, Alien); // Closed Ghost 50int AlienX = 141; 51int AlienY = 185; 52int AlienD = 2; // direction d == 0 = right, 1 = down, 2 = left, 3 = up 53 54 55// myGLCD.drawBitmap (240, 180, 40, 40, Cannon); // Closed Ghost 56int CannonX = 270; 57int CannonY = 185; 58int CannonD = 2; // direction d == 0 = right, 1 = down, 2 = left, 3 = up 59 60 61// Initializes RTC time values: 62const int DS1307 = 0x68; // Address of DS1307 see data sheets 63 64// Display Dimmer Variables 65int dimscreen = 255; // This variable is used to drive the screen brightness where 255 is max brightness 66int LDR = 100; // LDR variable measured directly from Analog 7 67 68 69 70//==== Creating Objects 71UTFT myGLCD(SSD1289,38,39,40,41); //Parameters should be adjusted to your Display/Schield model 72URTouch myTouch( 6, 5, 4, 3, 2); 73 74//==== Defining Fonts 75extern uint8_t SmallFont[]; 76extern uint8_t BigFont[]; 77extern uint8_t SevenSegNumFont[]; 78extern uint8_t SevenSeg_XXXL_Num[]; 79 80// Define bitmaps 81 82extern unsigned int Alien1[0x640]; // Alien 1 graphic 83extern unsigned int Alien2[0x640]; // Alien 2 graphic 84extern unsigned int Cannon[0x640]; // Space invaders cannon 85 86extern unsigned int MarioL1[0x310]; // M Left 1 87extern unsigned int MarioL2[0x310]; // Ghost Bitmap Straight ahead 88extern unsigned int MarioL3[0x310]; // Ghost Bitmap Straight ahead 89extern unsigned int MarioR1[0x310]; // Ghost Bitmap Straight ahead 90extern unsigned int MarioR2[0x310]; // Ghost Bitmap Straight ahead 91extern unsigned int MarioR3[0x310]; // Ghost Bitmap Straight ahead 92extern unsigned int MarioStop[0x310]; // Ghost Bitmap Straight ahead 93extern unsigned int MarioU1[0x310]; // Ghost Bitmap Straight ahead 94extern unsigned int MarioU2[0x310]; // Ghost Bitmap Straight ahead 95extern unsigned int MarioU3[0x310]; // Ghost Bitmap Straight ahead 96extern unsigned int MarioU4[0x310]; // Ghost Bitmap Straight ahead 97 98extern unsigned int rd_ghost[784]; // Ghost Bitmap Straight ahead 99extern unsigned int ru_ghost[784]; // Ghost Bitmap Straight ahead 100extern unsigned int rl_ghost[784]; // Ghost Bitmap Straight ahead 101extern unsigned int rr_ghost[784]; // Ghost Bitmap Straight ahead 102 103 104extern unsigned int r_o_pacman[784]; // Ghost Bitmap Straight ahead 105extern unsigned int r_m_pacman[784]; // Ghost Bitmap Straight ahead 106extern unsigned int l_o_pacman[784]; // Ghost Bitmap Straight ahead 107extern unsigned int l_m_pacman[784]; // Ghost Bitmap Straight ahead 108extern unsigned int u_m_pacman[784]; // Ghost Bitmap Straight ahead 109extern unsigned int u_o_pacman[784]; // Ghost Bitmap Straight ahead 110extern unsigned int d_m_pacman[784]; // Ghost Bitmap Straight ahead 111extern unsigned int d_o_pacman[784]; // Ghost Bitmap Straight ahead 112extern unsigned int c_pacman[784]; // Ghost Bitmap Straight ahead 113 114 115extern unsigned int Monkey2[0x640]; // Ghost Bitmap Straight ahead 116extern unsigned int Monkey3[0x640]; // Ghost Bitmap Straight ahead 117 118 119// Touch screen coordinates 120boolean screenPressed = false; 121int xT,yT; 122int userT = 4; // flag to indicate directional touch on screen 123boolean setupscreen = false; // used to access the setup screen 124 125//Alarm setup variables 126boolean xsetup = false; // Flag to determine if existing setup mode 127 128 129// Animation delay to slow movement down 130int dly = 0; // Orignally 30 131 132 133// Time Refresh counter 134int rfcvalue = 300; // wait this long untiul check time for changes 135int rfc = 1; 136 137 138// Declare global variables for previous time, to enable refesh of only digits that have changed 139// There are four digits that bneed to be drawn independently to ensure consisitent positioning of time 140 int c1 = 20; // Tens hour digit 141 int c2 = 20; // Ones hour digit 142 int c3 = 20; // Tens minute digit 143 int c4 = 20; // Ones minute digit 144 145 146void setup() { 147 148//Initialize RTC 149 Serial.begin(9600); 150 // while (!Serial) ; // wait until Arduino Serial Monitor opens 151 delay(200); 152 setSyncProvider(RTC.get); // the function to get the time from the RTC 153 setSyncInterval(60); // sync the time every 60 seconds (1 minutes) 154 if(timeStatus()!= timeSet){ 155 Serial.println("Unable to sync with the RTC"); 156 RTC.set(1408278800); // set the RTC to Aug 25 2014 9:00 am 157 setTime(1408278800); 158 } 159 else{ 160 Serial.println("RTC has set the system time"); 161 } 162 163// Setup Alarm enable pin to play back sound on the ISD1820 board 164 pinMode(8, OUTPUT); // D8 used to toggle sound 165 digitalWrite(8,LOW); // Set to low to turn off sound 166 167 // Initiate display 168 myGLCD.InitLCD(); 169 myGLCD.clrScr(); 170 myTouch.InitTouch(); 171 myTouch.setPrecision(PREC_LOW); 172 173 174 drawscreen(); // Initiate the game 175 UpdateDisp(); // update value to clock 176 177 178} 179 180void loop() { 181 182// increment Pacman Graphic Flag 0 = Closed, 1 = Medium Open, 2 = Wide Open 183p=p+1; 184if(p==4){ 185 p=0; // Reset counter to closed 186} 187 188// increment Pacman Graphic Flag 0 = Closed, 1 = Medium Open, 2 = Wide Open 189m=m+1; 190if(m==3){ 191 m=0; // Reset counter to closed 192} 193 194// Set Screen Brightness 195// Check the ambient light and adjust LED brightness to suit Ambient approx 500 dark is below 100 196LDR = analogRead(A7); 197 198/* Test value range of LDR 199 myGLCD.setColor(237, 28, 36); 200 myGLCD.setBackColor(0, 0, 0); 201 myGLCD.printNumI(LDR,250,60); 202*/ 203 204if (LDR >=121){ 205 dimscreen = 255; 206 } 207 208if (LDR <=120) { 209 dimscreen = 45; 210 } 211 212analogWrite(9, dimscreen); // Controls brightness 0 is Dark, Ambient room is approx 25 and 70 is direct sunlight 213 214 215 216// Read the current date and time from the RTC and reset board 217rfc++; 218 if (rfc >= rfcvalue) { // count cycles and print time 219 UpdateDisp(); // update value to clock then ... 220 dly = 18; // reset delay 221 rfc = 0; 222 223 } 224 225//=== Check if Alarm needs to be sounded 226 if (alarmstatus == true){ 227 if ( (alarmhour == hour()) && (alarmminute == minute())) { // Sound the alarm 228 soundalarm = true; 229 } 230 } 231 232//=== Start Alarm Sound - Sound pays for 10 seconds then will restart at 20 second mark 233 234if ((alarmstatus == true)&&(soundalarm==true)){ // Set off a counter and take action to restart sound if screen not touched 235 236 if (act == 0) { // Set off alarm by toggling D8, recorded sound triggered by LOW to HIGH transition 237 digitalWrite(8,HIGH); // Set high 238 digitalWrite(8,LOW); // Set low 239 UpdateDisp(); // update value to clock 240 } 241 act = act +1; 242 243 if (act == actr) { // Set off alarm by toggling D8, recorded sound triggered by LOW to HIGH transition 244 digitalWrite(8,HIGH); // Set high 245 digitalWrite(8,LOW); // Set low 246 act = 0; // Reset counter hopfully every 20 seconds 247 } 248 249} 250 251// Check if user input to touch screen 252// UserT sets direction 0 = right, 1 = down, 2 = left, 3 = up, 4 = no touch input 253 254 255 myTouch.read(); 256 if (myTouch.dataAvailable() && !screenPressed) { 257 xT = myTouch.getX(); 258 yT = myTouch.getY(); 259 260 // ********************************** 261 // ******* Enter Setup Mode ********* 262 // ********************************** 263 264 if (((xT>=120) && (xT<=200) && (yT>=105) && (yT<=140)) && (soundalarm !=true)) { // Call Setup Routine if alarm is not sounding 265 xsetup = true; // Toggle flag 266 clocksetup(); // Call Clock Setup Routine 267 UpdateDisp(); // update value to clock 268 269 } else // If centre of screen touched while alarm sounding then turn off the sound and reset the alarm to not set 270 271 if (((xT>=120) && (xT<=200) && (yT>=105) && (yT<=140)) && ((alarmstatus == true) && (soundalarm ==true))) { 272 273 alarmstatus = false; 274 soundalarm = false; 275 digitalWrite(8,LOW); // Set low 276 } 277 screenPressed = true; 278 } 279 // Doesn't allow holding the screen / you must tap it 280 else if ( !myTouch.dataAvailable() && screenPressed){ 281 screenPressed = false; 282 } 283 284 285 286drawghost(ghostX, ghostY, ghostD, p); // Increment position and Draw image 287 288// ghost Direction // 289// direction d == 0 = right, 1 = down, 2 = left, 3 = up 290 291if(ghostD == 0){ // Right 292 // Increment Counter and test results 293 ghostX = ghostX + 3; 294 if (ghostX == 270){ 295 myGLCD.fillRect(ghostX-3, ghostY, ghostX, ghostY+28); // Clear trail off graphic before changing position 296 ghostD = 1; // Change direction down 297 } 298} else if(ghostD == 1) { // Down 299 // Increment Counter and test results 300 ghostY = ghostY + 3; 301 if (ghostY == 185){ 302 myGLCD.fillRect(ghostX+3, ghostY-3, ghostX+36, ghostY); // Clear trail off graphic before changing position 303 ghostD = 2; // Change direction down 304 } 305} else if(ghostD == 2) { // Left 306 // Increment Counter and test results 307 ghostX = ghostX - 3; 308 if (ghostX == 12){ 309 myGLCD.fillRect(ghostX+28, ghostY, ghostX+31, ghostY+28); // Clear trail off graphic before printing new positi 310 ghostD = 3; // Change direction down 311 } 312} else if(ghostD == 3) { // Up 313 // Increment Counter and test results 314 ghostY = ghostY - 3; 315 if (ghostY == 14){ 316 myGLCD.fillRect(ghostX, ghostY+29, ghostX+28, ghostY+28); // Clear trail off graphic before printing new position 317 ghostD = 0; // Change direction down 318 } 319} 320 321 322drawMonkey(MonkeyX, MonkeyY, MonkeyD, p); // Increment position and Draw image 323 324// Monkey Direction // 325// direction d == 0 = right, 1 = down, 2 = left, 3 = up 326 327if(MonkeyD == 0){ // Right 328 // Increment Counter and test results 329 MonkeyX = MonkeyX + 3; 330 if (MonkeyX == 270){ 331 myGLCD.fillRect(MonkeyX-3, MonkeyY, MonkeyX, MonkeyY+40); // Clear trail off graphic before changing direction 332 MonkeyD = 1; // Change direction down 333 } 334} else if(MonkeyD == 1) { // Down 335 // Increment Counter and test results 336 MonkeyY = MonkeyY + 3; 337 if (MonkeyY == 185){ 338 myGLCD.fillRect(MonkeyX+3, MonkeyY-3, MonkeyX+38, MonkeyY); // Clear trail off graphic before printing new position 339 MonkeyD = 2; // Change direction down 340 } 341} else if(MonkeyD == 2) { // Left 342 // Increment Counter and test results 343 MonkeyX = MonkeyX - 3; 344 if (MonkeyX == 12){ 345 myGLCD.fillRect(MonkeyX+41, MonkeyY+1, MonkeyX+40, MonkeyY+38); // Clear trail off graphic before printing new positi 346 MonkeyD = 3; // Change direction down 347 } 348} else if(MonkeyD == 3) { // Up 349 // Increment Counter and test results 350 MonkeyY = MonkeyY - 3; 351 if (MonkeyY == 14){ 352 myGLCD.fillRect(MonkeyX, MonkeyY+38, MonkeyX+40, MonkeyY+43); // Clear trail off graphic before printing new position 353 MonkeyD = 0; // Change direction down 354 } 355} 356 357 358drawCannon(CannonX, CannonY, CannonD, p); // Increment position and Draw image 359 360// Cannon Direction // 361// direction d == 0 = right, 1 = down, 2 = left, 3 = up 362 363if(CannonD == 0){ // Right 364 // Increment Counter and test results 365 CannonX = CannonX + 3; 366 if (CannonX == 270){ 367 myGLCD.fillRect(CannonX-3, CannonY+3, CannonX, CannonY+36); // Clear trail off graphic before changing direction 368 CannonD = 1; // Change direction down 369 } 370} else if(CannonD == 1) { // Down 371 // Increment Counter and test results 372 CannonY = CannonY + 3; 373 if (CannonY == 185){ 374 CannonD = 2; // Change direction down 375 } 376} else if(CannonD == 2) { // Left 377 // Increment Counter and test results 378 CannonX = CannonX - 3; 379 if (CannonX == 12){ 380 myGLCD.fillRect(CannonX+41, CannonY+3, CannonX+40, CannonY+36); // Clear trail off graphic before printing new positi 381 CannonD = 3; // Change direction down 382 } 383} else if(CannonD == 3) { // Up 384 // Increment Counter and test results 385 CannonY = CannonY - 3; 386 if (CannonY == 14){ 387 CannonD = 0; // Change direction down 388 } 389} 390 391 392drawpacman(pacmanX, pacmanY, pacmanD, p); // Increment position and Draw image 393 394// pacman Direction // 395// direction d == 0 = right, 1 = down, 2 = left, 3 = up 396 397if(pacmanD == 0){ // Right 398 // Increment Counter and test results 399 pacmanX = pacmanX + 3; 400 if (pacmanX == 270){ 401 myGLCD.fillRect(pacmanX-3, pacmanY+3, pacmanX, pacmanY+36); // Clear trail off graphic before changing direction 402 pacmanD = 1; // Change direction down 403 } 404} else if(pacmanD == 1) { // Down 405 // Increment Counter and test results 406 pacmanY = pacmanY + 3; 407 if (pacmanY == 185){ 408 myGLCD.fillRect(pacmanX+3, pacmanY-3, pacmanX+36, pacmanY); // Clear trail off graphic before changing position 409 pacmanD = 2; // Change direction down 410 } 411} else if(pacmanD == 2) { // Left 412 // Increment Counter and test results 413 pacmanX = pacmanX - 3; 414 if (pacmanX == 12){ 415 myGLCD.fillRect(pacmanX+28, pacmanY, pacmanX+31, pacmanY+28); // Clear trail off graphic before printing new positi 416 pacmanD = 3; // Change direction down 417 } 418} else if(pacmanD == 3) { // Up 419 // Increment Counter and test results 420 pacmanY = pacmanY - 3; 421 if (pacmanY == 14){ 422 myGLCD.fillRect(pacmanX, pacmanY+29, pacmanX+28, pacmanY+28); // Clear trail off graphic before printing new position 423 pacmanD = 0; // Change direction down 424 } 425} 426 427 428drawAlien(AlienX, AlienY, AlienD, p); // Increment position and Draw image 429 430// Alien Direction // 431// direction d == 0 = right, 1 = down, 2 = left, 3 = up 432 433if(AlienD == 0){ // Right 434 // Increment Counter and test results 435 AlienX = AlienX + 3; 436 if (AlienX == 270){ 437 myGLCD.fillRect(AlienX-3, AlienY+3, AlienX, AlienY+36); // Clear trail off graphic before changing direction 438 AlienD = 1; // Change direction down 439 } 440} else if(AlienD == 1) { // Down 441 // Increment Counter and test results 442 AlienY = AlienY + 3; 443 if (AlienY == 185){ 444 AlienD = 2; // Change direction down 445 } 446} else if(AlienD == 2) { // Left 447 // Increment Counter and test results 448 AlienX = AlienX - 3; 449 if (AlienX == 12){ 450 myGLCD.fillRect(AlienX+41, AlienY+3, AlienX+40, AlienY+36); // Clear trail off graphic before printing new positi 451 AlienD = 3; // Change direction down 452 } 453} else if(AlienD == 3) { // Up 454 // Increment Counter and test results 455 AlienY = AlienY - 3; 456 if (AlienY == 14){ 457 AlienD = 0; // Change direction down 458 } 459} 460 461 462drawMario(MarioX, MarioY, MarioD, p); // Increment position and Draw image 463 464// Mario Direction // 465// direction d == 0 = right, 1 = down, 2 = left, 3 = up 466 467if(MarioD == 0){ // Right 468 // Increment Counter and test results 469 MarioX = MarioX + 3; 470 if (MarioX == 270){ 471 myGLCD.fillRect(MarioX-3, MarioY+3, MarioX, MarioY+36); // Clear trail off graphic before changing direction 472 MarioD = 1; // Change direction down 473 } 474} else if(MarioD == 1) { // Down 475 // Increment Counter and test results 476 MarioY = MarioY + 3; 477 if (MarioY == 185){ 478 myGLCD.fillRect(MarioX+3, MarioY-3, MarioX+36, MarioY); // Clear trail off graphic before printing new position 479 MarioD = 2; // Change direction down 480 } 481} else if(MarioD == 2) { // Left 482 // Increment Counter and test results 483 MarioX = MarioX - 3; 484 if (MarioX == 12){ 485 MarioD = 3; // Change direction down 486 } 487} else if(MarioD == 3) { // Up 488 // Increment Counter and test results 489 MarioY = MarioY - 3; 490 if (MarioY == 14){ 491 myGLCD.fillRect(MarioX, MarioY+30, MarioX+28, MarioY+28); // Clear trail off graphic before printing new position 492 MarioD = 0; // Change direction down 493 } 494} 495 496 497 498 499 500delay(dly); 501 502 503 504} 505 506// ************************************************************************************************************ 507// ===== Update Digital Clock 508// ************************************************************************************************************ 509 void UpdateDisp(){ 510 511// Clear the time area 512 myGLCD.setColor(0, 0, 0); 513 myGLCD.setBackColor(0, 0, 0); 514// myGLCD.fillRect(60, 80 ,262, 166); 515 516 517 int h; // Hour value in 24 hour format 518 int e; // Minute value in minute format 519 int pm = 0; // Flag to detrmine if PM or AM 520 521 // There are four digits that need to be drawn independently to ensure consisitent positioning of time 522 int d1; // Tens hour digit 523 int d2; // Ones hour digit 524 int d3; // Tens minute digit 525 int d4; // Ones minute digit 526 527 528 h = hour(); // 24 hour RT clock value 529 e = minute(); 530 531/* TEST 532h = 12; 533e = 8; 534*/ 535 536 537// Calculate hour digit values for time 538 539if ((h >= 10) && (h <= 12)) { // AM hours 10,11,12 540 d1 = 1; // calculate Tens hour digit 541 d2 = h - 10; // calculate Ones hour digit 0,1,2 542 } else 543 if ( (h >= 22) && (h <= 24)) { // PM hours 10,11,12 544 d1 = 1; // calculate Tens hour digit 545 d2 = h - 22; // calculate Ones hour digit 0,1,2 546 } else 547 if ((h <= 9)&&(h >= 1)) { // AM hours below ten 548 d1 = 0; // calculate Tens hour digit 549 d2 = h; // calculate Ones hour digit 0,1,2 550 } else 551 if ( (h >= 13) && (h <= 21)) { // PM hours below 10 552 d1 = 0; // calculate Tens hour digit 553 d2 = h - 12; // calculate Ones hour digit 0,1,2 554 } else { 555 // If hour is 0 556 d1 = 1; // calculate Tens hour digit 557 d2 = 2; // calculate Ones hour digit 0,1,2 558 } 559 560 561// Calculate minute digit values for time 562 563if ((e >= 10)) { 564 d3 = e/10 ; // calculate Tens minute digit 1,2,3,4,5 565 d4 = e - (d3*10); // calculate Ones minute digit 0,1,2 566 } else { 567 // e is less than 10 568 d3 = 0; 569 d4 = e; 570 } 571 572 573if (h>=12){ // Set 574// h = h-12; // Work out value 575 pm = 1; // Set PM flag 576} 577 578// ************************************************************************* 579// Print each digit if it has changed to reduce screen impact/flicker 580 581// Set digit font colour to white 582 583 myGLCD.setColor(255, 255, 255); 584 585 myGLCD.setBackColor(0, 0, 0); 586 myGLCD.setFont(SevenSeg_XXXL_Num); 587 588// First Digit 589if(((d1 != c1)||(xsetup == true))&&(d1 != 0)){ // Do not print zero in first digit position 590 myGLCD.printNumI(d1,10,70); // Printing thisnumber impacts LFH walls so redraw impacted area 591 592// ---------------- Clear lines on Outside wall 593 myGLCD.setColor(0,0,0); 594 myGLCD.drawRoundRect(1, 238, 318, 1); 595 596} 597 598//If prevous time 12:59 or 00:59 and change in time then blank First Digit 599 600if((c1 == 1) && (c2 == 2) && (c3 == 5) && (c4 == 9) && (d2 != c2) ){ // Clear the previouis First Digit and redraw wall 601 602 myGLCD.setColor(0,0,0); 603 myGLCD.fillRect(50, 70, 70, 165); 604 605 606} 607 608if((c1 == 0) && (c2 == 0) && (c3 == 5) && (c4 == 9) && (d2 != c2) ){ // Clear the previouis First Digit and redraw wall 609 610 myGLCD.setColor(0,0,0); 611 myGLCD.fillRect(50, 70, 70, 165); 612 613 614} 615 616 617 618 myGLCD.setColor(255, 255, 255); 619 myGLCD.setBackColor(0, 0, 0); 620 myGLCD.setFont(SevenSeg_XXXL_Num); 621 622// Second Digit 623if((d2 != c2)||(xsetup == true)){ 624 myGLCD.printNumI(d2,70,70); // Print 0 625} 626 627// Third Digit 628if((d3 != c3)||(xsetup == true)){ 629 myGLCD.printNumI(d3,143,70); // Was 145 630} 631 632// Fourth Digit 633if((d4 != c4)||(xsetup == true)){ 634 myGLCD.printNumI(d4,204,70); // Was 205 635} 636 637if (xsetup == true){ 638 xsetup = false; // Reset Flag now leaving setup mode 639 } 640 // Print PM or AM 641 642// myGLCD.setColor(1, 73, 240); 643 myGLCD.setBackColor(0, 0, 0); 644 myGLCD.setFont(BigFont); 645 if (pm == 0) { 646 myGLCD.print("AM", 270, 147); 647 } else { 648 myGLCD.print("PM", 270, 147); 649 } 650 651// ----------- Alarm Set on LHS lower pillar 652if (alarmstatus == true) { // Print AS on fron screenleft hand side 653 myGLCD.print("AS", 7, 147); 654} 655 656 657 // Round dots 658 659 myGLCD.setColor(255, 255, 255); 660 myGLCD.setBackColor(0, 0, 0); 661 myGLCD.fillCircle(137, 105, 5); 662 myGLCD.fillCircle(137, 135, 5); 663 664 665 666 667 668//--------------------- copy exising time digits to global variables so that these can be used to test which digits change in future 669 670c1 = d1; 671c2 = d2; 672c3 = d3; 673c4 = d4; 674 675} 676 677 678 679 680// ===== initiateGame - Custom Function 681void drawscreen() { 682 683 684 // Setup Clock Background 685 //Draw Background lines 686 687 myGLCD.setColor(1, 73, 240); 688// myGLCD.setColor(229, 14, 122); 689// myGLCD.setColor(255, 0, 131); 690// ---------------- Outside wall 691 692 myGLCD.drawRoundRect(0, 239, 319, 0); 693 myGLCD.drawRoundRect(2, 237, 317, 2); 694 695 696 myGLCD.drawBitmap (ghostX, ghostY, 28, 28, rd_ghost); // Closed Ghost 697 myGLCD.drawBitmap (MarioX, MarioY, 28, 28, MarioR3); // Closed Ghost 698 myGLCD.drawBitmap (MonkeyX, MonkeyY, 40, 40, Monkey2); // Closed Ghost 699 700 myGLCD.drawBitmap (pacmanX, pacmanY, 28, 28, r_o_pacman); // Closed Ghost 701 myGLCD.drawBitmap (AlienX, AlienY, 40, 40, Alien1); // Closed Ghost 702 myGLCD.drawBitmap (CannonX, CannonY, 40, 40, Cannon); // Closed Ghost 703 } 704 705 706 707 // ********************************** 708 // ******* Enter Setup Mode ********* 709 // ********************************** 710 // Use up down arrows to change time and alrm settings 711 712 void clocksetup(){ 713 714int timehour = hour(); 715int timeminute = minute(); 716 717// Read Alarm Set Time from Eeprom 718 719 // read a byte from the current address of the EEPROM 720 ahour = EEPROM.read(100); 721 alarmhour = (int)ahour; 722 if (alarmhour >24 ) { 723 alarmhour = 0; 724 } 725 726 amin = EEPROM.read(101); 727 alarmminute = (int)amin; 728 if (alarmminute >60 ) { 729 alarmminute = 0; 730 } 731 732 733boolean savetimealarm = false; // If save button pushed save the time and alarm 734 735 // Setup Screen 736 myGLCD.clrScr(); 737// ---------------- Outside wall 738 739 myGLCD.setColor(255, 255, 0); 740 myGLCD.setBackColor(0, 0, 0); 741 742 myGLCD.drawRoundRect(0, 239, 319, 0); 743 myGLCD.drawRoundRect(2, 237, 317, 2); 744 745//Reset screenpressed flag 746screenPressed = false; 747 748// Read in current clock time and Alarm time 749 750 751 752 // Setup buttons 753 myGLCD.setFont(BigFont); 754 755 // Time Set buttons 756 myGLCD.print("+ +", 135, 38); 757 myGLCD.print("- -", 135, 82); 758 myGLCD.drawRoundRect(132, 35, 152, 55); // time hour + 759 myGLCD.drawRoundRect(180, 35, 200, 55); // time minute + 760 761 myGLCD.drawRoundRect(132, 80, 152, 100); // time hour - 762 myGLCD.drawRoundRect(180, 80, 200, 100); // time minute - 763 764 // Alarm Set buttons 765 myGLCD.print("+ +", 135, 138); 766 myGLCD.print("- -", 135, 182); 767 myGLCD.drawRoundRect(132, 135, 152, 155); // alarm hour + 768 myGLCD.drawRoundRect(180, 135, 200, 155); // alarm minute + 769 770 myGLCD.drawRoundRect(132, 180, 152, 200); // alarm hour - 771 myGLCD.drawRoundRect(180, 180, 200, 200); // alarm minute - 772 773 774 775 776 myGLCD.print("SAVE", 13, 213); 777 myGLCD.print("EXIT", 245, 213); 778 myGLCD.drawRoundRect(10, 210, 80, 230); 779 myGLCD.drawRoundRect(243, 210, 310, 230); 780 781// Get your Ghost on 782 myGLCD.drawBitmap (50, 20, 28, 28, rd_ghost); // Closed Ghost 783 myGLCD.drawBitmap (240, 100, 28, 28, r_o_pacman); // Closed Ghost 784 myGLCD.drawBitmap (240, 20, 40, 40, Alien1); // Closed Ghost 785 786// Begin Loop here 787 788while (xsetup == true){ 789 790 791 if (alarmstatus == true){ // flag where false is off and true is on 792 myGLCD.print("SET", 220, 160); 793 } else { 794 myGLCD.print("OFF", 220, 160); 795 } 796 myGLCD.drawRoundRect(218, 157, 268, 177); 797 798// Draw Sound Button 799 800 myGLCD.print("TEST", 50, 110); // Triggers alarm sound 801 myGLCD.drawRoundRect(48, 108, 116, 128); 802 803// Display Current Time 804 805 myGLCD.print("Time", 40, 60); 806 807 808// myGLCD.printNumI(timehour, 130, 60); 809 if(timehour>=10){ // Annoyingly if number less than 10 doesnt print on RHS and misses zero so need to compensate 810 myGLCD.printNumI(timehour, 130, 60); // If >= 10 just print minute 811 } else { 812 myGLCD.print("0", 130, 60); 813 myGLCD.printNumI(timehour, 146, 60); 814 } 815 816 myGLCD.print(":", 160, 60); 817 818 if(timeminute>=10){ // Annoyingly if number less than 10 doesnt print on RHS and misses zero so need to compensate 819 myGLCD.printNumI(timeminute, 175, 60); // If >= 10 just print minute 820 } else { 821 myGLCD.print("0", 175, 60); 822 myGLCD.printNumI(timeminute, 193, 60); 823 } 824 825 826//Display Current Alarm Setting 827 828 myGLCD.print("Alarm", 40, 160); 829 830 831// myGLCD.printNumI(alarmhour, 130, 160); 832 if(alarmhour>=10){ // Annoyingly if number less than 10 doesnt print on RHS and misses zero so need to compensate 833 myGLCD.printNumI(alarmhour, 130, 160); // If >= 10 just print minute 834 } else { 835 myGLCD.print("0", 130, 160); 836 myGLCD.printNumI(alarmhour, 146, 160); 837 } 838 839 840 841 myGLCD.print(":", 160, 160); 842 843 if(alarmminute>=10){ // Annoyingly if number less than 10 doesnt print on RHS and misses zero so need to compensate 844 myGLCD.printNumI(alarmminute, 175, 160); // If >= 10 just print minute 845 } else { 846 myGLCD.print("0", 175, 160); 847 myGLCD.printNumI(alarmminute, 193, 160); 848 } 849 850// Read input to determine if buttons pressed 851 myTouch.read(); 852 if (myTouch.dataAvailable()) { 853 xT = myTouch.getX(); 854 yT = myTouch.getY(); 855 856 // Capture input command from user 857 if ((xT>=230) && (xT<=319) && (yT>=200) && (yT<=239)) { // (243, 210, 310, 230) Exit Button 858 xsetup = false; // Exit setupmode 859 } 860 861 else if ((xT>=0) && (xT<=90) && (yT>=200) && (yT<=239)) { // (243, 210, 310, 230) Save Alarm and Time Button 862 savetimealarm = true; // Exit and save time and alarm 863 xsetup = false; // Exit setupmode 864 } 865 866 867 else if ((xT>=130) && (xT<=154) && (yT>=32) && (yT<=57)) { // Time Hour + (132, 35, 152, 55) 868 timehour = timehour + 1; // Increment Hour 869 if (timehour == 24) { // reset hour to 0 hours if 24 870 timehour = 0 ; 871 872 } 873 } 874 875 else if ((xT>=130) && (xT<=154) && (yT>=78) && (yT<=102)) { // (132, 80, 152, 100); // time hour - 876 timehour = timehour - 1; // Increment Hour 877 if (timehour == -1) { // reset hour to 23 hours if < 0 878 timehour = 23 ; 879 880 } 881 } 882 883 else if ((xT>=178) && (xT<=202) && (yT>=32) && (yT<=57)) { // Time Minute + (180, 35, 200, 55) 884 timeminute = timeminute + 1; // Increment Hour 885 if (timeminute == 60) { // reset minute to 0 minutes if 60 886 timeminute = 0 ; 887 } 888 } 889 890 else if ((xT>=178) && (xT<=202) && (yT>=78) && (yT<=102)) { // (180, 80, 200, 100); // time minute - 891 timeminute = timeminute - 1; // Increment Hour 892 if (timeminute == -1) { // reset minute to 0 minutes if 60 893 timeminute = 59 ; 894 } 895 } 896 897 else if ((xT>=130) && (xT<=154) && (yT>=133) && (yT<=157)) { // (132, 135, 152, 155); // alarm hour + 898 alarmhour = alarmhour + 1; // Increment Hour 899 if (alarmhour == 24) { // reset hour to 0 hours if 24 900 alarmhour = 0 ; 901 902 } 903 } 904 905 else if ((xT>=130) && (xT<=154) && (yT>=178) && (yT<=202)) { // (132, 180, 152, 200); // alarm hour - 906 alarmhour = alarmhour - 1; // Increment Hour 907 if (alarmhour == -1) { // reset hour to 23 hours if < 0 908 alarmhour = 23 ; 909 910 } 911 } 912 913 else if ((xT>=178) && (xT<=202) && (yT>=133) && (yT<=157)) { // (180, 135, 200, 155); // alarm minute + 914 alarmminute = alarmminute + 1; // Increment Hour 915 if (alarmminute == 60) { // reset minute to 0 minutes if 60 916 alarmminute = 0 ; 917 } 918 } 919 920 else if ((xT>=178) && (xT<=202) && (yT>=178) && (yT<=202)) { // (180, 180, 200, 200); // alarm minute - 921 alarmminute = alarmminute - 1; // Increment Hour 922 if (alarmminute == -1) { // reset minute to 0 minutes if 60 923 alarmminute = 59 ; 924 } 925 } 926 927 else if ((xT>=216) && (xT<=270) && (yT>=155) && (yT<=179)) { // (218, 157, 268, 177); // alarm set button pushed 928 if (alarmstatus == true) { 929 alarmstatus = false; // Turn off Alarm 930 } else { 931 alarmstatus = true; // Turn on Alarm 932 } 933 } 934 else if ((xT>=46) && (xT<=118) && (yT>=106) && (yT<=130)) { // ((48, 108, 116, 128); // alarm test button pushed 935 // Set off alarm by toggling D8, recorded sound triggered by LOW to HIGH transition 936 digitalWrite(8,HIGH); // Set high 937 digitalWrite(8,LOW); // Set low 938 } 939 940 // Should mean changes should scroll if held down 941 delay(250); 942 } 943 944} 945 946 947 948 949if ( savetimealarm == true) { 950 // The following codes transmits the data to the RTC 951 Wire.beginTransmission(DS1307); 952 Wire.write(byte(0)); 953 Wire.write(decToBcd(0)); 954 Wire.write(decToBcd(timeminute)); 955 Wire.write(decToBcd(timehour)); 956 Wire.write(decToBcd(0)); 957 Wire.write(decToBcd(0)); 958 Wire.write(decToBcd(0)); 959 Wire.write(decToBcd(0)); 960 Wire.write(byte(0)); 961 Wire.endTransmission(); 962 // Ends transmission of data 963 964 // Write the Alarm Time to EEPROM so it can be stored when powered off 965 966 //alarmhour = (int)ahour; 967 ahour = (byte)alarmhour; 968 amin = (byte)alarmminute; 969 EEPROM.write(100, ahour); 970 EEPROM.write(101, amin); 971 972 // Now time and alarm data saved reset flag 973 savetimealarm = false; 974} 975 976 977 //* Clear Screen 978 myGLCD.setColor(0, 0, 0); 979 myGLCD.setBackColor(0, 0, 0); 980 myGLCD.fillRect(0,239,319,0); 981 xsetup = true; // Set Flag now leaving setup mode in order to draw Clock Digits 982 setSyncProvider(RTC.get); // the function to get the time from the RTC 983 setSyncInterval(60); // sync the time every 60 seconds (1 minutes) 984 drawscreen(); // Initiate the screen 985 UpdateDisp(); // update value to clock 986 987 } 988 989 // ================= Decimal to BCD converter 990 991byte decToBcd(byte val) { 992 return ((val/10*16) + (val%10)); 993} 994 995 996/* 997 myGLCD.drawBitmap (ghostX, ghostY, 28, 28, ghost); // Closed Ghost 998 myGLCD.drawBitmap (MarioX, MarioY, 40, 40, Mario); // Closed Ghost 999 myGLCD.drawBitmap (MonkeyX, MonkeyY, 40, 40, Monkey); // Closed Ghost 1000 1001 myGLCD.drawBitmap (pacmanX, pacmanY, 28, 28, r_o_pacman); // Closed Ghost 1002 myGLCD.drawBitmap (AlienX, AlienY, 40, 40, Alien); // Closed Ghost 1003 myGLCD.drawBitmap (CannonX, CannonY, 40, 40, Cannon); // Closed Ghost 1004*/ 1005 1006//********************************************************************************************************** 1007//====== Draws the rd_ghost - bitmap 1008void drawghost(int x, int y, int d, int p) { 1009 1010 // Draws the ghost - bitmap 1011 // knotting direction d == 0 = right, 1 = down, 2 = left, 3 = up 1012 myGLCD.setColor(0, 0, 0); 1013 myGLCD.setBackColor(0, 0, 0); 1014 1015 if ( d == 0){ // Right 1016 1017 myGLCD.fillRect(x-3, y, x, y+28); // Clear trail off graphic before printing new position 1018 1019 // draw image 1020 myGLCD.drawBitmap (ghostX, ghostY, 28, 28, rr_ghost); 1021 1022 } else if ( d == 1){ // Down 1023 1024 myGLCD.fillRect(x+3, y-3, x+36, y); // Clear trail off graphic before printing new position 1025 1026 // draw image 1027 myGLCD.drawBitmap (ghostX, ghostY, 28, 28, rd_ghost); 1028 1029 1030 } else if ( d == 2){ // Left 1031 1032 myGLCD.fillRect(x+28, y, x+31, y+28); // Clear trail off graphic before printing new positi 1033 1034 // draw image 1035 myGLCD.drawBitmap (ghostX, ghostY, 28, 28, rl_ghost); 1036 1037 // draw image 1038 1039 } else if ( d == 3){ // Up 1040 1041 myGLCD.fillRect(x, y+29, x+28, y+28); // Clear trail off graphic before printing new position 1042 1043 // draw image 1044 myGLCD.drawBitmap (ghostX, ghostY, 28, 28, ru_ghost); 1045 1046 1047 } 1048 1049} 1050 1051 1052//********************************************************************************************************** 1053//====== Draws the Mario - bitmap 1054void drawMario(int x, int y, int d, int p) { 1055 1056 // Draws the Mario - bitmap 1057 // Mario direction d == 0 = right, 1 = down, 2 = left, 3 = up 1058 myGLCD.setColor(0, 0, 0); 1059 myGLCD.setBackColor(0, 0, 0); 1060 1061 if ( d == 0){ // Right 1062 1063 myGLCD.fillRect(x-3, y+3, x, y+36); // Clear trail off graphic before printing new position 1064 1065 // draw image 1066 if (p==0) { 1067 myGLCD.drawBitmap (MarioX, MarioY, 28, 28, MarioR1); 1068 } else if (p==1) { 1069 myGLCD.drawBitmap (MarioX, MarioY, 28, 28, MarioR3); 1070 } else if (p==2) { 1071 myGLCD.drawBitmap (MarioX, MarioY, 28, 28, MarioR2); 1072 } else if (p==3) { 1073 myGLCD.drawBitmap (MarioX, MarioY, 28, 28, MarioR3); 1074 } 1075 1076 } else if ( d == 1){ // Down 1077 1078 myGLCD.fillRect(x+3, y-3, x+36, y); // Clear trail off graphic before printing new position 1079 1080 // draw image 1081 if (p==0) { 1082 myGLCD.drawBitmap (MarioX, MarioY, 28, 28, MarioU1); 1083 } else if (p==1) { 1084 myGLCD.drawBitmap (MarioX, MarioY, 28, 28, MarioU2); 1085 } else if (p==2) { 1086 myGLCD.drawBitmap (MarioX, MarioY, 28, 28, MarioU1); 1087 } else if (p==3) { 1088 myGLCD.drawBitmap (MarioX, MarioY, 28, 28, MarioU2); 1089 } 1090 1091 } else if ( d == 2){ // Left 1092 1093 myGLCD.fillRect(x+28, y, x+31, y+28); // Clear trail off graphic before printing new positi 1094 1095 // draw image 1096 if (p==0) { 1097 myGLCD.drawBitmap (MarioX, MarioY, 28, 28, MarioL1); 1098 } else if (p==1) { 1099 myGLCD.drawBitmap (MarioX, MarioY, 28, 28, MarioL3); 1100 } else if (p==2) { 1101 myGLCD.drawBitmap (MarioX, MarioY, 28, 28, MarioL2); 1102 } else if (p==3) { 1103 myGLCD.drawBitmap (MarioX, MarioY, 28, 28, MarioL3); 1104 } 1105 1106 } else if ( d == 3){ // Up 1107 1108 myGLCD.fillRect(x, y+30, x+28, y+28); // Clear trail off graphic before printing new position 1109 1110 // draw image 1111 if (p==0) { 1112 myGLCD.drawBitmap (MarioX, MarioY, 28, 28, MarioU1); 1113 } else if (p==1) { 1114 myGLCD.drawBitmap (MarioX, MarioY, 28, 28, MarioU2); 1115 } else if (p==2) { 1116 myGLCD.drawBitmap (MarioX, MarioY, 28, 28, MarioU1); 1117 } else if (p==3) { 1118 myGLCD.drawBitmap (MarioX, MarioY, 28, 28, MarioU2); 1119 } 1120 } 1121// myGLCD.drawBitmap (MarioX, MarioY, 40, 40, MarioR3); 1122} 1123 1124 1125//********************************************************************************************************** 1126//====== Draws the Cannon - bitmap 1127void drawCannon(int x, int y, int d, int p) { 1128 1129 // Draws the Cannon - bitmap 1130 // Cannon direction d == 0 = right, 1 = down, 2 = left, 3 = up 1131 myGLCD.setColor(0, 0, 0); 1132 myGLCD.setBackColor(0, 0, 0); 1133 1134 1135 1136 if ( d == 0){ // Right 1137 1138 myGLCD.fillRect(x-3, y+3, x, y+36); // Clear trail off graphic before printing new position 1139 1140 // draw image 1141 1142 } else if ( d == 1){ // Down 1143 1144 myGLCD.fillRect(x+3, y-3, x+36, y); // Clear trail off graphic before printing new position 1145 1146 // draw image 1147 1148 } else if ( d == 2){ // Left 1149 1150 myGLCD.fillRect(x+41, y+3, x+40, y+36); // Clear trail off graphic before printing new positi 1151 1152 // draw image 1153 1154 } else if ( d == 3){ // Up 1155 1156 myGLCD.fillRect(x, y+41, x+40, y+40); // Clear trail off graphic before printing new position 1157 1158 // draw image 1159 1160 } 1161 1162 1163 myGLCD.drawBitmap (CannonX, CannonY, 40, 40, Cannon); 1164} 1165 1166 1167//********************************************************************************************************** 1168//====== Draws the Monkey - bitmap 1169void drawMonkey(int x, int y, int d, int p) { 1170 1171 // Draws the Monkey - bitmap 1172 // Monkey direction d == 0 = right, 1 = down, 2 = left, 3 = up 1173 myGLCD.setColor(0, 0, 0); 1174 myGLCD.setBackColor(0, 0, 0); 1175 1176 1177 if ( d == 0){ // Right 1178 1179 myGLCD.fillRect(x-3, y, x, y+40); // Clear trail off graphic before printing new position 1180 1181 1182 1183 // draw image 1184 if (p==0) { 1185 myGLCD.drawBitmap (MonkeyX, MonkeyY, 40, 40, Monkey2); 1186 } else if (p==1) { 1187 myGLCD.drawBitmap (MonkeyX, MonkeyY, 40, 40, Monkey2); 1188 } else if (p==2) { 1189 myGLCD.drawBitmap (MonkeyX, MonkeyY, 40, 40, Monkey3); 1190 }else { 1191 myGLCD.drawBitmap (MonkeyX, MonkeyY, 40, 40, Monkey3); 1192 } 1193 1194 1195 } else if ( d == 1){ // Down 1196 1197 myGLCD.fillRect(x, y-3, x+40, y); // Clear trail off graphic before printing new position 1198 1199 // draw image 1200 myGLCD.drawBitmap (MonkeyX, MonkeyY, 40, 40, Monkey3); 1201 1202 } else if ( d == 2){ // Left 1203 1204 myGLCD.fillRect(x+41, y, x+40, y+40); // Clear trail off graphic before printing new positi 1205 1206 // draw image 1207 if (p==0) { 1208 myGLCD.drawBitmap (MonkeyX, MonkeyY, 40, 40, Monkey2); 1209 } else if (p==1) { 1210 myGLCD.drawBitmap (MonkeyX, MonkeyY, 40, 40, Monkey2); 1211 } else if (p==2) { 1212 myGLCD.drawBitmap (MonkeyX, MonkeyY, 40, 40, Monkey3); 1213 }else { 1214 myGLCD.drawBitmap (MonkeyX, MonkeyY, 40, 40, Monkey3); 1215 } 1216 1217 1218 } else if ( d == 3){ // Up 1219 1220 myGLCD.fillRect(x, y+43, x+40, y+40); // Clear trail off graphic before printing new position 1221 1222 // draw image 1223 myGLCD.drawBitmap (MonkeyX, MonkeyY, 40, 40, Monkey3); 1224 1225 } 1226 1227 1228 1229 1230} 1231 1232 1233//********************************************************************************************************** 1234//====== Draws the pacman - bitmap 1235void drawpacman(int x, int y, int d, int p) { 1236 1237 // Draws the pacman - bitmap 1238 // pacman direction d == 0 = right, 1 = down, 2 = left, 3 = up 1239 myGLCD.setColor(0, 0, 0); 1240 myGLCD.setBackColor(0, 0, 0); 1241 1242 1243 1244 if ( d == 0){ // Right 1245 1246 myGLCD.fillRect(x-3, y+3, x, y+36); // Clear trail off graphic before printing new position 1247 1248 // draw image 1249 if (p==0) { 1250 myGLCD.drawBitmap (pacmanX, pacmanY, 28, 28, c_pacman); 1251 } else if (p==1) { 1252 myGLCD.drawBitmap (pacmanX, pacmanY, 28, 28, r_m_pacman); 1253 } else if (p==2) { 1254 myGLCD.drawBitmap (pacmanX, pacmanY, 28, 28, r_o_pacman); 1255 }else { 1256 myGLCD.drawBitmap (pacmanX, pacmanY, 28, 28, r_m_pacman); 1257 } 1258 1259 1260 } else if ( d == 1){ // Down 1261 1262 myGLCD.fillRect(x+3, y-3, x+36, y); // Clear trail off graphic before printing new position 1263 1264 // draw image 1265 if (p==0) { 1266 myGLCD.drawBitmap (pacmanX, pacmanY, 28, 28, c_pacman); 1267 } else if (p==1) { 1268 myGLCD.drawBitmap (pacmanX, pacmanY, 28, 28, d_m_pacman); 1269 } else if (p==2) { 1270 myGLCD.drawBitmap (pacmanX, pacmanY, 28, 28, d_o_pacman); 1271 }else { 1272 myGLCD.drawBitmap (pacmanX, pacmanY, 28, 28, d_m_pacman); 1273 } 1274 1275 } else if ( d == 2){ // Left 1276 1277 myGLCD.fillRect(x+28, y, x+31, y+28); // Clear trail off graphic before printing new positi 1278 1279 // draw image 1280 if (p==0) { 1281 myGLCD.drawBitmap (pacmanX, pacmanY, 28, 28, c_pacman); 1282 } else if (p==1) { 1283 myGLCD.drawBitmap (pacmanX, pacmanY, 28, 28, l_m_pacman); 1284 } else if (p==2) { 1285 myGLCD.drawBitmap (pacmanX, pacmanY, 28, 28, l_o_pacman); 1286 }else { 1287 myGLCD.drawBitmap (pacmanX, pacmanY, 28, 28, l_m_pacman); 1288 } 1289 1290 } else if ( d == 3){ // Up 1291 1292 myGLCD.fillRect(x, y+29, x+28, y+28); // Clear trail off graphic before printing new position 1293 1294 // draw image 1295 if (p==0) { 1296 myGLCD.drawBitmap (pacmanX, pacmanY, 28, 28, c_pacman); 1297 } else if (p==1) { 1298 myGLCD.drawBitmap (pacmanX, pacmanY, 28, 28, u_m_pacman); 1299 } else if (p==2) { 1300 myGLCD.drawBitmap (pacmanX, pacmanY, 28, 28, u_o_pacman); 1301 }else { 1302 myGLCD.drawBitmap (pacmanX, pacmanY, 28, 28, u_m_pacman); 1303 } 1304 } 1305 1306 1307// myGLCD.drawBitmap (pacmanX, pacmanY, 28, 28, r_o_pacman); 1308} 1309 1310 1311//********************************************************************************************************** 1312//====== Draws the Alien - bitmap 1313void drawAlien(int x, int y, int d, int p) { 1314 1315 // Draws the Alien - bitmap 1316 // Alien direction d == 0 = right, 1 = down, 2 = left, 3 = up 1317 myGLCD.setColor(0, 0, 0); 1318 myGLCD.setBackColor(0, 0, 0); 1319 1320 1321 if ( d == 0){ // Right 1322 1323 myGLCD.fillRect(x-3, y+3, x, y+36); // Clear trail off graphic before printing new position 1324 1325 // draw image 1326 if((p == 1)||(p == 3)){ 1327 myGLCD.drawBitmap (AlienX, AlienY, 40, 40, Alien1); 1328 } else { 1329 myGLCD.drawBitmap (AlienX, AlienY, 40, 40, Alien2); 1330 } 1331 1332 } else if ( d == 1){ // Down 1333 1334 myGLCD.fillRect(x+3, y-3, x+36, y); // Clear trail off graphic before printing new position 1335 1336 // draw image 1337 if((p == 1)||(p == 3)){ 1338 myGLCD.drawBitmap (AlienX, AlienY, 40, 40, Alien1); 1339 } else { 1340 myGLCD.drawBitmap (AlienX, AlienY, 40, 40, Alien2); 1341 } 1342 1343 } else if ( d == 2){ // Left 1344 1345 myGLCD.fillRect(x+41, y+3, x+40, y+36); // Clear trail off graphic before printing new positi 1346 1347 // draw image 1348 if((p == 1)||(p == 3)){ 1349 myGLCD.drawBitmap (AlienX, AlienY, 40, 40, Alien1); 1350 } else { 1351 myGLCD.drawBitmap (AlienX, AlienY, 40, 40, Alien2); 1352 } 1353 1354 } else if ( d == 3){ // Up 1355 1356 myGLCD.fillRect(x, y+41, x+40, y+40); // Clear trail off graphic before printing new position 1357 1358 // draw image 1359 if((p == 1)||(p == 3)){ 1360 myGLCD.drawBitmap (AlienX, AlienY, 40, 40, Alien1); 1361 } else { 1362 myGLCD.drawBitmap (AlienX, AlienY, 40, 40, Alien2); 1363 } 1364 1365 } 1366 1367 1368 1369} 1370 1371 1372 1373
Downloadable files
Circuit Diagram
Circuit Diagram

Documentation
Thingiverse
https://www.thingiverse.com/thing:3017701
https://www.thingiverse.com/thing:3017701
Comments
Only logged in users can leave comments