Devices & Components
Arduino Mega 2560 Rev3
Analog joystick (Generic)
Graphic LCD 84x48 - Nokia 5110
Project description
Code
CactchTheCircle
arduino
The library is here: http://www.rinkydinkelectronics.com/library.php?id=47
1#include <LCD5110_Graph.h> 2 3LCD5110 myGLCD(7,6,5,3,4); 4 5extern uint8_t SmallFont[]; 6extern unsigned char TinyFont[]; 7int sc=10000; 8int to=10000; 9int rc=0; 10double xa=0; 11int a, b; 12 13 14void setup() 15{ 16 myGLCD.InitLCD(); 17 myGLCD.setFont(TinyFont); 18 randomSeed(analogRead(7)); 19 rc = sc; //record = 10000 20} 21 22 23 24void loop() 25{ 26 27if(sc>rc) 28rc=sc; // increase th record 29 30if(sc<=10000) //reseting record to reset speed 31rc=sc; 32 33 34 myGLCD.clrScr(); 35 myGLCD.drawRect(0, 0, 83, 47); 36 37if(xa == 0) 38{ 39 a=random(0,83); 40 b=random(0,47); 41if(rc>0&&rc<11000) //seting the speed 42xa=150; 43if(rc>11000&&rc<12000) 44xa=130; 45if(rc>12000&&rc<13000) 46xa=100; 47if(rc>13000&&rc<14000) 48xa=65; 49if(rc>14000&&rc<15000) 50xa=45; 51if(rc>15000&&rc<17000) 52xa=35; 53if(rc>17000&&rc<19000) 54xa=25; 55if(rc>20000) 56xa=20; 57} 58 xa--; 59 60 61 62 63 myGLCD.print("Score ", LEFT, 0); 64 myGLCD.print(String(sc), 22, 0); 65 66 if(sc>=15000&&sc<16000) 67 { 68 myGLCD.print("not bad.", RIGHT , 0); 69 } 70 71 if(sc>=16000&&sc<17000) 72 { 73 myGLCD.print("Good!", RIGHT , 0); 74 } 75 76 77if(sc>=17000&&sc<19000) { 78 myGLCD.print("MY BOY!", RIGHT , 0); 79 } 80 81 82 if(sc>=19000) 83 { 84 myGLCD.print("WOW!!", RIGHT , 0); 85 } 86 myGLCD.drawCircle(a,b,3); 87 myGLCD.drawCircle(a,b,4); 88 myGLCD.drawCircle(a,b,5); 89 90 myGLCD.drawCircle(map(analogRead(A1),0,1024,0,83),map(analogRead(A0),0,1024,0,47),1); 91 myGLCD.drawCircle(map(analogRead(A1),0,1024,0,83),map(analogRead(A0),0,1024,0,47),3); 92 myGLCD.drawCircle(map(analogRead(A1),0,1024,0,83),map(analogRead(A0),0,1024,0,47),4); 93 94 95 if(xa == 0) //loosing one round 96{ 97sc -= 150; 98} 99 100if(map(analogRead(A1),0,1024,0,83)<a+5&&map(analogRead(A1),0,1024,0,83)>a-5 && map(analogRead(A0),0,1024,0,47)<b+5&& map(analogRead(A0),0,1024,0,47)>b-5) // winning one round 101{ 102 xa=0; 103 sc+=100; 104} 105 106 107if(sc<=0) // Game over 108while(1) 109{ 110 myGLCD.clrScr(); 111 myGLCD.setFont(SmallFont); 112 myGLCD.print("game over!", CENTER, 32); 113 myGLCD.update(); 114 115} 116 117if(sc>=20500) // WIN!! (IMPOSSIBLE : )) ) 118while(1) 119{ 120 myGLCD.clrScr(); 121 myGLCD.setFont(SmallFont); 122 myGLCD.print("WINNER!!", CENTER, 24); 123 myGLCD.print("WHO THE HELL", CENTER, 32); 124 myGLCD.print("ARE YOU?!", CENTER, 40); 125 myGLCD.update(); 126 127} 128 129if(to==0) // (time out) 130while(1) 131{ 132 myGLCD.clrScr(); 133 myGLCD.setFont(SmallFont); 134 myGLCD.print("T.O! record:", CENTER, 32); 135 myGLCD.print(String(sc), CENTER, 40); 136 137 myGLCD.update(); 138 139} 140 141 142 myGLCD.update(); 143 to --; // timer decrease 144 delay(10); 145 146}
CactchTheCircle
arduino
The library is here: http://www.rinkydinkelectronics.com/library.php?id=47
1#include <LCD5110_Graph.h> 2 3LCD5110 myGLCD(7,6,5,3,4); 4 5extern uint8_t SmallFont[]; 6extern unsigned char TinyFont[]; 7int sc=10000; 8int to=10000; 9int rc=0; 10double xa=0; 11int a, b; 12 13 14void setup() 15{ 16 myGLCD.InitLCD(); 17 myGLCD.setFont(TinyFont); 18 randomSeed(analogRead(7)); 19 rc = sc; //record = 10000 20} 21 22 23 24void loop() 25{ 26 27if(sc>rc) 28rc=sc; // increase th record 29 30if(sc<=10000) //reseting record to reset speed 31rc=sc; 32 33 34 myGLCD.clrScr(); 35 myGLCD.drawRect(0, 0, 83, 47); 36 37if(xa == 0) 38{ 39 a=random(0,83); 40 b=random(0,47); 41if(rc>0&&rc<11000) //seting the speed 42xa=150; 43if(rc>11000&&rc<12000) 44xa=130; 45if(rc>12000&&rc<13000) 46xa=100; 47if(rc>13000&&rc<14000) 48xa=65; 49if(rc>14000&&rc<15000) 50xa=45; 51if(rc>15000&&rc<17000) 52xa=35; 53if(rc>17000&&rc<19000) 54xa=25; 55if(rc>20000) 56xa=20; 57} 58 xa--; 59 60 61 62 63 myGLCD.print("Score ", LEFT, 0); 64 myGLCD.print(String(sc), 22, 0); 65 66 if(sc>=15000&&sc<16000) 67 { 68 myGLCD.print("not bad.", RIGHT , 0); 69 } 70 71 if(sc>=16000&&sc<17000) 72 { 73 myGLCD.print("Good!", RIGHT , 0); 74 } 75 76 77if(sc>=17000&&sc<19000) { 78 myGLCD.print("MY BOY!", RIGHT , 0); 79 } 80 81 82 if(sc>=19000) 83 { 84 myGLCD.print("WOW!!", RIGHT , 0); 85 } 86 myGLCD.drawCircle(a,b,3); 87 myGLCD.drawCircle(a,b,4); 88 myGLCD.drawCircle(a,b,5); 89 90 myGLCD.drawCircle(map(analogRead(A1),0,1024,0,83),map(analogRead(A0),0,1024,0,47),1); 91 myGLCD.drawCircle(map(analogRead(A1),0,1024,0,83),map(analogRead(A0),0,1024,0,47),3); 92 myGLCD.drawCircle(map(analogRead(A1),0,1024,0,83),map(analogRead(A0),0,1024,0,47),4); 93 94 95 if(xa == 0) //loosing one round 96{ 97sc -= 150; 98} 99 100if(map(analogRead(A1),0,1024,0,83)<a+5&&map(analogRead(A1),0,1024,0,83)>a-5 && map(analogRead(A0),0,1024,0,47)<b+5&& map(analogRead(A0),0,1024,0,47)>b-5) // winning one round 101{ 102 xa=0; 103 sc+=100; 104} 105 106 107if(sc<=0) // Game over 108while(1) 109{ 110 myGLCD.clrScr(); 111 myGLCD.setFont(SmallFont); 112 myGLCD.print("game over!", CENTER, 32); 113 myGLCD.update(); 114 115} 116 117if(sc>=20500) // WIN!! (IMPOSSIBLE : )) ) 118while(1) 119{ 120 myGLCD.clrScr(); 121 myGLCD.setFont(SmallFont); 122 myGLCD.print("WINNER!!", CENTER, 24); 123 myGLCD.print("WHO THE HELL", CENTER, 32); 124 myGLCD.print("ARE YOU?!", CENTER, 40); 125 myGLCD.update(); 126 127} 128 129if(to==0) // (time out) 130while(1) 131{ 132 myGLCD.clrScr(); 133 myGLCD.setFont(SmallFont); 134 myGLCD.print("T.O! record:", CENTER, 32); 135 myGLCD.print(String(sc), CENTER, 40); 136 137 myGLCD.update(); 138 139} 140 141 142 myGLCD.update(); 143 to --; // timer decrease 144 delay(10); 145 146}
Downloadable files
connections diagram
connections are easy to change using the code, joystick has two analog outputs and LCD pins can be changed also within the code. LCD -> Arduino: VCC -> Arduino 5V LIGHT(LED, BL or BACKLIGHT) -> Arduino 5V GND -> Arduino GND CLK (SCLK) -> Arduino pin 7 DIN (DN or MOSI) -> Arduino pin 6 DC (D/C) -> Arduino pin 5 CE (SCE or CS) -> Arduino pin 4 RST (RESET) -> Arduino pin 3 JOYSTICK -> Arduino: GND -> Arduino GND 5V -> Arduino 5V VRX -> A1 VRY -> A0
connections diagram

Comments
Only logged in users can leave comments